Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lallinger-tech authored Sep 10, 2019
0 parents commit 860e94b
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions process.py
Original file line number Diff line number Diff line change
@@ -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))

5 changes: 5 additions & 0 deletions push.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions sendData.sh
Original file line number Diff line number Diff line change
@@ -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/
22 changes: 22 additions & 0 deletions service.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 860e94b

Please sign in to comment.