8 from pprint import pprint
10 CAMUNDA="http://localhost:8080/engine-rest/"
12 def get_current_deployments(key = 'sentiment-analysis'):
13 res = requests.get(CAMUNDA + "deployment")
14 #return [proc for proc in res.json() if proc['name'] == key]
17 def get_current_process_instances(key = 'sentiment-analysis'):
18 res = requests.get(CAMUNDA + 'process-instance')
22 return [instance for instance in res.json() if instance['definitionId'].startswith(key + ":")]
24 def cleanup_old_deployments(key='sentiment-analysis'):
25 print ("Cleaning up old deployments")
26 for deployment in get_current_deployments(key):
27 res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true&skipCustomListeners=true")
28 if (res.status_code == 204):
29 print ("Cleaned up deployment {}".format(deployment['id']))
31 print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code))
37 def create_deployment(cleanup=False):
39 ("deployment-name", "sentiment-analysis"),
40 #("enable-duplicate-filtering", "true"),
41 #("deploy-changed-only", "true"),
42 ("file1", open("sentiment-analysis.bpmn")),
43 ("file2", open("forms/input-terms.html")),
44 ("file3", open("forms/download-pdf.html")),
47 cleanup_old_deployments()
48 res = requests.post(CAMUNDA + "deployment/create", files=parameters)
49 if (res.status_code == 200):
50 print ("Successfully deployed Sentiment Analysis")
52 pprint ("Status Code: {}".format(res.status_code))
58 def submit_terms(terms):
59 termlist = [{'term': term} for term in terms]
64 'value': json.dumps(termlist),
67 'serializationDataFormat': "application/json",
72 res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
73 if (res.status_code == 200):
74 print ("Successfully started Sentiment Analysis")
76 pprint ("Status Code: {}".format(res.status_code))
81 import xml.dom.minidom
82 content = res.content.decode('utf-8').replace('<!doctype html>', '')
83 print(xml.dom.minidom.parseString(content).toprettyxml())
88 instances = get_current_process_instances()
89 if len(instances) == 0:
90 print ("Error: no running instance found.")
92 instance = instances[0]['id']
93 res = requests.get(CAMUNDA + 'process-instance/' + instance + '/variables')
99 if __name__ == "__main__":
100 parser = argparse.ArgumentParser()
101 parser.add_argument('--no-deploy', dest='deploy', default=True, action='store_false', help="Do not run the deployment step")
102 parser.add_argument('--no-cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy does not need cleanup")
103 parser.add_argument('--autoclick', dest='autoclick', type=int, default=0, help="How many steps to autoclick")
104 args = parser.parse_args()
107 # initialize camunda process
108 create_deployment(cleanup=args.cleanup)
110 if args.autoclick >= 1:
112 submit_terms(["voting", "phonegate", "35c3"])
114 if args.autoclick >= 2: