Merge branch 'master' into '49-upload-all-containers-to-public-repo-in-docker-hub'
authorFabian Eichhorner <fabian.eichhorner@gmail.com>
Sun, 20 Jan 2019 16:47:23 +0000 (17:47 +0100)
committerFabian Eichhorner <fabian.eichhorner@gmail.com>
Sun, 20 Jan 2019 16:47:23 +0000 (17:47 +0100)
# Conflicts:
#   g6t4.yml

14 files changed:
README.md
g6t4.yml
service-analysis/Dockerfile
service-analysis/README.md
service-analysis/analysis.env [new file with mode: 0644]
service-analysis/indico_api_key.txt [deleted file]
service-analysis/sentiment_analysis.py
service-reporting/Dockerfile
service-reporting/README.md
service-twitter/.dockerignore
service-twitter/.idea/runConfigurations/TwitterServiceApplication.xml
service-twitter/README.md
service-twitter/src/main/resources/application.yml
service-twitter/twitter.env [new file with mode: 0644]

index 8b34e9c0f1888f7d782dc7ca0e214d4965ce4b36..0213284f71d031f5418a5284834e77f1af8aaea6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,9 +34,9 @@ We now support multiple hypervisors! :)
 + Main Contributor: Sebastian Steiner
 + external services
     + https://www.indico.io
-    + `API KEY: G6T4/service-analysis/indico_api_key.txt`
-### fallback
-+ Full readme: [fallback](service-fallback/README.md)
+    + `API KEY: G6T4/service-analysis/analysis.env`: `INDICO_API_KEY`
+### failover
++ Full readme: [failover](service-failover/README.md)
 + Main Contributor: Jan Vales
 ### reporting
 + Full readme: [reporting](service-reporting/README.md)
@@ -47,7 +47,8 @@ We now support multiple hypervisors! :)
 + external services
     + https://www.twitter.com
     + `API KEY: G6T4/service-twitter/src/main/resources/application.yml`
-### Web UI
+### website
++ Full readme: [website](service-website/README.md)
 + Main Contributors:
     + Michael Winsauer (UI)
     + Fabian Eichhorner (CSS)
index 52e351fe6c05e37a17af6cc3db0e69f0e14790b1..b17fb435050b531e552e0a1b5225e2a0a5cc56f1 100644 (file)
--- a/g6t4.yml
+++ b/g6t4.yml
@@ -17,6 +17,9 @@ services:
     ports:
       - "8081:8081"
 #    restart: always
+    env_file:
+      - service-analysis/analysis.env
+
 
   service-failover:
     build: ./service-failover
@@ -38,6 +41,8 @@ services:
     ports:
       - "8084:8084"
 #    restart: always
+    env_file:
+      - service-twitter/twitter.env
 
   service-website:
     build: ./service-website
index be70c7c4eb2136b3b72f309eb7c74176110eb7e3..508af5e584e4debe78a7440ed2d578b1407a1431 100644 (file)
@@ -1,8 +1,9 @@
 FROM   python:3.7-slim
-LABEL  maintainer="Sebastian Steiner"
+LABEL  maintainer="Sebastian Steiner <sebastian.steiner@tuwien.ac.at>"
 
 WORKDIR        /app
-COPY   . /app/
+COPY   *.py /app/
+COPY   *.txt /app/
 
 RUN            pip install -r requirements.txt
 
index 57c6b0c795acc0564b84331d2b9beed93cfd6b5b..ed3f0efa45ae48f8756a2818a66bf6d03ff1c9d1 100644 (file)
@@ -1,9 +1,8 @@
 # Sentiment Service
 
-
 ## API
-Provides a REST-API to get the average sentiment of a given list of texts
-The service uses the the sentiment analysis service indico.
+Provides a REST-API to get the average sentiment of a given list of texts.
+The service uses the sentiment analysis service indico.
 
 `GET`: `/` Displays the expected input for a POST
 
@@ -50,24 +49,28 @@ For more examples see curl commands in local -> commands.
 
 ## external services
 This sentiment analysis service uses the online sentiment analysis indico (https://www.indico.io).
-The indico api key can be set in the file indico_api_key.txt. The current key does work, however excessive use of this service will require you to provide your own key, since the amount of requests for this key is limited.
+The indico api key can be set in the file `analysis.env`. The current key does work, however excessive use of this service will require you to provide your own key, since the amount of requests for this key is limited.
 In case of an 503 error, you can use the `/offline_analysis`.
 
 ## run with docker
-- `docker build -t sentiment_analysis .`
-- `docker container run -d -p YOUR_PORT:8081 sentiment_analysis`
+- `docker image build -t service-analysis .`
+- `docker container run --env-file=analysis.env -d -p YOUR_PORT:8081 service-analysis:latest`
 
 ## run local
 ### requirements
 - python 3.7
-- pip: indicoio
-- pip: flask
-- pip: flask_restful
-- pip: textblob
+- pip: 
+    - indicoio
+    - flask
+    - flask_restful
+    - textblob
 ### commands
 - `python3.7 sentiment_analysis.py` to start the service
+
+## examples
 - positive online sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[{"text":"happy birthday, i love you"}]'`
 - negative online sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[{"text":"i hate you, please die"}]'`
 - positive offline sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081/offline_analysis -d '[{"text":"happy birthday, i love you"}]'`
 - negative offline sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081/offline_analysis -d '[{"text":"i hate you, please die"}]'`
-- health check test example: `curl -v -X GET http://localhost:8081/health`
+- health check example: `curl -v -X GET http://localhost:8081/health`
+- invalid input example (error: 409): `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[]'`
diff --git a/service-analysis/analysis.env b/service-analysis/analysis.env
new file mode 100644 (file)
index 0000000..cdc07a4
--- /dev/null
@@ -0,0 +1 @@
+INDICO_API_KEY=525f16078717a430f9dac17cdc9dbaa3
diff --git a/service-analysis/indico_api_key.txt b/service-analysis/indico_api_key.txt
deleted file mode 100644 (file)
index 339d02b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-525f16078717a430f9dac17cdc9dbaa3
index 055a48de5e32b48754779d794a197e614d5be74c..e84402f6b4ea8629632e477776fb86acbfc2ac1d 100644 (file)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 import json
 import indicoio
+import os
 
 from analysis import Analysis
 from offline_analysis import Offline_Analysis
@@ -12,8 +13,7 @@ from flask_restful import Api
 app = Flask(__name__)
 api = Api(app)
 
-with open('indico_api_key.txt', 'r') as key:
-       indicoio.config.api_key = key.read().replace('\n','')
+indicoio.config.api_key = os.environ['INDICO_API_KEY']
 
 api.add_resource(Analysis, '/')
 api.add_resource(Offline_Analysis, '/offline_analysis')
index 1cef98c76e604bdf456185e4c4f5809af384eefd..7e70952c652d573e974cf32cc360ea79295223c4 100644 (file)
@@ -12,6 +12,7 @@ RUN dotnet publish -c Release -o out
 
 # Build runtime image
 FROM microsoft/dotnet:2.2-aspnetcore-runtime
+LABEL maintainer="Fabian Eichhorner <fabian.eichhorner@tuwien.ac.at>"
 WORKDIR /app
 COPY --from=build-env /app/out .
 
@@ -19,9 +20,7 @@ COPY --from=build-env /app/out .
 EXPOSE 8083            
 ENV ASPNETCORE_URLS=http://+:8083
 
-# copy pdf library
-# COPY libwkhtmltox.* ./
-# install additional libaries
+# install pdf libaries
 RUN apt-get update \
     && apt-get install -y --no-install-recommends \
         zlib1g \
index cc0a95af51f9c75a74a886936479064816d3f0f4..64d91a14d2ea14c9fed84a13620035f4e54fab01 100644 (file)
@@ -1,5 +1,6 @@
 # PDF Service
 
+## API
 Provides a REST-API to generate PDF reports for terms and their sentiment analysis results. The service uses an .NET Core wrapper for the wkhtmltopdf library to generate pdf out of html code.
 
 `GET`: `/` Shows a demo page  
@@ -28,13 +29,15 @@ Provides a REST-API to generate PDF reports for terms and their sentiment analys
 ``` 
 - return: pdf file
 
+## API errors
+- `400`: request does not fulfil specification
+
 ### Term model
 Term(string `Name`, double `Sentiment`)
 
 ## run with docker
-
-- `docker build -t service-reporting .`    
-- `docker run -p YOUR_PORT:8083 service-reporting:latest`
+- `docker image build -t service-reporting .`    
+- `docker container run -p YOUR_PORT:8083 service-reporting:latest`
 
 ## run local
 ### requirements
@@ -43,8 +46,8 @@ Term(string `Name`, double `Sentiment`)
 ### commands
 - `dotnet run`
 
-## Tests
+## examples
 - successfull pdf as application/json: `curl -X POST  http://localhost:8083/generatePDF  -H 'Content-Type: application/json'  -d '[ { "name": "A bad term", "sentiment": 0.1 }, { "name": "Another bad term", "sentiment": 0.3 }, { "name": "A neutral term", "sentiment": 0.5 }, { "name": "A good term", "sentiment": 0.65 }, { "name": "Another good term", "sentiment": 0.9 } ] ' -vs > test1.pdf`
 - successfull pdf as application/base64: `curl -X POST http://localhost:8083/generatePDF -H 'Accept: application/base64' -H 'Content-Type: application/json' -d '[ { "name": "A bad term", "sentiment": 0.1 }, { "name": "Another bad term", "sentiment": 0.3 }, { "name": "A neutral term", "sentiment": 0.5 }, { "name": "A good term", "sentiment": 0.65 }, { "name": "Another good term", "sentiment": 0.9 } ] ' -vs | base64 -d > test2.pdf`
 - invalid sentiment value: `curl -X POST http://localhost:8083/generatePDF -H 'Content-Type: application/json' -d '[ { "name": "Term with invalid sentiment value", "sentiment": 12 } ] ' -vs && echo`
-- invalid json structure: `curl -X POST http://localhost:8083/generatePDF -H 'Content-Type: application/json' -d '[ { "name1": "A term with invalid json format", "sentiment": 0.5 } ] ' -vs && echo`
\ No newline at end of file
+- invalid json structure: `curl -X POST http://localhost:8083/generatePDF -H 'Content-Type: application/json' -d '[ { "name1": "A term with invalid json format", "sentiment": 0.5 } ] ' -vs && echo`
index 01dc7368a5d133928134ab8947e5c0988e69b749..80eb53347a0e709741686712fe7dbbf23b6b6a97 100644 (file)
@@ -105,3 +105,4 @@ atlassian-ide-plugin.xml
 README.md
 *.iml
 !/.mvn/wrapper/maven-wrapper.jar
+twitter.env
index a350b35c0a8a90321908d361bef6c7f783b090f8..f570e3f3532d65b7f9e94b58bffe390122af124d 100644 (file)
@@ -1,6 +1,16 @@
 <component name="ProjectRunConfigurationManager">
   <configuration default="false" name="TwitterServiceApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
     <module name="service-twitter" />
+    <extension name="net.ashald.envfile">
+      <option name="IS_ENABLED" value="true" />
+      <option name="IS_SUBST" value="false" />
+      <option name="IS_PATH_MACRO_SUPPORTED" value="false" />
+      <option name="IS_IGNORE_MISSING_FILES" value="false" />
+      <ENTRIES>
+        <ENTRY IS_ENABLED="true" PARSER="runconfig" />
+        <ENTRY IS_ENABLED="true" PARSER="env" PATH="twitter.env" />
+      </ENTRIES>
+    </extension>
     <option name="SPRING_BOOT_MAIN_CLASS" value="at.aic18.g6t4.servicetwitter.TwitterServiceApplication" />
     <option name="ALTERNATIVE_JRE_PATH" />
     <method v="2">
index 79630d0cfc7c5f3905d53be74da11ca4e624addf..d243d035c8ce0d171524a1d8c21871bd3b7d0125 100644 (file)
@@ -1,38 +1,40 @@
 # Twitter Service
 
-
-
 ## API
+Provides a REST-API that mainly mirrors the search API from Twitter.
+The service uses the official Twitter API.
 
 You can use the search under [http://localhost:8084/search/tweets.json?q=Google](http://localhost:8080/search/tweets.json?q=Google)
 where `q` is your search string.
 
-It mainly mirrors the search API from Twitter. My implementation contains some basic fields with the same names as in
-the official API. If you need more, please let me know.
-
-
-### Example
-
-`curl -vs http://localhost:8084/search/tweets.json?q=Google `
-
-Pipe it into e.g. `jq` for a more readable output.
+`GET`: `/search/tweets.json?q=` returns tweets matching the given search term as a set of JSON objects  
+- param: `q` search term
+example: `/search/tweets.json?q=example`
 
+`GET`: `/actuator/health` Returns HTTP Status 200 if service is running
 
+## API errors
+`TODO`
 
-## API Keys
-
-Unfortunately you have to provide your own API Keys, as sharing them is forbidden. In the worst case there would be five
-people using the same keys at the same time. This probably asks for a ban.
-
-I really don't want to risk it, as my application for a [Twitter Developer Platform](https://developer.twitter.com/)
-account was ridiculously complicated. You have to answer four questions, with at least 400 (?) words, and as detailed as
-possible. My application apparently wasn't detailed enough, so they asked me follow up questions. After two emails, one
-with ~1.200 words, they were finally satisfied.
-
+## external services
+This twitter service uses the online twitter api.
+Unfortunately you have to provide your own API Keys, as sharing them is forbidden. In the worst case there would be five people using the same keys at the same time. This probably asks for a ban.
+I really don't want to risk it, as my application for a [Twitter Developer Platform](https://developer.twitter.com/) account was ridiculously complicated. You have to answer four questions, with at least 400 (?) words, and as detailed as possible. My application apparently wasn't detailed enough, so they asked me follow up questions. After two emails, one with ~1.200 words, they were finally satisfied.
 Furthermore people with an existing account, like I had, can't create new apps anymore, unless they apply again.
-
-So I would advise you to [apply for an account](https://developer.twitter.com/en/apply-for-access) yourself, or maybe
-ask someone else from the group if they have a spare key.
-
-The keys then go into `application.yml` below `oauth:`, i.e. `consumer-key`, `consumer-secret`, `access-token`,
-`access-token-secret`.
+So I would advise you to [apply for an account](https://developer.twitter.com/en/apply-for-access) yourself, or maybe ask someone else from the group if they have a spare key.
+The twitter api keys can be set in the file `twitter.env`. 
+
+## run with docker
+- `docker image build -t service-twitter .`
+- `docker container run --env-file=twitter.env -d -p YOUR_PORT:8084 service-twitter:latest`
+
+## run local
+### requirements
+`TODO`
+### commands
+`TODO`
+
+## examples
+- API call example: `curl -vs http://localhost:8084/search/tweets.json?q=Google`
+    - Pipe it into e.g. `jq` for a more readable output.
+- health check test example: `curl -v -X GET http://localhost:8084/actuator/health`
index ac49b95b5459a867fcc931041d4fd1564d1e2342..5b941f40346c6a22a324e1145f6ec5fbc1b8b77f 100644 (file)
@@ -10,7 +10,7 @@ server:
 twitter4j:
   debug: false
   oauth:
-    consumer-key: "DnmBShVqvJ2xfnRjkAWtq644Z"
-    consumer-secret: "YbP2oAdU9IyuYMAUxbyJn1NNKZ91jnOz1CpNKMSCjCR0Pu8JlJ"
-    access-token: "2698046929-w0qbrGWkqKigFTkAaKCkFJc1XoixWG2FPTlU3i3"
-    access-token-secret: "rx88CHkOLbXUuTHDHOdZLnnw5KDeMQkVD2ltlkqWqWmlP"
+    consumer-key: ${CONSUMER_KEY}
+    consumer-secret: ${CONSUMER_SECRET}
+    access-token: ${ACCESS_TOKEN}
+    access-token-secret: ${ACCESS_TOKEN_SECRET}
diff --git a/service-twitter/twitter.env b/service-twitter/twitter.env
new file mode 100644 (file)
index 0000000..5136686
--- /dev/null
@@ -0,0 +1,4 @@
+CONSUMER_KEY=DnmBShVqvJ2xfnRjkAWtq644Z
+CONSUMER_SECRET=YbP2oAdU9IyuYMAUxbyJn1NNKZ91jnOz1CpNKMSCjCR0Pu8JlJ
+ACCESS_TOKEN=2698046929-w0qbrGWkqKigFTkAaKCkFJc1XoixWG2FPTlU3i3
+ACCESS_TOKEN_SECRET=rx88CHkOLbXUuTHDHOdZLnnw5KDeMQkVD2ltlkqWqWmlP