-
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.
Merge pull request #45 from mwvgroup/development
Development
- Loading branch information
Showing
23 changed files
with
399 additions
and
473 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Cloud Functions | ||
|
||
This directory contains cloud functions used by the Pitt-Google Broker. | ||
Source code for each function is stored in a dedicated directory | ||
and is accompanied by a bash script that deploys the cloud function | ||
to the Google Cloud Platform. | ||
|
||
For more information on cloud functions, see: https://cloud.google.com/functions | ||
|
||
| Function | Description | | ||
|---|---| | ||
| `GCS_to_BQ` | Load the contents of avro files from Google Cloud Storage (GCP) into Big Query (BQ) | | ||
| `scheduleinstance` | Deploys and schedules the execution of functions for launching virtual machines that ingest ZTF data into BQ | |
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,38 @@ | ||
#!/bin/sh | ||
|
||
echo "WARNING: Make sure you have updated the values of [IMAGE NAME] and [VERSION] with the values of the current Docker image using this script.\n" | ||
# version number should be most recent commit used to build the image | ||
# git log -1 --format=format:"%H" | ||
|
||
# Configure gcloud as a Docker credential helper | ||
gcloud auth configure-docker gcr.io/ardent-cycling-243415/consumeztf | ||
|
||
# Create 2 instances of the consumer | ||
gcloud compute instances create-with-container consume-ztf-1 --zone=us-central1-a --machine-type=f1-micro --image-project=cos-cloud --container-image=gcr.io/ardent-cycling-243415/consumeztf:7019f8aa86ffe16dcb36fa791dc2fb7e56bb687f --labels=env=consume-ztf-1 --image=cos-stable-81-12871-1190-0 --service-account=591409139500-compute@developer.gserviceaccount.com --scopes=cloud-platform | ||
gcloud compute instances create-with-container consume-ztf-2 --zone=us-central1-a --machine-type=f1-micro --image-project=cos-cloud --container-image=gcr.io/ardent-cycling-243415/consumeztf:7019f8aa86ffe16dcb36fa791dc2fb7e56bb687f --labels=env=consume-ztf-2 --image=cos-stable-81-12871-1190-0 --service-account=591409139500-compute@developer.gserviceaccount.com --scopes=cloud-platform | ||
|
||
|
||
# Create the Pub/Sub topics to trigger starting and stopping the instance | ||
gcloud pubsub topics create start-instance-event | ||
gcloud pubsub topics create stop-instance-event | ||
|
||
|
||
# Create the cloud functions to publish to PubSub | ||
|
||
cd scheduleinstance/ | ||
|
||
gcloud functions deploy startInstancePubSub --trigger-topic start-instance-event --runtime nodejs8 | ||
|
||
gcloud functions deploy stopInstancePubSub --trigger-topic stop-instance-event --runtime nodejs8 | ||
|
||
# Finally, schedule the PubSub messages that trigger the cloud functions. | ||
|
||
# Reset consume-ztf-1 on odd days | ||
gcloud scheduler jobs create pubsub stop-consume-ztf-1 --schedule '0 9 1-31/2 * *' --topic stop-instance-event --message-body '{"zone":"us-west1-b", "label":"env=consume-ztf-1"}' --time-zone 'America/Los_Angeles' | ||
|
||
gcloud scheduler jobs create pubsub start-consume-ztf-1 --schedule '0 17 1-31/2 * *' --topic start-instance-event --message-body '{"zone":"us-west1-b", "label":"env=consume-ztf-1"}' --time-zone 'America/Los_Angeles' | ||
|
||
# Reset consume-ztf-2 on even days | ||
gcloud scheduler jobs create pubsub stop-consume-ztf-2 --schedule '0 0 2-30/2 * *' --topic stop-instance-event --message-body '{"zone":"us-west1-b", "label":"env=consume-ztf-2"}' --time-zone 'America/Los_Angeles' | ||
|
||
gcloud scheduler jobs create pubsub start-consume-ztf-2 --schedule '0 0 2-30/2 * *' --topic start-instance-event --message-body '{"zone":"us-west1-b", "label":"env=consume-ztf-2"}' --time-zone 'America/Los_Angeles' |
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 |
---|---|---|
@@ -1,23 +1,41 @@ | ||
FROM python:3.7 | ||
# Slim used to reduce image size | ||
FROM python:3.7-slim | ||
|
||
# Configure Environment variables | ||
ENV PYTHONPATH "Pitt-Google-Broker/:${PYTHONPATH}" | ||
ENV GOOGLE_CLOUD_PROJECT "ardent-cycling-243415" | ||
ENV ztf_server "public2.alerts.ztf.uw.edu:9094" | ||
ENV ztf_principle "[email protected]" | ||
ENV ztf_keytab_path "pitt-reader.user.keytab" | ||
ENV PATH="/root/miniconda3/bin:${PATH}" | ||
ARG PATH="/root/miniconda3/bin:${PATH}" | ||
|
||
# Copy credentials and runtime files | ||
COPY docker_files/consume_ztf.py docker_files/consume_ztf.py | ||
COPY krb5.conf /etc/krb5.conf | ||
COPY pitt-reader.user.keytab pitt-reader.user.keytab | ||
|
||
# Install utils for fetching remote source code | ||
RUN apt-get update && \ | ||
apt-get install -y git wget python-dev gcc krb5-user && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
apt-get clean | ||
|
||
RUN wget \ | ||
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ | ||
&& mkdir /root/.conda \ | ||
&& bash Miniconda3-latest-Linux-x86_64.sh -b \ | ||
&& rm -f Miniconda3-latest-Linux-x86_64.sh | ||
|
||
RUN conda install -c conda-forge kafka-python -y | ||
RUN conda install -c conda-forge python-confluent-kafka -y | ||
RUN conda install -c stuarteberg -c conda-forge librdkafka -y | ||
|
||
# Get broker source code and install dependencies | ||
RUN git clone --single-branch --branch master --depth 1 https://github.com/mwvgroup/Pitt-Google-Broker && \ | ||
rm -rf Pitt-Google-Broker/.git | ||
|
||
MAINTAINER Daniel Perrefort "[email protected]" | ||
|
||
COPY consume_ztf.py consume_ztf.py | ||
|
||
# Install git | ||
RUN apt-get update | ||
RUN apt-get install -y git | ||
|
||
# Get broker source code and add to path | ||
RUN git clone https://github.com/mwvgroup/Pitt-Google-Broker | ||
|
||
# Install dependencies | ||
# Some dependency installs may fail without numpy, so we install it first | ||
RUN pip install numpy | ||
RUN pip install -r Pitt-Google-Broker/requirements.txt | ||
|
||
# Configure Python Environment | ||
ENV PYTHONPATH="Pitt-Google-Broker/:${PYTHONPATH}" | ||
|
||
|
||
CMD [ "python", "./consume_ztf.py" ] | ||
# Launch the ZTF consumer | ||
CMD [ "python", "docker_files/consume_ztf.py" ] |
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,63 @@ | ||
Cloud Configuration | ||
=================== | ||
|
||
Before deploying a broker instance to the cloud, you will need to create and | ||
authenticate a new cloud project. This project, and it's unique Id, will be | ||
used to organize the various resources used by the deployed system. For | ||
information on creating a new GCP project, see: | ||
`https://cloud.google.com/resource-manager/docs/creating-managing-projects <https://cloud.google.com/resource-manager/docs/creating-managing-projects>`. | ||
|
||
Once your project has been created, take note of the unique project Id as it | ||
will be required at multiple points throughout the deployment process. | ||
|
||
Authenticate CLI Tools | ||
------------------- | ||
|
||
You will need to authenticate the `gcloud` command line tools | ||
so that they can access your google cloud project. This is accomplished using | ||
the project Id noted earlier: | ||
|
||
.. code-block:: bash | ||
gcloud auth login # Login to GCP | ||
gcloud config set project [PROJECT-ID] # Configure the project ID | ||
gcloud auth configure-docker # Allow access for deploying docker images | ||
Setting up GCP | ||
-------------- | ||
|
||
You will need to set up a handful of tools in GCP. This includes enabling | ||
various API's for use in your GCP project | ||
|
||
.. code-block: bash | ||
gcloud services enable containerregistry.googleapis.com | ||
With the API's enabled, the broker package provides | ||
an automated setup tool that creates various recourses required | ||
for the broker to run. | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from broker.gcp_setup import auto_setup | ||
# See a list of changes that will be made to your GCP project | ||
help(auto_setup) | ||
# Setup your GCP project | ||
auto_setup() | ||
Deploying the ``stream_GCS_to_BQ`` Cloud Function | ||
------------------------------------------------- | ||
|
||
The ``stream_GCS_to_BQ`` function must be deployed from the command line as a | ||
Google Cloud Function so that it listens to the appropriate bucket(s) for new | ||
alert Avro files and appends the data to a BigQuery table. The Google Cloud SDK | ||
must be installed first (see :ref:`_gcloud`). The following script automates the | ||
deployment. Note that it may take a couple of minutes to complete. | ||
|
||
.. code-block::bash | ||
:linenos: | ||
./broker/cloud_functions/GCS_to_BQ.sh |
Oops, something went wrong.