-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from ostelco/develop
Merge Develop to Master
- Loading branch information
Showing
30 changed files
with
539 additions
and
80 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
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
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
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
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,24 @@ | ||
FROM ubuntu:17.10 | ||
|
||
MAINTAINER CSI "[email protected]" | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
curl=7.55.1-1ubuntu2.4 \ | ||
uuid-runtime=2.30.1-0ubuntu4.1 \ | ||
lsb-release=9.20160110ubuntu5 \ | ||
ca-certificates=20170717 \ | ||
&& echo "deb http://packages.cloud.google.com/apt cloud-sdk-artful main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \ | ||
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \ | ||
&& apt-get update && apt-get install -y --no-install-recommends \ | ||
google-cloud-sdk=198.0.0-0 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY script/idle.sh /idle.sh | ||
COPY script/export_data.sh /export_data.sh | ||
COPY script/delete_export_data.sh /delete_export_data.sh | ||
|
||
RUN chmod +x /idle.sh | ||
RUN chmod +x /export_data.sh | ||
RUN chmod +x /delete_export_data.sh | ||
|
||
CMD ["/idle.sh"] |
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,50 @@ | ||
# Exporter | ||
|
||
This contains a set of scripts to generate the data for analayis. The export script | ||
`export_data.sh` creates a new big query table with a new uuid which maps the pseudonyms to | ||
msisdn. This table is then used to join the hourly data consumption to create a new | ||
pseudonymised version of hourly consumption. The output doesn't contain msisdns. The output | ||
table is then exported as a csv file in google cloud storage. There is also a script | ||
`delete_export_data.sh` to delete these tables & files. | ||
|
||
Currently this is deployed as a pod. The commands can be run by logging into the container. | ||
|
||
Tables created: | ||
1) exported_pseudonyms.<exportId> : The pseudonyms table, which can be used to reverse lookup msisdns | ||
2) exported_data_consumption.<exportId> : The output hourly consumption table, used to export data to csv | ||
|
||
How to deploy/use this in kubernetes cluster | ||
|
||
``` | ||
#PROJECT_ID=pantel-2decb | ||
export PROJECT_ID="$(gcloud config get-value project -q)" | ||
# Create cluster | ||
gcloud container clusters create private-cluster --scopes=default,bigquery,datastore,pubsub,sql,storage-rw --num-nodes=3 | ||
# Get authentication credentials for the cluster | ||
gcloud container clusters get-credentials private-cluster | ||
# Build the Docker image (In the folder with Dockerfile) | ||
docker build -t gcr.io/${PROJECT_ID}/exporter:v1 . | ||
# Push to the registry | ||
gcloud docker -- push gcr.io/${PROJECT_ID}/exporter:v1 | ||
# Apply the deployment | ||
kubectl apply -f ./exporter.yaml | ||
# Details of the deployment | ||
kubectl describe deployment exporter | ||
kubectl get pods | ||
# Login to the pod | ||
kubectl exec -it <exporter pod name> -- /bin/bash | ||
# Run exporter from the above shell | ||
/export_data.sh | ||
# Delete deployment | ||
kubectl delete deployment exporter | ||
``` |
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,20 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: exporter | ||
labels: | ||
app: exporter | ||
tier: backend | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: exporter | ||
tier: backend | ||
spec: | ||
containers: | ||
- name: exporter | ||
image: gcr.io/pantel-2decb/exporter:v2.1 | ||
ports: | ||
- containerPort: 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,25 @@ | ||
#!/bin/bash | ||
#set -x | ||
|
||
exportId=$1 | ||
if [ -z "$1" ]; then | ||
echo "Specify the id of the export operation you want to delete" | ||
exit | ||
fi | ||
exportId=${exportId//-} | ||
exportId=${exportId,,} | ||
projectId=pantel-2decb | ||
|
||
pseudonymsTable=exported_pseudonyms.$exportId | ||
dataConsumptionTable=exported_data_consumption.$exportId | ||
csvfile=$projectId-dataconsumption-export/$exportId.csv | ||
|
||
echo "Cleaning all data for export $exportId" | ||
echo "Deleting Table $pseudonymsTable" | ||
bq rm -f -t $pseudonymsTable | ||
echo "Deleting Table $dataConsumptionTable" | ||
bq rm -f -t $dataConsumptionTable | ||
echo "Deleting csv gs://$csvfile" | ||
gsutil rm gs://$csvfile | ||
|
||
echo "Finished cleanup for the export $exportId" |
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,66 @@ | ||
#!/bin/bash | ||
#set -x | ||
|
||
exportId=$1 | ||
if [ -z "$1" ]; then | ||
exportId=$(uuidgen) | ||
fi | ||
exportId=${exportId//-} | ||
exportId=${exportId,,} | ||
projectId=pantel-2decb | ||
|
||
pseudonymsTable=$projectId.exported_pseudonyms.$exportId | ||
hourlyConsumptionTable=$projectId.data_consumption.hourly_consumption | ||
dataConsumptionTable=exported_data_consumption.$exportId | ||
csvfile=$projectId-dataconsumption-export/$exportId.csv | ||
|
||
# Generate the pseudonym tables for this export | ||
echo "Starting export job for $exportId" | ||
pseudonymHost="pseudonym-server-service.default.svc.cluster.local" | ||
startUrl="http://$pseudonymHost/pseudonym/export/$exportId" | ||
httpStatus=$(curl -sL -w "%{http_code}" $startUrl -o /dev/null) | ||
|
||
if [[ $httpStatus != 200 ]]; then | ||
echo "Failed to start the pseudonym table creation: $httpStatus" | ||
exit | ||
fi | ||
|
||
# Wait for the table creation to finish | ||
echo "Waiting to finish table export for $exportId" | ||
sleep 30 & | ||
queryUrl="http://$pseudonymHost/pseudonym/exportstatus/$exportId" | ||
httpStatus=$(curl -sL -w "%{http_code}" $queryUrl -o /dev/null) | ||
if [[ $httpStatus != 200 ]]; then | ||
echo "Failed to query the table creation: $httpStatus" | ||
exit | ||
fi | ||
|
||
jsonResult=RUNNING | ||
while [[ $jsonResult = RUNNING || $jsonResult = INITIAL ]]; do | ||
jsonResult=$(curl -X GET $queryUrl 2> /dev/null | sed -n -e 's/.*"status"://p'| cut -d \" -f 2) | ||
done | ||
if [[ $jsonResult != FINISHED ]]; then | ||
echo "Table creation failed $(curl -X GET $queryUrl 2> /dev/null)" | ||
exit | ||
fi | ||
echo "Created Table $pseudonymsTable" | ||
|
||
|
||
echo "Creating table $dataConsumptionTable" | ||
# SQL for joining pseudonym & hourly consumption tables. | ||
read -r -d '' sqlForJoin << EOM | ||
SELECT | ||
hc.bytes, ps.msisdnid, hc.timestamp | ||
FROM | ||
\`$hourlyConsumptionTable\` as hc | ||
JOIN | ||
\`$pseudonymsTable\` as ps | ||
ON ps.msisdn = hc.msisdn | ||
EOM | ||
# Run the query using bq & dump results to the new table | ||
bq --location=EU --format=none query --destination_table $dataConsumptionTable --replace --use_legacy_sql=false $sqlForJoin | ||
echo "Created table $dataConsumptionTable" | ||
|
||
echo "Exporting data to csv $csvfile" | ||
bq --location=EU extract --destination_format=CSV $dataConsumptionTable gs://$csvfile | ||
echo "Exported data to gs://$csvfile" |
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,18 @@ | ||
#!/bin/bash | ||
|
||
echo "This is a idle script (infinite loop) to keep container running." | ||
echo "Please replace this script." | ||
|
||
cleanup () | ||
{ | ||
kill -s SIGTERM $! | ||
exit 0 | ||
} | ||
|
||
trap cleanup SIGINT SIGTERM | ||
|
||
while [ 1 ] | ||
do | ||
sleep 60 & | ||
wait $! | ||
done |
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.