-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 860e94b
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |