From: David Kaufmann Date: Sun, 25 Nov 2018 21:46:13 +0000 (+0100) Subject: Merge branch '17-change-reporting-service-rest-parameter' into 'master' X-Git-Tag: code-freeze~36 X-Git-Url: https://git.somenet.org/pub/jan/aic18.git/commitdiff_plain/574ba58c9e2c965fec9f0731caf76e88de86e0af?hp=4c0c194309314288cca97084a454e435a12b29e2 Merge branch '17-change-reporting-service-rest-parameter' into 'master' Resolve "Change reporting-service rest parameter" Closes #17 See merge request aic18/G6T4!16 --- diff --git a/camunda-overlay/camunda-deploy.sh b/camunda-overlay/camunda-deploy.sh deleted file mode 100755 index 60d4d63..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 -i "${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..da4e5d7 --- /dev/null +++ b/camunda-overlay/camunda.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 + +import sys +import os +import json +import requests +import argparse +from pprint import pprint + +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] + return res.json() + +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&skipCustomListeners=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)) + try: + pprint(res.json()) + except: + pprint(res.content) + +def create_deployment(cleanup=False): + parameters = [ + ("deployment-name", "sentiment-analysis"), + #("enable-duplicate-filtering", "true"), + #("deploy-changed-only", "true"), + ("file1", open("sentiment-analysis.bpmn")), + ("file2", open("forms/input-terms.html")), + ("file3", open("forms/download-pdf.html")), + ] + if cleanup: + cleanup_old_deployments() + res = requests.post(CAMUNDA + "deployment/create", files=parameters) + if (res.status_code == 200): + print ("Successfully deployed Sentiment Analysis") + else: + 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 + params = { + 'variables': { + 'terms': { + 'value': json.dumps(termlist), + 'type': "json", + 'valueInfo': { + 'serializationDataFormat': "application/json", + } + } + } + } + res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params) + if (res.status_code == 200): + print ("Successfully started Sentiment Analysis") + else: + pprint ("Status Code: {}".format(res.status_code)) + try: + pprint(res.json()) + except: + try: + import xml.dom.minidom + content = res.content.decode('utf-8').replace('', '') + print(xml.dom.minidom.parseString(content).toprettyxml()) + except: + pprint(res.content) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--deploy', dest='deploy', default=True, action='store_false', help="Do deployment step") + parser.add_argument('--no-cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy does not need cleanup") + parser.add_argument('--autoclick', dest='autoclick', type=int, default=0, help="How many steps to autoclick") + args = parser.parse_args() + + if args.deploy: + # initialize camunda process + create_deployment(cleanup=args.cleanup) + + if args.autoclick >= 1: + # start clicking + submit_terms(["voting", "phonegate", "35c3"]) diff --git a/camunda-overlay/forms/download-pdf.html b/camunda-overlay/forms/download-pdf.html index 3fc7e07..4a50a18 100644 --- a/camunda-overlay/forms/download-pdf.html +++ b/camunda-overlay/forms/download-pdf.html @@ -1 +1,3 @@ -

There is no pdf right now.

+
+

Download:

+
diff --git a/camunda-overlay/sentiment-analysis.bpmn b/camunda-overlay/sentiment-analysis.bpmn index 29e6337..0063757 100644 --- a/camunda-overlay/sentiment-analysis.bpmn +++ b/camunda-overlay/sentiment-analysis.bpmn @@ -1,312 +1,204 @@ - - + + - + - - - - - - - - - - - - - - - All terms are analyzed - ${terms}==[] - - - + + + + + + + + // make variable global +execution.setVariable("results", S('[]')) + + + SequenceFlow_15dip2q + + + + + // make variables local to loop +execution.setVariable("analysis", 0, "terms_loop"); +execution.setVariable('tweets', S('[]'), "terms_loop"); + + + var results = execution.getVariable("results"); +var term = execution.getVariable("term"); +var analysis = execution.getVariable("analysis"); +var termStr = term.prop('term').value(); + +// this is for dictionary +//results.prop(termStr, analysis); +// this is for list +var item = {}; +item[termStr] = analysis; +results.append(item) + +execution.setVariable("results", S(results)) + + + SequenceFlow_15dip2q + SequenceFlow_1j2y6tv + + + + + + http://analysis:8081/ + POST + + + application/json + application/json + + + ${tweets.toString()} + + var response = connector.getVariable("response"); +response.trim() + + + http-connector + + + SequenceFlow_0g6bfz6 + SequenceFlow_1bz7zx2 + + + + + + + var term = execution.getVariable("term"); +'http://twitter:8084/search/tweets.json?q='+term.prop('term').value() + + GET + + + application/json + + + + var response = connector.getVariable("response"); +S(response); + + + http-connector + + + SequenceFlow_0f6v4j4 + SequenceFlow_0g6bfz6 + + + SequenceFlow_0f6v4j4 + + + + + + SequenceFlow_1bz7zx2 + + - SequenceFlow_0tu3w40 - - SequenceFlow_0jebdb9 - SequenceFlow_0tu3w40 - - PT1M - - + + + + + + http://reporting:8083/generatePDF/ + POST + + + application/pdf + application/json + + + ${results.toString()} + + var response = connector.getVariable("response"); +print ("response: ") +print (response) +var file = Java.type('org.camunda.bpm.engine.variable.Variables').fileValue("pdfTest").file(response.getBytes("utf-8")).mimeType('application/pdf').create() +//response.getBytes("utf-8") +file + + + http-connector + + + SequenceFlow_1j2y6tv + SequenceFlow_14nqu0e + - SequenceFlow_0ez6lnk + SequenceFlow_14nqu0e SequenceFlow_0jebdb9 - - SequenceFlow_03ohp0o - SequenceFlow_12s5p9s - - PT1M - - - - SequenceFlow_1gdqfur - SequenceFlow_1inwzje - - PT1M - - - - SequenceFlow_11xavl5 - - - SequenceFlow_12s5p9s - - - SequenceFlow_1inwzje - SequenceFlow_0h1h7gs - - - - - SequenceFlow_0fct5f2 - - - SequenceFlow_0ra8hjs - SequenceFlow_0ez6lnk - SequenceFlow_03ohp0o - "" - - - SequenceFlow_07bm292 - SequenceFlow_0bzf3di - "" - - - SequenceFlow_0h1h7gs - SequenceFlow_07bm292 - - PT1M - - - - - SequenceFlow_1gbx7mw - SequenceFlow_0yqo6md - - PT1M - - - - SequenceFlow_0yqo6md - SequenceFlow_0okj60f - SequenceFlow_10v2c9r - - - SequenceFlow_10v2c9r - SequenceFlow_0e9hshn - - PT1M - - - - SequenceFlow_0okj60f - SequenceFlow_0ra8hjs - - PT1M - - - - SequenceFlow_0bzf3di - SequenceFlow_0fct5f2 - - PT1M - - - - SequenceFlow_0e9hshn - SequenceFlow_11ge7w6 - SequenceFlow_1gdqfur - SequenceFlow_1gbx7mw - "" - - - - SequenceFlow_0f33zny - SequenceFlow_11ge7w6 - - PT1M - - - - SequenceFlow_11xavl5 - SequenceFlow_0f33zny - for ( i in terms) { - println "line found: " + i -} -nt = {} -nt["term"] = "newterm" -terms += nt -return "" - - - - collect all analyze results - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - + + - - + + - - - - - - - - - - - - - - + + - - - + + + - - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + - - - + + + - - - - - - - - - - - - - - - + + + - - - - - - - - - + + + - - - - - - - - - + + + - - + + - - - - - - - diff --git a/docker-compose.yml b/docker-compose.yml index 8e7d00e..58b4096 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,7 +30,7 @@ services: build: ./service-reporting container_name: reporting ports: - - "8083:80" + - "8083:8083" restart: always service-twitter: diff --git a/provision.sh b/provision.sh index 90c7099..eeb2084 100755 --- a/provision.sh +++ b/provision.sh @@ -5,14 +5,21 @@ cd /vagrant ############################### # Get Docker + Docker-Compose # ############################### -apt-get update -apt-get install -y -q apt-transport-https vim +# Check for updates only once per boot. +dpkg-query -W docker-ce docker-compose &>/dev/null || rm -f /tmp/apt_run_this_boot -wget -q "https://download.docker.com/linux/debian/gpg" -O - | apt-key add -echo "deb https://download.docker.com/linux/debian stretch stable" > /etc/apt/sources.list.d/docker_com.list +if [ ! -f /tmp/apt_run_this_boot ]; then + apt-get update + apt-get install -y -q apt-transport-https vim -apt-get update -apt-get install -y -q docker-ce docker-compose + wget -q "https://download.docker.com/linux/debian/gpg" -O - | apt-key add + echo "deb https://download.docker.com/linux/debian stretch stable" > /etc/apt/sources.list.d/docker_com.list + + apt-get update + apt-get install -y -q docker-ce docker-compose + + date -Isec > /tmp/apt_run_this_boot +fi ############################# # remove running containers # diff --git a/service-fallback/README.md b/service-fallback/README.md new file mode 100644 index 0000000..d3a44f8 --- /dev/null +++ b/service-fallback/README.md @@ -0,0 +1,3 @@ +# Fallback service + +tbd \ No newline at end of file diff --git a/service-reporting/Dockerfile b/service-reporting/Dockerfile index c372a86..080fad4 100644 --- a/service-reporting/Dockerfile +++ b/service-reporting/Dockerfile @@ -1,6 +1,7 @@ FROM microsoft/dotnet:2.2.100-preview3-sdk AS build-env WORKDIR /app + # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore @@ -14,6 +15,10 @@ FROM microsoft/dotnet:2.2.0-preview3-aspnetcore-runtime WORKDIR /app COPY --from=build-env /app/out . +# set ports +EXPOSE 8083 +ENV ASPNETCORE_URLS=http://+:8083 + # copy pdf library # COPY libwkhtmltox.* ./ # install additional libaries @@ -29,7 +34,6 @@ RUN apt-get update \ --location \ https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so - # copy assets COPY assets/*.css ./assets/ ENTRYPOINT ["dotnet", "PdfService.dll"] \ No newline at end of file