From ba617243a73b56151b0e6f5a9b01e11c59cc0763 Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Thu, 8 Nov 2018 22:38:39 +0100 Subject: [PATCH] modify deployment process --- camunda-overlay/camunda-deploy.sh | 20 --- camunda-overlay/camunda.py | 62 ++++++++ camunda-overlay/sentiment-analysis.bpmn | 186 ++++++++++++------------ 3 files changed, 155 insertions(+), 113 deletions(-) delete mode 100755 camunda-overlay/camunda-deploy.sh create mode 100755 camunda-overlay/camunda.py diff --git a/camunda-overlay/camunda-deploy.sh b/camunda-overlay/camunda-deploy.sh deleted file mode 100755 index 1158825..0000000 --- a/camunda-overlay/camunda-deploy.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -camunda="http://localhost:8080" -camunda_deployment="${camunda}/engine-rest/deployment" -deployment_name="Sentiment Analysis" - -# find old deployments named ${deployment_name} -old_ids=`curl -s ${camunda_deployment}/ | python3 -c "import sys, json; doc = json.load(sys.stdin); items = [deployment['id'] for deployment in doc if deployment['name'] == '${deployment_name}']; print (*items, sep = '\n')"` -# delete all old deployments -for old_id in ${old_ids}; do - curl -s -X DELETE "${camunda_deployment}/${old_id}?cascade=true" -done - -# deploy new verson -curl -si "${camunda_deployment}/create" \ - -H "Expect:" \ - -F "deployment-name=${deployment_name}" \ - -F "sentiment-analysis.bpmn=@sentiment-analysis.bpmn" \ - -F "input-forms.html=@forms/input-terms.html" \ - -F "download-pdf.html=@forms/download-pdf.html" diff --git a/camunda-overlay/camunda.py b/camunda-overlay/camunda.py new file mode 100755 index 0000000..486e8a2 --- /dev/null +++ b/camunda-overlay/camunda.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import sys +import os +import json +import requests +import argparse + +CAMUNDA="http://localhost:8080/engine-rest/" + +def get_current_deployments(key = 'sentiment-analysis'): + res = requests.get(CAMUNDA + "deployment") + return [proc for proc in res.json() if proc['name'] == key] + +def cleanup_old_deployments(key='sentiment-analysis'): + print ("Cleaning up old deployments") + for deployment in get_current_deployments(key): + res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true") + if (res.status_code == 204): + print ("Cleaned up deployment {}".format(deployment['id'])) + else: + print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code)) + +def create_deployment(initial=False): + files = [ + ("deployment-name", "sentiment-analysis"), + ("file1", open("sentiment-analysis.bpmn")), + ("file2", open("forms/input-terms.html")), + ("file3", open("forms/download-pdf.html")), + ] + if not initial: + cleanup_old_deployments() + res = requests.post(CAMUNDA + "deployment/create", files=files) + if (res.status_code == 200): + print ("Successfully deployed Sentiment Analysis") + else: + from pprint import pprint + pprint ("Status Code: {}".format(res.status_code)) + try: + pprint(res.json()) + except: + pprint(res.content) + +def submit_terms(terms=[]): + termlist = [{'term': term} for term in terms] + # submit to camunda + pass + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--deploy', dest='deploy', default=True, action='store_false', help="Do deployment step") + parser.add_argument('--initial', dest='initial', default=False, action='store_true', help="Initial deploy does not need cleanup") + parser.add_argument('--autoclick', dest='autoclick', type=int, nargs=1, help="How many steps to autoclick") + args = parser.parse_args() + + if args.deploy: + # initialize camunda process + create_deployment(initial=args.initial) + + if args.autoclick >= 1: + # start clicking + submit_terms(["voting", "phonegate", "35c3"]) diff --git a/camunda-overlay/sentiment-analysis.bpmn b/camunda-overlay/sentiment-analysis.bpmn index 29e6337..f5a55e8 100644 --- a/camunda-overlay/sentiment-analysis.bpmn +++ b/camunda-overlay/sentiment-analysis.bpmn @@ -1,29 +1,10 @@ - + - + - - - - - - - - - - - - - - - All terms are analyzed - ${terms}==[] - - - SequenceFlow_0tu3w40 @@ -62,8 +43,6 @@ SequenceFlow_1inwzje SequenceFlow_0h1h7gs - - SequenceFlow_0fct5f2 @@ -85,7 +64,6 @@ PT1M - SequenceFlow_1gbx7mw SequenceFlow_0yqo6md @@ -126,7 +104,6 @@ SequenceFlow_1gbx7mw "" - SequenceFlow_0f33zny SequenceFlow_11ge7w6 @@ -145,167 +122,190 @@ nt["term"] = "newterm" terms += nt return "" - + + + + + + + + + + + + + + + All terms are analyzed + ${terms}==[] + + + + + + + collect all analyze results + - + - + - + - - + + - - + + - + - - - + + + - - + + - + - - + + - + - + - - + + - - + + - - + + - + - - + + - - - + + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - + - + - - + + - + - + - - + + -- 2.43.0