]> git.somenet.org - pub/jan/aic18.git/blob - camunda-overlay/camunda.py
modify deployment process
[pub/jan/aic18.git] / camunda-overlay / camunda.py
1 #!/usr/bin/env python3
2
3 import sys
4 import os
5 import json
6 import requests
7 import argparse
8
9 CAMUNDA="http://localhost:8080/engine-rest/"
10
11 def get_current_deployments(key = 'sentiment-analysis'):
12     res = requests.get(CAMUNDA + "deployment")
13     return [proc for proc in res.json() if proc['name'] == key]
14
15 def cleanup_old_deployments(key='sentiment-analysis'):
16     print ("Cleaning up old deployments")
17     for deployment in get_current_deployments(key):
18         res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true")
19         if (res.status_code == 204):
20             print ("Cleaned up deployment {}".format(deployment['id']))
21         else:
22             print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code))
23
24 def create_deployment(initial=False):
25     files = [
26             ("deployment-name", "sentiment-analysis"),
27             ("file1", open("sentiment-analysis.bpmn")),
28             ("file2", open("forms/input-terms.html")),
29             ("file3", open("forms/download-pdf.html")),
30             ]
31     if not initial:
32         cleanup_old_deployments()
33     res = requests.post(CAMUNDA + "deployment/create", files=files)
34     if (res.status_code == 200):
35         print ("Successfully deployed Sentiment Analysis")
36     else:
37         from pprint import pprint
38         pprint ("Status Code: {}".format(res.status_code))
39         try:
40             pprint(res.json())
41         except:
42             pprint(res.content)
43
44 def submit_terms(terms=[]):
45     termlist = [{'term': term} for term in terms]
46     # submit to camunda
47     pass
48
49 if __name__ == "__main__":
50     parser = argparse.ArgumentParser()
51     parser.add_argument('--deploy', dest='deploy', default=True, action='store_false', help="Do deployment step")
52     parser.add_argument('--initial', dest='initial', default=False, action='store_true', help="Initial deploy does not need cleanup")
53     parser.add_argument('--autoclick', dest='autoclick', type=int, nargs=1, help="How many steps to autoclick")
54     args = parser.parse_args()
55
56     if args.deploy:
57         # initialize camunda process
58         create_deployment(initial=args.initial)
59
60     if args.autoclick >= 1:
61         # start clicking
62         submit_terms(["voting", "phonegate", "35c3"])