diff --git a/pkg/server/runtimes/kubernetes_runtime/kubernetes_runtime_service/make_k8s_activity_service.go b/pkg/server/runtimes/kubernetes_runtime/kubernetes_runtime_service/make_k8s_activity_service.go index b9631bc..b47a235 100755 --- a/pkg/server/runtimes/kubernetes_runtime/kubernetes_runtime_service/make_k8s_activity_service.go +++ b/pkg/server/runtimes/kubernetes_runtime/kubernetes_runtime_service/make_k8s_activity_service.go @@ -5,10 +5,12 @@ import ( "math/rand" "os" "strconv" + "strings" "github.com/ovvesley/akoflow/pkg/server/entities/k8s_job_entity" "github.com/ovvesley/akoflow/pkg/server/entities/workflow_activity_entity" "github.com/ovvesley/akoflow/pkg/server/entities/workflow_entity" + "github.com/ovvesley/akoflow/pkg/shared/utils/utils_read_file" ) type MakeK8sActivityService struct { @@ -84,15 +86,29 @@ func (m *MakeK8sActivityService) getPortAkoFlowServer() string { func (m *MakeK8sActivityService) addCommandToMonitorFilesStorage(command string, path string) string { port := m.getPortAkoFlowServer() - command += `ls -lR $ACTIVITY_MOUNT_PATH > /tmp/du_output.txt; echo "Preparing to start request"; body=$(cat /tmp/du_output.txt); body_length=$(printf %s "$body" | wc -c); echo "Start request"; { echo -ne "POST /akoflow-server/internal/storage/` + path + `/?activityId=$ACTIVITY_ID HTTP/1.1\r\n"; echo -ne "Host: $AKOFLOW_SERVER_SERVICE_SERVICE_HOST\r\n"; echo -ne "Content-Type: text/plain\r\n"; echo -ne "Content-Length: $body_length\r\n"; echo -ne "Connection: close\r\n"; echo -ne "\r\n"; echo -ne "$body"; } | nc $AKOFLOW_SERVER_SERVICE_SERVICE_HOST ` + port + `; echo "End request"; ` + scriptPath := "/app/pkg/server/scripts/monitor_files_storage.sh" + utilsReadFile := utils_read_file.New() + script := utilsReadFile.ReadFile(scriptPath) + + script = strings.ReplaceAll(script, "#PATH_PARAM#", path) + script = strings.ReplaceAll(script, "#PORT#", port) + + command += script + "; " return command } func (m *MakeK8sActivityService) addCommandToMonitorDiskSpecStorage(command string, path string) string { port := m.getPortAkoFlowServer() - command += `df -h > /tmp/du_output.txt; echo "Preparing to start request"; body=$(cat /tmp/du_output.txt); body_length=$(printf %s "$body" | wc -c); echo "Start request"; { echo -ne "POST /akoflow-server/internal/storage/` + path + `/?activityId=$ACTIVITY_ID HTTP/1.1\r\n"; echo -ne "Host: $AKOFLOW_SERVER_SERVICE_SERVICE_HOST\r\n"; echo -ne "Content-Type: text/plain\r\n"; echo -ne "Content-Length: $body_length\r\n"; echo -ne "Connection: close\r\n"; echo -ne "\r\n"; echo -ne "$body"; } | nc $AKOFLOW_SERVER_SERVICE_SERVICE_HOST ` + port + `; echo "End request"; ` + scriptPath := "/app/pkg/server/scripts/monitor_disk_spec_storage.sh" + + utilsReadFile := utils_read_file.New() + script := utilsReadFile.ReadFile(scriptPath) + + script = strings.ReplaceAll(script, "#PATH_PARAM#", path) + script = strings.ReplaceAll(script, "#PORT#", port) + command += script + "; " return command } diff --git a/pkg/server/scripts/monitor_disk_spec_storage.sh b/pkg/server/scripts/monitor_disk_spec_storage.sh new file mode 100644 index 0000000..3ba195b --- /dev/null +++ b/pkg/server/scripts/monitor_disk_spec_storage.sh @@ -0,0 +1,30 @@ +#!/bin/bash +PATH_PARAM="#PATH_PARAM#" +PORT="#PORT#" + +df -h $ACTIVITY_MOUNT_PATH > /tmp/disk_spec_output.txt +echo "Preparing to start request" +body=$(cat /tmp/disk_spec_output.txt) +body_length=$(printf %s "$body" | wc -c) +echo "Start request" + +if command -v nc >/dev/null 2>&1; then + { echo -ne "POST /akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID HTTP/1.1\r\n"; \ + echo -ne "Host: $AKOFLOW_SERVER_SERVICE_SERVICE_HOST\r\n"; \ + echo -ne "Content-Type: text/plain\r\n"; \ + echo -ne "Content-Length: $body_length\r\n"; \ + echo -ne "Connection: close\r\n"; \ + echo -ne "\r\n"; \ + echo -ne "$body"; } | nc $AKOFLOW_SERVER_SERVICE_SERVICE_HOST $PORT +elif command -v curl >/dev/null 2>&1; then + curl -X POST "http://$AKOFLOW_SERVER_SERVICE_SERVICE_HOST:$PORT/akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID" -H "Content-Type: text/plain" --data "$body" +elif command -v wget >/dev/null 2>&1; then + wget --post-data="$body" --header="Content-Type: text/plain" "http://$AKOFLOW_SERVER_SERVICE_SERVICE_HOST:$PORT/akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID" -O /dev/null +elif [ "$BASH_VERSION" ] && [ -e /dev/tcp ]; then + exec 3<>/dev/tcp/$AKOFLOW_SERVER_SERVICE_SERVICE_HOST/$PORT + echo -ne "POST /akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID HTTP/1.1\r\nHost: $AKOFLOW_SERVER_SERVICE_SERVICE_HOST\r\nContent-Type: text/plain\r\nContent-Length: $body_length\r\nConnection: close\r\n\r\n$body" >&3 +else + echo "No HTTP client available (nc, curl, wget or bash)" >&2 +fi + +echo -e "\nEnd request" \ No newline at end of file diff --git a/pkg/server/scripts/monitor_files_storage.sh b/pkg/server/scripts/monitor_files_storage.sh new file mode 100644 index 0000000..fc9a81d --- /dev/null +++ b/pkg/server/scripts/monitor_files_storage.sh @@ -0,0 +1,24 @@ +#!/bin/bash +PATH_PARAM="#PATH_PARAM#" +PORT="#PORT#" + +ls -lR $ACTIVITY_MOUNT_PATH > /tmp/du_output.txt +echo "Preparing to start request" +body=$(cat /tmp/du_output.txt) +body_length=$(printf %s "$body" | wc -c) +echo "Start request" + +if command -v nc >/dev/null 2>&1; then + { echo -ne "POST /akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID HTTP/1.1\r\n"; echo -ne "Host: $AKOFLOW_SERVER_SERVICE_SERVICE_HOST\r\n"; echo -ne "Content-Type: text/plain\r\n"; echo -ne "Content-Length: $body_length\r\n"; echo -ne "Connection: close\r\n"; echo -ne "\r\n"; echo -ne "$body"; } | nc $AKOFLOW_SERVER_SERVICE_SERVICE_HOST $PORT +elif command -v curl >/dev/null 2>&1; then + curl -X POST "http://$AKOFLOW_SERVER_SERVICE_SERVICE_HOST:$PORT/akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID" -H "Content-Type: text/plain" --data "$body" +elif command -v wget >/dev/null 2>&1; then + wget --post-data="$body" --header="Content-Type: text/plain" "http://$AKOFLOW_SERVER_SERVICE_SERVICE_HOST:$PORT/akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID" -O /dev/null +elif [ "$BASH_VERSION" ] && [ -e /dev/tcp ]; then + exec 3<>/dev/tcp/$AKOFLOW_SERVER_SERVICE_SERVICE_HOST/$PORT + echo -ne "POST /akoflow-server/internal/storage/$PATH_PARAM/?activityId=$ACTIVITY_ID HTTP/1.1\r\nHost: $AKOFLOW_SERVER_SERVICE_SERVICE_HOST\r\nContent-Type: text/plain\r\nContent-Length: $body_length\r\nConnection: close\r\n\r\n$body" >&3 +else + echo "No HTTP client available (nc, curl, wget or bash)" >&2 +fi + +echo -e "\nEnd request" \ No newline at end of file