From 42403c3781173903df365852c03e58cf78c5f1cd Mon Sep 17 00:00:00 2001 From: "aniket.parlikar316@gmail.com" Date: Fri, 5 Aug 2022 12:08:51 -0400 Subject: [PATCH 1/4] Added new files to firestore folder --- scripts/firestore_delete/main.py | 35 +++++++++++++++++++++++ scripts/firestore_delete/requirements.txt | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 scripts/firestore_delete/main.py create mode 100644 scripts/firestore_delete/requirements.txt diff --git a/scripts/firestore_delete/main.py b/scripts/firestore_delete/main.py new file mode 100644 index 0000000..de111ca --- /dev/null +++ b/scripts/firestore_delete/main.py @@ -0,0 +1,35 @@ +#The given script creates a CLoud Function to that is triggered when an image file is deleted from the street2sat-uploaded bucket +#and then proceeds to delete the corresponding record from the Firestore DB. + +import logging +from google.cloud import firestore + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) +db = firestore.Client() + +def firestore_delete(event, context): + """Triggered by a change to a Cloud Storage bucket. + Args: + event (dict): Event payload. + context (google.cloud.functions.Context): Metadata for the event. + """ + #Getting the image name + img_path = event['name'] + + #Extracting the document name from the file path + doc_ref=img_path.replace("/","-").split(".")[0] + logging.info("The name of the document is "+doc_ref) + + #Getting the document reference + doc = db.collection('street2sat').document(doc_ref) + doc_check=doc.get() + + #Checking if the document reference exists in the collections and deleting it. + if doc_check.exists: + logger.info("The record associated with the image file exists in the Firestore DB") + logger.info("Deleting the given document") + doc.delete() + logger.info("Document has been deleted.") + else: + logger.info('No such record associated with the image file exists in the Firestore DB!') diff --git a/scripts/firestore_delete/requirements.txt b/scripts/firestore_delete/requirements.txt new file mode 100644 index 0000000..072cbf9 --- /dev/null +++ b/scripts/firestore_delete/requirements.txt @@ -0,0 +1,3 @@ +# Function dependencies, for example: +# package>=version +google-cloud-firestore \ No newline at end of file From 1107ab982e1593e2504a884ba334d902503f9314 Mon Sep 17 00:00:00 2001 From: Aniket-Parlikar <57226253+Aniket-Parlikar@users.noreply.github.com> Date: Fri, 12 Aug 2022 10:44:49 -0400 Subject: [PATCH 2/4] Deleted firestore_delete scripts in scripts folder --- scripts/firestore_delete/main.py | 35 ----------------------- scripts/firestore_delete/requirements.txt | 3 -- 2 files changed, 38 deletions(-) delete mode 100644 scripts/firestore_delete/main.py delete mode 100644 scripts/firestore_delete/requirements.txt diff --git a/scripts/firestore_delete/main.py b/scripts/firestore_delete/main.py deleted file mode 100644 index de111ca..0000000 --- a/scripts/firestore_delete/main.py +++ /dev/null @@ -1,35 +0,0 @@ -#The given script creates a CLoud Function to that is triggered when an image file is deleted from the street2sat-uploaded bucket -#and then proceeds to delete the corresponding record from the Firestore DB. - -import logging -from google.cloud import firestore - -logging.basicConfig(level=logging.INFO) -logger = logging.getLogger(__name__) -db = firestore.Client() - -def firestore_delete(event, context): - """Triggered by a change to a Cloud Storage bucket. - Args: - event (dict): Event payload. - context (google.cloud.functions.Context): Metadata for the event. - """ - #Getting the image name - img_path = event['name'] - - #Extracting the document name from the file path - doc_ref=img_path.replace("/","-").split(".")[0] - logging.info("The name of the document is "+doc_ref) - - #Getting the document reference - doc = db.collection('street2sat').document(doc_ref) - doc_check=doc.get() - - #Checking if the document reference exists in the collections and deleting it. - if doc_check.exists: - logger.info("The record associated with the image file exists in the Firestore DB") - logger.info("Deleting the given document") - doc.delete() - logger.info("Document has been deleted.") - else: - logger.info('No such record associated with the image file exists in the Firestore DB!') diff --git a/scripts/firestore_delete/requirements.txt b/scripts/firestore_delete/requirements.txt deleted file mode 100644 index 072cbf9..0000000 --- a/scripts/firestore_delete/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Function dependencies, for example: -# package>=version -google-cloud-firestore \ No newline at end of file From 029f216e6edab445388593784d333b4e31aafe13 Mon Sep 17 00:00:00 2001 From: Aniket-Parlikar <57226253+Aniket-Parlikar@users.noreply.github.com> Date: Fri, 12 Aug 2022 10:51:50 -0400 Subject: [PATCH 3/4] Moved the files from the scripts to the GCP folder --- gcp/delete-street2sat-prediction/main.py | 34 +++++++++++++++++++ .../requirements.txt | 3 ++ 2 files changed, 37 insertions(+) create mode 100644 gcp/delete-street2sat-prediction/main.py create mode 100644 gcp/delete-street2sat-prediction/requirements.txt diff --git a/gcp/delete-street2sat-prediction/main.py b/gcp/delete-street2sat-prediction/main.py new file mode 100644 index 0000000..9b69be9 --- /dev/null +++ b/gcp/delete-street2sat-prediction/main.py @@ -0,0 +1,34 @@ +# The given script creates a CLoud Function to that is triggered when an image file is deleted from the street2sat-uploaded bucket +# and then proceeds to delete the corresponding record from the Firestore DB. +import logging +from google.cloud import firestore + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) +db = firestore.Client() + +def hello_gcs(event, context): + """Triggered by a change to a Cloud Storage bucket. + Args: + event (dict): Event payload. + context (google.cloud.functions.Context): Metadata for the event. + """ + #Getting the image name + img_path = event['name'] + + #Extracting the document name from the file path + doc_ref=img_path.replace("/","-").split(".")[0] + logging.info("The name of the document is "+doc_ref+".") + + #Getting the document reference + doc = db.collection('street2sat').document(doc_ref) + doc_check=doc.get() + + #Checking if the document reference exists in the collections and deleting it. + if doc_check.exists: + logger.info("The record associated with the image file exists in the Firestore DB.") + logger.info("Deleting the given document.") + doc.delete() + logger.info("Document has been deleted.") + else: + logger.info('No such record associated with the image file exists in the Firestore DB!.') diff --git a/gcp/delete-street2sat-prediction/requirements.txt b/gcp/delete-street2sat-prediction/requirements.txt new file mode 100644 index 0000000..072cbf9 --- /dev/null +++ b/gcp/delete-street2sat-prediction/requirements.txt @@ -0,0 +1,3 @@ +# Function dependencies, for example: +# package>=version +google-cloud-firestore \ No newline at end of file From f4b942fe8d2c56daf5cb2dae5e55d3def8c856d0 Mon Sep 17 00:00:00 2001 From: Aniket-Parlikar <57226253+Aniket-Parlikar@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:35:42 -0400 Subject: [PATCH 4/4] Added deploy command for delete trigger function Added deploy command for the street2sat delete function --- deploy.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index f361b50..a4516d9 100644 --- a/deploy.sh +++ b/deploy.sh @@ -17,4 +17,13 @@ gcloud functions deploy trigger-street2sat \ --runtime=python39 \ --entry-point=hello_gcs \ --set-env-vars INFERENCE_HOST="$URL" \ - --timeout=300s \ No newline at end of file + --timeout=300s + +gcloud functions deploy delete-street2sat-prediction \ + --source=gcp/delete-street2sat-prediction \ + --trigger-event=google.storage.object.delete \ + --trigger-resource=$BUCKET \ + --allow-unauthenticated \ + --runtime=python39 \ + --entry-point=hello_gcs \ + --timeout=300s