Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to pensando em colocar o caminho do github aqui

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use o

func (u *UtilsReadFile) ReadFile(filePath string) string {

Ele é um utilitario para ler arquivo.
Tenta evitar código duplicado.

Para replace de variaveis use

#VAR1#
ai tu faz o replace.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foi


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
}

Expand Down
30 changes: 30 additions & 0 deletions pkg/server/scripts/monitor_disk_spec_storage.sh
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 24 additions & 0 deletions pkg/server/scripts/monitor_files_storage.sh
Original file line number Diff line number Diff line change
@@ -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"