diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de04b3f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# Use the official Python image. +# https://hub.docker.com/_/python +FROM python:3.7 + +# Copy local code to the container image. +ENV APP_HOME /process +WORKDIR $APP_HOME +COPY . . + +# Install production dependencies. +RUN pip install Flask gunicorn azure-storage-blob + +# Run the web service on container startup. Here we use the gunicorn +# webserver, with one worker process and 8 threads. +# For environments with multiple CPU cores, increase the number of workers +# to be equal to the cores available. +CMD exec gunicorn --bind :8080 --workers 1 --threads 8 process:app \ No newline at end of file diff --git a/process.py b/process.py new file mode 100644 index 0000000..3a9ba9d --- /dev/null +++ b/process.py @@ -0,0 +1,54 @@ +import os, json, uuid, sys + +from flask import Flask +from flask import request +from azure.storage.blob import BlockBlobService, PublicAccess + +app = Flask(__name__) + +def fibo(count): + if count==1 or count==2: + return 1 + + return fibo(count-1)+fibo(count-2) + +def preprocessing(data): + pieces = data.split(",") + pieces[1] = str(fibo(int(pieces[1]))) + return ','.join(pieces) + + +def process(data): + user=os.environ['STORAGE_USERNAME'] + password=os.environ['STORAGE_PASSWORD'] + container_landing ='landingzone' + container_staging = 'staging' + block_blob_service = BlockBlobService(account_name=user, account_key=password) + + local_path = os.path.expanduser("~/tmp") + local_file_name = data["data"]["url"].split("/")[-1] + full_path_to_file = os.path.join(local_path, local_file_name) + + block_blob_service.get_blob_to_path(container_landing, local_file_name, full_path_to_file) + + f = open(full_path_to_file,"r") + content = f.read() + f.close() + + f = open(full_path_to_file,"w") + f.write(preprocessing(content)) + f.close() + + block_blob_service.create_blob_from_path(container_staging, local_file_name, full_path_to_file) + os.remove(full_path_to_file) + block_blob_service.delete_blob(container_landing,local_file_name,delete_snapshots='include') + + +@app.route('/', methods=['PUT','POST']) +def receive(): + process(request.get_json()) + return 'OK\n' + +if __name__ == "__main__": + app.run(debug=True,host='0.0.0.0',port=int(8080)) + diff --git a/push.sh b/push.sh new file mode 100644 index 0000000..6323a6a --- /dev/null +++ b/push.sh @@ -0,0 +1,5 @@ +docker build -t lallinger/process . --build-arg HTTP_PROXY=$http_proxy --build-arg HTTPS_PROXY=$http_proxy +docker push lallinger/process +oc project process +oc delete -f service.yaml +oc create -f service.yaml \ No newline at end of file diff --git a/sendData.sh b/sendData.sh new file mode 100644 index 0000000..41b55e1 --- /dev/null +++ b/sendData.sh @@ -0,0 +1,8 @@ +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + count=10 +else + count=$1 +fi + +curl -X POST -H "Content-Type: application/json" -d '{"name":"simple","count":'"$count"',"meta":"test"}' -k https://extract-transform.extract-transform.c2.1eu1.apps-d.rohde-schwarz.com/ diff --git a/service.yaml b/service.yaml new file mode 100644 index 0000000..dcc7105 --- /dev/null +++ b/service.yaml @@ -0,0 +1,22 @@ +apiVersion: serving.knative.dev/v1alpha1 +kind: Service +metadata: + name: process + namespace: process +spec: + template: + spec: + containers: + - image: docker.io/lallinger/process:latest + imagePullPolicy: Always + env: + - name: STORAGE_USERNAME + valueFrom: + secretKeyRef: + name: storage-account-secret + key: username + - name: STORAGE_PASSWORD + valueFrom: + secretKeyRef: + name: storage-account-secret + key: password \ No newline at end of file