-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflowGenerator.py
61 lines (48 loc) · 2.26 KB
/
workflowGenerator.py
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
from random import sample
from random import randint
import json
from model.workflow import ConfigDetail
from model.workflow import Config
from model.workflow import Workflow
class WorkflowGenerator:
def printToFile(self,s):
fileName = "./json-data-generator-1.2.2-SNAPSHOT/conf/cpuUsageWorkflow_{}_{}.json".format(self.clusterName, self.nodeNumber)
f = open(fileName, 'w')
f.write(s + "\n")
f.close()
def getAnomalousRangeForCorrectSeq(self, timeSeq):
return (timeSeq * self.anomalyDuration, (timeSeq+1) * self.anomalyDuration)
def getAnomalousRangeForWrongSeq(self, timeSeq):
return (timeSeq * self.anomalyDuration, (timeSeq+1) * self.anomalyDuration-1)
def generateAnomalousTimeSeq(self):
timeSeq = sample(range(int(self.totalWorkflowDuration/self.anomalyDuration)),self.anomalyCount)
calculateRange = lambda x: self.getAnomalousRangeForCorrectSeq(x) if x%4!=0 else self.getAnomalousRangeForWrongSeq(x)
self.anomalyStartArray=list(map(calculateRange,timeSeq))
self.anomalyStartArray.sort()
print(self.anomalyStartArray)
def generateSteps(self):
steps=[]
for i in range(self.totalWorkflowDuration):
if i>=self.anomalyStartArray[self.listPos][0] and i < self.anomalyStartArray[self.listPos][1]:
cpu = "double(81.0,100.0)"
if i == (self.anomalyStartArray[self.listPos][1])-1:
self.listPos =(self.listPos + 1)%len(self.anomalyStartArray)
else:
cpu = "double(1.0,80.0)"
config = Config(ConfigDetail(self.clusterName, cpu, self.nodeNumber, "now()", i))
steps.append(config)
return steps
def printStepsToFile(self):
self.listPos=0
workflow = Workflow(0, False, False, 1000, True, self.generateSteps())
self.printToFile(workflow.toJSON())
def generate(self,arg=[]):
timeInMins=randint(1,10)
self.anomalyCount=timeInMins*randint(1,3)
self.totalWorkflowDuration = timeInMins * 60
self.anomalyDuration = 10
(self.clusterName, self.nodeNumber)=tuple(arg)
self.generateAnomalousTimeSeq()
self.printStepsToFile()
if __name__=="__main__":
WorkflowGenerator().generate()