-
Notifications
You must be signed in to change notification settings - Fork 0
/
configGenerator.py
39 lines (33 loc) · 1.51 KB
/
configGenerator.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
import json
from model.producers import WorkflowConfig
from model.producers import Producer
from model.producers import Workflow
from workflowGenerator import WorkflowGenerator
class ConfigGenerator:
def __init__(self):
self.wfg=WorkflowGenerator()
def printToConfigFile(self,configuration):
fileName = "./json-data-generator-1.2.2-SNAPSHOT/conf/cpuUsageConfig_{}.json".format(self.clusterName)
f = open(fileName, 'w')
f.write(configuration + "\n")
f.close()
def generateWorkflows(self,clusterDetails):
self.clusterName=clusterDetails['clusterName']
firstNode=clusterDetails['firstNode']
lastNode=clusterDetails['lastNode']
workflows=[]
for nodeNumber in range(firstNode, lastNode + 1):
self.wfg.generate([self.clusterName, nodeNumber])
workflowFilename = "cpuUsageWorkflow_{}_{}.json".format(self.clusterName,nodeNumber)
workflowName = "cpuUsage" + str(nodeNumber)
workflows.append(Workflow(workflowFilename, 1, workflowName))
return workflows
def generateConfig(self):
clusterConfigFile=open("clusterConfig.json",'r')
config = json.load(clusterConfigFile)
producers = [ Producer(config['broker'], config['topic']) ]
workflows = self.generateWorkflows(config['cluster'])
workflowConfig = WorkflowConfig(producers,workflows)
self.printToConfigFile(workflowConfig.toJSON())
if __name__=="__main__":
ConfigGenerator().generateConfig()