-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcommands.go
More file actions
141 lines (126 loc) · 4.07 KB
/
commands.go
File metadata and controls
141 lines (126 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package commands
import (
"fmt"
cloudstorages "github.com/st-tech/gatling-operator/pkg/cloudstorages"
)
func GetGatlingWaiterCommand(parallelism *int32, gatlingNamespace string, gatlingName string) string {
template := `
PARALLELISM=%d
NAMESPACE=%s
JOB_NAME=%s
POD_NAME=$(cat /etc/pod-info/name)
kubectl label pods -n $NAMESPACE $POD_NAME gatling-waiter=initialized
while true; do
READY_PODS=$(kubectl get pods -n $NAMESPACE --selector=job-name=$JOB_NAME-runner,gatling-waiter=initialized --no-headers | grep -c ".*");
echo "$READY_PODS/$PARALLELISM pods are ready";
if [ $READY_PODS -eq $PARALLELISM ]; then
break;
fi;
sleep 1;
done
`
return fmt.Sprintf(template,
*parallelism,
gatlingNamespace,
gatlingName,
)
}
func GetGatlingRunnerCommand(
simulationsFormat string, simulationsDirectoryPath string, tempSimulationsDirectoryPath string,
resourcesDirectoryPath string, resultsDirectoryPath string, startTime string, simulationClass string,
generateLocalReport bool) string {
template := `
SIMULATIONS_FORMAT=%s
SIMULATIONS_DIR_PATH=%s
TEMP_SIMULATIONS_DIR_PATH=%s
RESOURCES_DIR_PATH=%s
RESULTS_DIR_PATH=%s
START_TIME="%s"
SIMULATION_CLASS=%s
RUN_STATUS_FILE="${RESULTS_DIR_PATH}/COMPLETED"
if [ -z "${START_TIME}" ]; then
START_TIME=$(date +"%%Y-%%m-%%d %%H:%%M:%%S" --utc)
fi
start_time_stamp=$(date -d "${START_TIME}" +"%%s")
current_time_stamp=$(date +"%%s")
echo "Wait until ${START_TIME}"
until [ ${current_time_stamp} -ge ${start_time_stamp} ];
do
current_time_stamp=$(date +"%%s")
echo "it's ${current_time_stamp} now and waiting until ${start_time_stamp} ..."
sleep 1;
done
if [ ! -d ${SIMULATIONS_DIR_PATH} ]; then
mkdir -p ${SIMULATIONS_DIR_PATH}
fi
if [ -d ${TEMP_SIMULATIONS_DIR_PATH} ]; then
cp -p ${TEMP_SIMULATIONS_DIR_PATH}/*.scala ${SIMULATIONS_DIR_PATH}
fi
if [ ! -d ${RESOURCES_DIR_PATH} ]; then
mkdir -p ${RESOURCES_DIR_PATH}
fi
if [ ! -d ${RESULTS_DIR_PATH} ]; then
mkdir -p ${RESULTS_DIR_PATH}
fi
if [ ${SIMULATIONS_FORMAT} = "bundle" ]; then
gatling.sh -sf ${SIMULATIONS_DIR_PATH} -s ${SIMULATION_CLASS} -rsf ${RESOURCES_DIR_PATH} -rf ${RESULTS_DIR_PATH} %s %s
elif [ ${SIMULATIONS_FORMAT} = "gradle" ]; then
gradle -Dgatling.core.directory.results=${RESULTS_DIR_PATH} --simulation=${SIMULATION_CLASS}
fi
GATLING_EXIT_STATUS=$?
if [ $GATLING_EXIT_STATUS -ne 0 ]; then
RUN_STATUS_FILE="${RESULTS_DIR_PATH}/FAILED"
echo "gatling.sh has failed!" 1>&2
fi
touch ${RUN_STATUS_FILE}
exit $GATLING_EXIT_STATUS
`
generateLocalReportOption := "-nr"
if generateLocalReport {
generateLocalReportOption = ""
}
runModeOptionLocal := "-rm local"
return fmt.Sprintf(template,
simulationsFormat,
simulationsDirectoryPath,
tempSimulationsDirectoryPath,
resourcesDirectoryPath,
resultsDirectoryPath,
startTime,
simulationClass,
generateLocalReportOption,
runModeOptionLocal)
}
func GetGatlingTransferResultCommand(resultsDirectoryPath string, provider string, region string, storagePath string) string {
var command string
cspp := cloudstorages.GetProvider(provider)
if cspp != nil {
command = (*cspp).GetGatlingTransferResultCommand(resultsDirectoryPath, region, storagePath)
}
return command
}
func GetGatlingAggregateResultCommand(resultsDirectoryPath string, provider string, region string, storagePath string) string {
var command string
cspp := cloudstorages.GetProvider(provider)
if cspp != nil {
command = (*cspp).GetGatlingAggregateResultCommand(resultsDirectoryPath, region, storagePath)
}
return command
}
func GetGatlingGenerateReportCommand(resultsDirectoryPath string) string {
template := `
GATLING_AGGREGATE_DIR=%s
DIR_NAME=$(dirname ${GATLING_AGGREGATE_DIR})
BASE_NAME=$(basename ${GATLING_AGGREGATE_DIR})
gatling.sh -rf ${DIR_NAME} -ro ${BASE_NAME}
`
return fmt.Sprintf(template, resultsDirectoryPath)
}
func GetGatlingTransferReportCommand(resultsDirectoryPath string, provider string, region string, storagePath string) string {
var command string
cspp := cloudstorages.GetProvider(provider)
if cspp != nil {
command = (*cspp).GetGatlingTransferReportCommand(resultsDirectoryPath, region, storagePath)
}
return command
}