Skip to content

Commit d6bd8c6

Browse files
committed
Added function to scale processes to lower limit upon startup plus unit tests for scaleup and scaledown funcs
1 parent abb461f commit d6bd8c6

8 files changed

Lines changed: 67 additions & 17 deletions

File tree

addproc.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
# -copy all contents of process.csv into customprocess.csv before running the script
1313
# -configure ${TORQPROCESSES} in setenv.sh to point to customprocess.csv
1414

15-
#source the relevant setenv.sh
16-
source setenv.sh
17-
1815
#input procname from cmd line
1916
inputprocname=$1
2017

@@ -63,7 +60,7 @@ elif [ $# -eq 1 ] ; then
6360
#run summary of all processes in customprocess.csv
6461
grep $inputprocname ${KDBAPPCONFIG}/process.csv | awk -F',' -vOFS=',' '{ $2 = "{KDBBASEPORT}+" '"$portnum"'; $4 ="'$newprocname'" }1' >> ${KDBAPPCONFIG}/customprocess.csv
6562
echo "$inputprocname replicated as $newprocname"
66-
bash torq.sh start $newprocname -csv ${KDBAPPCONFIG}/customprocess.csv
67-
bash torq.sh summary -csv ${KDBAPPCONFIG}/customprocess.csv
63+
bash ${TORQHOME}/torq.sh start $newprocname -csv ${KDBAPPCONFIG}/customprocess.csv
64+
bash ${TORQHOME}/torq.sh summary -csv ${KDBAPPCONFIG}/customprocess.csv
6865
fi
6966
fi

code/processes/orchestrator.q

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/default parameters
66

7-
scalingdetails:([] time:`timestamp$(); procname:`$(); dir:`$(); totalnumofinstances:`int$(); lowerlimit:`int$(); upperlimit:`int$()); /table for tracking scaling
7+
scalingdetails:([] time:`timestamp$(); procname:`$(); dir:`$(); instancecreated:`$(); instanceremoved:`$(); totalnumofinstances:`int$(); lowerlimit:`int$(); upperlimit:`int$()); /table for tracking scaling
88

99
processlimitscsv:hsym first .proc.getconfigfile"processlimits.csv"; /location of csv file
1010
limits:1!("SII";enlist ",")0:processlimitscsv; /table of scalable processes and the max number of instances allowed for each
@@ -21,25 +21,36 @@ getscaleprocsinstances[];
2121

2222
/function to scale up a process
2323
scaleup:{[procname]
24-
$[.orch.scaleprocsinstances[procname;`instances]<.orch.limits[procname;`upper];
25-
[system "bash addproc.sh ",string procname;
24+
$[scaleprocsinstances[procname;`instances]<limits[procname;`upper];
25+
[system "bash ${TORQHOME}/addproc.sh ",string procname;
2626
/update number of process instances
2727
getscaleprocsinstances[];
2828
/update table with record for scaling up
29-
`.orch.scalingdetails upsert (.z.p;procname;`up;.orch.scaleprocsinstances[procname;`instances];.orch.limits[procname;`lower];.orch.limits[procname;`upper])];
29+
`.orch.scalingdetails upsert (.z.p;procname;`up;`$(last procs where procs like string[procname],"*");`;scaleprocsinstances[procname;`instances];limits[procname;`lower];limits[procname;`upper])];
3030
.lg.o[`scale;"upper limit hit for ",string procname]
3131
];
3232
}
3333

3434
/function to scale down a process
3535
scaledown:{[procname]
36-
$[.orch.scaleprocsinstances[procname;`instances]>.orch.limits[procname;`lower];
37-
[latestinstance:last .orch.procs where .orch.procs like string[procname],"*";
38-
system "bash removeproc.sh ",latestinstance;
36+
$[scaleprocsinstances[procname;`instances]>limits[procname;`lower];
37+
[latestinstance:last procs where procs like string[procname],"*";
38+
system "bash ${TORQHOME}/removeproc.sh ",latestinstance;
3939
/update number of process instances
4040
getscaleprocsinstances[];
4141
/update table with record for scaling down
42-
`.orch.scalingdetails upsert (.z.p;procname;`down;.orch.scaleprocsinstances[procname;`instances];.orch.limits[procname;`lower];.orch.limits[procname;`upper])];
42+
`.orch.scalingdetails upsert (.z.p;procname;`down;`;`$latestinstance;scaleprocsinstances[procname;`instances];limits[procname;`lower];limits[procname;`upper])];
4343
.lg.o[`scale;"lower limit hit for ",string procname]
4444
];
4545
}
46+
47+
48+
/function to ensure all processes have been scaled up to meet lower limit
49+
initialscaling:{[procname]
50+
if[scaleprocsinstances[procname;`instances]<limits[procname;`lower];
51+
reqinstances:limits[procname;`lower]-scaleprocsinstances[procname;`instances];
52+
do[reqinstances;scaleup[procname]];
53+
];
54+
}
55+
56+
initialscaling@/:scaleprocslist;

removeproc.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/bash
22

3-
#source the relevant setenv.sh
4-
source setenv.sh
5-
63
#get all procnames from process.csv
74
PROCNAMES="$(sed '1d' ${KDBAPPCONFIG}/process.csv | awk -F',' '{print $4}')"
85

@@ -27,7 +24,7 @@ elif [ $# -eq 1 ] ; then
2724
if [ "$(echo $CUSTOMPROCNAMES | grep -w $inputprocname)" ] ; then
2825
echo -e 'Shutting down process now'
2926

30-
bash torq.sh stop $inputprocname -csv ${KDBAPPCONFIG}/customprocessCopy.csv
27+
bash ${TORQHOME}/torq.sh stop $inputprocname -csv ${KDBAPPCONFIG}/customprocessCopy.csv
3128
grep -v "$inputprocname" ${KDBAPPCONFIG}/customprocessCopy.csv >| ${KDBAPPCONFIG}/customprocess.csv
3229
#bash ./torq.sh stop $inputprocname
3330
else
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
host,port,proctype,procname,U,localtime,g,T,w,load,startwithall,extras,qcmd
2+
localhost,{KDBBASEPORT}+1,discovery,discovery1,,1,0,,,${KDBCODE}/processes/discovery.q,1,
3+
localhost,{KDBBASEPORT},segmentedtickerplant,stp1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${TORQAPPHOME}/database.q -tplogdir ${KDBTPLOG},
4+
localhost,{KDBBASEPORT}+3,hdb,hdb1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,60,4000,${KDBHDB},1,,

tests/orchestrator/process.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
host,port,proctype,procname,U,localtime,g,T,w,load,startwithall,extras,qcmd
2+
localhost,{KDBBASEPORT}+1,discovery,discovery1,,1,0,,,${KDBCODE}/processes/discovery.q,1,
3+
localhost,{KDBBASEPORT},segmentedtickerplant,stp1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,0,,,${KDBCODE}/processes/segmentedtickerplant.q,1,-schemafile ${TORQAPPHOME}/database.q -tplogdir ${KDBTPLOG},
4+
localhost,{KDBBASEPORT}+3,hdb,hdb1,${TORQAPPHOME}/appconfig/passwords/accesslist.txt,1,1,60,4000,${KDBHDB},1,,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
procname,lower,upper
2+
hdb1,1,2

tests/orchestrator/run.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
#path to test directory
4+
testpath=${KDBTESTS}/orchestrator
5+
6+
OLDKDBAPPCONFIG=${KDBAPPCONFIG}
7+
export KDBAPPCONFIG=${testpath}
8+
9+
#start procs
10+
${TORQHOME}/torq.sh start all -csv ${testpath}/customprocess.csv
11+
12+
#Start test proc
13+
/usr/bin/rlwrap $QCMD ${TORQHOME}/torq.q \
14+
-proctype orchestrator -procname orchestrator1 \
15+
-test ${testpath} \
16+
-load ${TORQHOME}/code/processes/orchestrator.q \
17+
-procfile ${testpath}/customprocess.csv -debug
18+
19+
#Shut down procs
20+
${TORQHOME}/torq.sh stop all -csv ${testpath}/customprocess.csv
21+
22+
export KDBAPPCONFIG=${OLDKDBAPPCONFIG}

tests/orchestrator/test.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
action,ms,bytes,lang,code,repeat,minver,comment
2+
3+
/test for scaling up func
4+
before,0,0,q,instancesbefore:.orch.scaleprocsinstances[`hdb1;`instances],1,,"get current instances of hdb1"
5+
run,0,0,q,.orch.scaleup[`hdb1],1,,"scale up hdb1"
6+
run,0,0,q,instancesafter:.orch.scaleprocsinstances[`hdb1;`instances],1,,"get current instances of hdb1"
7+
true,0,0,q,instancesbefore<instancesafter,1,,"check instances now bigger for hdb1"
8+
9+
/testing scaling down
10+
run,0,0,q,instancesbefore:.orch.scaleprocsinstances[`hdb1;`instances],1,,"get current instances of hdb1"
11+
run,0,0,q,.orch.scaledown[`hdb1],1,,"scale down"
12+
run,0,0,q,instancesafter:.orch.scaleprocsinstances[`hdb1;`instances],1,,"get current instances of hdb1"
13+
true,0,0,q,instancesbefore>instancesafter,1,,"check instances now smaller for hdb1"

0 commit comments

Comments
 (0)