Skip to content

Commit 0779aa6

Browse files
committed
rename setup_broker/rubin dir to setup_broker/lsst and update files
1 parent c4fdb27 commit 0779aa6

File tree

4 files changed

+57
-35
lines changed

4 files changed

+57
-35
lines changed

broker/setup_broker/rubin/README.md renamed to broker/setup_broker/lsst/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Create a secret for your access credential:
4242

4343
```bash
4444
# define parameters
45-
survey="rubin"
45+
survey="lsst"
4646
PROJECT_ID=$GOOGLE_CLOUD_PROJECT
4747

4848
# define secret names
@@ -74,22 +74,23 @@ Clone the repo and cd into the directory:
7474

7575
```bash
7676
git clone https://github.com/mwvgroup/Pitt-Google-Broker.git
77-
cd Pitt-Google-Broker/broker/setup_broker/rubin
77+
cd Pitt-Google-Broker/broker/setup_broker/lsst
7878
```
7979

8080
Define the variables used below.
8181

8282
```bash
83-
testid="enter testid value"
83+
testid="mytest"
8484
teardown="False"
85-
survey="rubin"
85+
survey="lsst"
86+
schema_version="7.1"
8687
region="us-central1"
8788
```
8889

8990
Execute the `setup_broker.sh` script:
9091

9192
```bash
92-
./setup_broker.sh "${testid}" "${teardown}" "${survey}" "${region}"
93+
./setup_broker.sh "${testid}" "${teardown}" "${survey}" "${schema_version}" "${region}"
9394
```
9495

9596
This will create all of the necessary GCP resources. Allow the consumer VM to finish its installation process. Once
@@ -123,8 +124,9 @@ Initialize parameters and call the deployment script:
123124
```bash
124125
testid="mytest"
125126
teardown="True"
126-
survey="rubin"
127+
survey="lsst"
128+
schema_version="7.1"
127129
region="us-central1"
128130

129-
./setup_broker.sh "${testid}" "${teardown}" "${survey}" "${region}"
131+
./setup_broker.sh "${testid}" "${teardown}" "${survey}" "${schema_version}" "${region}"
130132
```

broker/setup_broker/rubin/create_vm.sh renamed to broker/setup_broker/lsst/create_vm.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# Creates or deletes the GCP VM instances needed by the broker.
33
# This script will not delete VMs that are in production
44

5-
6-
broker_bucket=$1 # name of GCS bucket where broker files are staged
5+
# name of GCS bucket where broker files are staged
6+
broker_bucket=$1
7+
# "False" uses production resources
8+
# any other string will be appended to the names of all resources
79
testid="${2:-test}"
8-
# "False" uses production resources
9-
# any other string will be appended to the names of all resources
10-
teardown="${3:-False}" # "True" tearsdown/deletes resources, else setup
11-
survey="${4:-rubin}"
10+
# "True" tearsdown/deletes resources, else setup
11+
teardown="${3:-False}"
1212
# name of the survey this broker instance will ingest
13+
survey="${4:-lsst}"
1314
zone="${5:-us-central1-a}"
1415
firewallrule="${6:-tcpport9094}"
1516

broker/setup_broker/rubin/setup_broker.sh renamed to broker/setup_broker/lsst/setup_broker.sh

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#! /bin/bash
22
# Create and configure GCP resources needed to run the nightly broker.
33

4-
testid="${1:-test}"
54
# "False" uses production resources
65
# any other string will be appended to the names of all resources
7-
teardown="${2:-False}"
6+
testid="${1:-test}"
87
# "True" tearsdown/deletes resources, else setup
9-
survey="${3:-rubin}"
8+
teardown="${2:-False}"
109
# name of the survey this broker instance will ingest
11-
region="${4:-us-central1}"
10+
survey="${3:-lsst}"
11+
schema_version="${4:-7.1}"
12+
versiontag=v$(echo "${schema_version}" | tr . _) # 7.1 -> v7_1
13+
region="${5:-us-central1}"
1214
zone="${region}-a" # just use zone "a" instead of adding another script arg
1315

1416
PROJECT_ID=$GOOGLE_CLOUD_PROJECT # get the environment variable
@@ -20,6 +22,7 @@ echo
2022
echo "GOOGLE_CLOUD_PROJECT = ${PROJECT_ID}"
2123
echo "survey = ${survey}"
2224
echo "testid = ${testid}"
25+
echo "schema_version = ${schema_version}"
2326
echo "teardown = ${teardown}"
2427
echo
2528
echo "Continue? [y/(n)]: "
@@ -34,28 +37,55 @@ fi
3437

3538
#--- GCP resources used directly in this script
3639
broker_bucket="${PROJECT_ID}-${survey}-broker_files"
37-
topic_alerts="${survey}-alerts"
38-
pubsub_subscription="${topic_alerts}"
40+
bq_dataset="${survey}"
41+
topic_alerts="${survey}-alerts_raw"
42+
pubsub_subscription="${topic_alerts}" # draft, remove before merging PR
43+
subscription_storebigquery="${survey}-bigquery"
44+
3945
# use test resources, if requested
40-
# (there must be a better way to do this)
4146
if [ "$testid" != "False" ]; then
4247
broker_bucket="${broker_bucket}-${testid}"
48+
bq_dataset="${bq_dataset}_${testid}"
4349
topic_alerts="${topic_alerts}-${testid}"
44-
pubsub_subscription="${pubsub_subscription}-${testid}"
50+
pubsub_subscription="${pubsub_subscription}-${testid}" # draft, remove before merging PR
51+
subscription_storebigquery="${subscription_storebigquery}-${testid}"
4552
fi
4653

54+
alerts_table="alerts_${versiontag}"
4755

48-
#--- Create (or delete) GCS, Pub/Sub resources
56+
#--- Create (or delete) BigQuery, GCS, Pub/Sub resources
57+
echo
58+
echo "Configuring BigQuery, GCS, Pub/Sub resources..."
4959
if [ "${teardown}" != "True" ]; then
60+
# create bigquery dataset and table
61+
bq --location="${region}" mk --dataset "${bq_dataset}"
62+
63+
cd templates || exit 5
64+
bq mk --table "${PROJECT_ID}:${bq_dataset}.${alerts_table}" "bq_${survey}_${alerts_table}_schema.json" || exit 5
65+
bq update --description "Alert data from LSST. This table is an archive of the lsst-alerts Pub/Sub stream. It has the same schema as the original alert bytes, including nested and repeated fields." "${PROJECT_ID}:${bq_dataset}.${alerts_table}"
66+
cd .. || exit 5
67+
5068
# create broker bucket and upload files
5169
echo "Creating broker_bucket and uploading files..."
5270
gsutil mb -b on -l "${region}" "gs://${broker_bucket}"
5371
./upload_broker_bucket.sh "${broker_bucket}"
5472

73+
#--- Create a firewall rule to open the port used by Kafka/Rubin LSST
74+
# on any instance with the flag --tags=tcpport9094
75+
echo
76+
echo "Configuring Rubin/Kafka firewall rule..."
77+
firewallrule="tcpport9094"
78+
gcloud compute firewall-rules create "${firewallrule}" \
79+
--allow=tcp:9094 \
80+
--description="Allow incoming traffic on TCP port 9094" \
81+
--direction=INGRESS \
82+
--enable-logging
83+
5584
# create pubsub
5685
echo "Configuring Pub/Sub resources..."
5786
gcloud pubsub topics create "${topic_alerts}"
5887
gcloud pubsub subscriptions create "${pubsub_subscription}" --topic="${topic_alerts}"
88+
gcloud pubsub subscriptions create "${subscription_storebigquery}" --topic="${topic_alerts}" --bigquery-table="${PROJECT_ID}:${bq_dataset}.${alerts_table}" --use_table_schema=true
5989

6090
# Set IAM policies on resources
6191
user="allUsers"
@@ -67,24 +97,13 @@ else
6797
if [ "${testid}" != "False" ]; then
6898
o="GSUtil:parallel_process_count=1" # disable multiprocessing for Macs
6999
gsutil -m -o "${o}" rm -r "gs://${broker_bucket}"
100+
bq rm -r -f "${PROJECT_ID}:${bq_dataset}"
70101
gcloud pubsub topics delete "${topic_alerts}"
71102
gcloud pubsub subscriptions delete "${pubsub_subscription}"
103+
gcloud pubsub subscriptions delete "${subscription_storebigquery}"
72104
fi
73105
fi
74106

75-
if [ "$teardown" != "True" ]; then
76-
#--- Create a firewall rule to open the port used by Kafka/Rubin
77-
# on any instance with the flag --tags=tcpport9094
78-
echo
79-
echo "Configuring Rubin/Kafka firewall rule..."
80-
firewallrule="tcpport9094"
81-
gcloud compute firewall-rules create "${firewallrule}" \
82-
--allow=tcp:9094 \
83-
--description="Allow incoming traffic on TCP port 9094" \
84-
--direction=INGRESS \
85-
--enable-logging
86-
fi
87-
88107
#--- Create VM instances
89108
echo
90109
echo "Configuring VMs..."

0 commit comments

Comments
 (0)