In [ ]:
GCP_PROJECT_ID = "" #@param {type:"string"}
INSTANCE_NAME="" #@param {type:"string"}
In [ ]:
!gcloud auth login
!gcloud config set project $GCP_PROJECT_ID
!rm -rf modem && git clone https://github.com/google/modem.git
In [ ]:
import re
email=!gcloud config get-value account
SSH_DESTINATION = re.findall(r".*@",email[0])[0]+INSTANCE_NAME
SSH_DESTINATION = SSH_DESTINATION.replace('.','_')
print("SSH Destination: ", SSH_DESTINATION)
In [ ]:
%%writefile enable_firewall.sh
exists_rule=$(gcloud compute firewall-rules list | grep "default-allow-ssh" | wc -l)
if [ $exists_rule -eq 0 ]
then
gcloud compute firewall-rules create default-allow-ssh --allow tcp:22;
echo "New firewall rule created."
else
echo "The correct firewall rules exist."
fi
In [ ]:
%%writefile modem/bqml/pipeline/svc_key.json
{
"TODO": "Replace file."
}
In [ ]:
%%writefile modem/bqml/pipeline/params.py
# -------------------------MANDATORY SECTION------------------------
# GA Details
GA_ACCOUNT_ID = ""
GA_PROPERTY_ID = ""
GA_DATASET_ID = ""
GA_IMPORT_METHOD = "di" # "di" - Data Import or "mp" - Measurement Protocol
# BQML Details -
# Ensure that the BQ result headers resemble the data import schema
# E.g. If data import schema looks like - ga:clientId, ga:dimension1, etc.
# BQ result headers should like ga_clientId, ga_dimension1, etc.
BQML_PREDICT_QUERY = """
"""
# Options for logging & error monitoring
# LOGGING: Create BQ Table for logs with schema as follows -
# time TIMESTAMP, status STRING, error ERROR
ENABLE_BQ_LOGGING = False
# ERROR MONITORING: Sign up for the free Sendgrid API.
ENABLE_SENDGRID_EMAIL_REPORTING = False
# --------------------------OPTIONAL SECTION-------------------------
# (OPTIONAL) Workflow Logging - BQ details, if enabled
GCP_PROJECT_ID = ""
BQ_DATASET_NAME = ""
BQ_TABLE_NAME = ""
# (OPTIONAL) Email Reporting - Sendgrid details, if enabled
SENDGRID_API_KEY = ""
TO_EMAIL = ""
# (OPTIONAL) Email Reporting - Additional Parameters
FROM_EMAIL = "workflow@example.com"
SUBJECT = "FAILED: Audience Upload to GA"
HTML_CONTENT = """
<p>
Hi WorkflowUser, <br>
Your BQML Custom Audience Upload has failed- <br>
Time: {0} UTC <br>
Reason: {1}
</p>
"""
Change the cron schedule (line 1) to the desired frequency.
In [ ]:
%%writefile modem/bqml/pipeline/shell_scheduler.sh
cron_schedule="*/2 * * * *"
echo "$cron_schedule cd ~/modem/bqml/pipeline && python main.py >> logs.csv" | crontab -
echo "Your workflow has been scheduled with the cron schedule of $cron_schedule. Enjoy!"
In [ ]:
!sh enable_firewall.sh
!gcloud compute scp --recurse modem $SSH_DESTINATION:~/
!echo "Code deployed."
When you run the cell below, an interactive shell opens up. Use the following commands -
cd modem/bqml/pipeline
sh shell_deploy.sh
sh shell_scheduler.sh
In [ ]:
!gcloud compute ssh $SSH_DESTINATION