11#! /bin/bash
2- # Create and configure GCP resources needed to run the nightly broker.
2+ # Create and configure GCP resources needed to run the broker.
33
44# "False" uses production resources
55# any other string will be appended to the names of all resources
3939broker_bucket=" ${PROJECT_ID} -${survey} -broker_files"
4040bq_dataset=" ${survey} "
4141topic_alerts=" ${survey} -alerts"
42- topic_storebigquery=" ${survey} -bigquery"
42+ topic_deadletter=" ${survey} -deadletter"
43+ subscription_storebigquery=" ${survey} -bigquery"
44+ subscription_deadletter=" ${survey} -deadletter"
4345
4446# use test resources, if requested
4547if [ " $testid " != " False" ]; then
4648 broker_bucket=" ${broker_bucket} -${testid} "
4749 bq_dataset=" ${bq_dataset} _${testid} "
4850 topic_alerts=" ${topic_alerts} -${testid} "
49- topic_storebigquery=" ${topic_storebigquery} -${testid} "
51+ topic_deadletter=" ${topic_deadletter} -${testid} "
52+ subscription_storebigquery=" ${subscription_storebigquery} -${testid} "
53+ subscription_deadletter=" ${subscription_deadletter} -${testid} "
54+
5055fi
5156
5257alerts_table=" alerts_${versiontag} "
@@ -71,13 +76,14 @@ if [ "${teardown}" != "True" ]; then
7176 # create pubsub
7277 echo " Configuring Pub/Sub resources..."
7378 gcloud pubsub topics create " ${topic_alerts} "
74- gcloud pubsub topics create " ${topic_storebigquery} "
79+ gcloud pubsub topics create " ${topic_deadletter} "
80+ gcloud pubsub subscriptions create " ${subscription_storebigquery} " --topic=" ${topic_alerts} " --bigquery-table=" ${PROJECT_ID} :${bq_dataset} .${alerts_table} " --use-table-schema --drop-unknown-fields --dead-letter-topic=" ${topic_deadletter} " --max-delivery-attempts=5 --dead-letter-topic-project=$PROJECT_ID
81+ gcloud pubsub subscriptions create " ${subscription_deadletter} " --topic=" ${topic_deadletter} "
7582
76- # Set IAM policies on resources
83+ # set IAM policies on resources
7784 user=" allUsers"
7885 roleid=" projects/${GOOGLE_CLOUD_PROJECT} /roles/userPublic"
7986 gcloud pubsub topics add-iam-policy-binding " ${topic_alerts} " --member=" ${user} " --role=" ${roleid} "
80- gcloud pubsub topics add-iam-policy-binding " ${topic_storebigquery} " --member=" ${user} " --role=" ${roleid} "
8187
8288else
8389 # ensure that we do not teardown production resources
8692 gsutil -m -o " ${o} " rm -r " gs://${broker_bucket} "
8793 bq rm -r -f " ${PROJECT_ID} :${bq_dataset} "
8894 gcloud pubsub topics delete " ${topic_alerts} "
89- gcloud pubsub topics delete " ${topic_storebigquery } "
95+ gcloud pubsub subscriptions delete " ${subscription_storebigquery } "
9096 fi
9197fi
9298
9399# --- Create VM instances
94100echo
95101echo " Configuring VMs..."
96102./create_vms.sh " ${broker_bucket} " " ${testid} " " ${teardown} " " ${survey} " " ${zone} "
97-
98- # --- Deploy Cloud Functions
99- echo
100- echo " Configuring Cloud Functions..."
101- cd .. && cd .. && cd cloud_functions && cd lvk || exit 5
102-
103- # --- BigQuery storage cloud function
104- cd store_BigQuery && ./deploy.sh " $testid " " $teardown " " $survey " " $versiontag " || exit 5
105-
106- # --- return to setup_broker/lvk directory
107- cd .. && cd .. && cd .. && cd setup_broker && cd lvk || exit 5
0 commit comments