1919import logging
2020import import_utils
2121import os
22- import sys
2322from absl import flags
2423
2524logging .getLogger ().setLevel (logging .INFO )
2625
2726FLAGS = flags .FLAGS
2827
29- flags .DEFINE_string (
30- 'project_id' , os .environ .get ('PROJECT_ID' , 'datcom-import-automation-prod' ),
31- 'GCP Project ID' )
32- flags .DEFINE_string ('spanner_project_id' ,
33- os .environ .get ('SPANNER_PROJECT_ID' , 'datcom-store' ),
28+ flags .DEFINE_string ('project_id' , os .environ .get ('PROJECT_ID' ),
29+ 'GCP Project ID' )
30+ flags .DEFINE_string ('spanner_project_id' , os .environ .get ('SPANNER_PROJECT_ID' ),
3431 'Spanner Project ID' )
3532flags .DEFINE_string ('spanner_instance_id' ,
36- os .environ .get ('SPANNER_INSTANCE_ID' , 'dc-kg-test' ),
33+ os .environ .get ('SPANNER_INSTANCE_ID' ),
3734 'Spanner Instance ID' )
3835flags .DEFINE_string ('spanner_database_id' ,
39- os .environ .get ('SPANNER_DATABASE_ID' , 'dc_graph_import' ),
36+ os .environ .get ('SPANNER_DATABASE_ID' ),
4037 'Spanner Database ID' )
41- flags .DEFINE_string ('gcs_bucket_id' ,
42- os .environ .get ('GCS_BUCKET_ID' , 'datcom-prod-imports' ),
38+ flags .DEFINE_string ('gcs_bucket_id' , os .environ .get ('GCS_BUCKET_ID' ),
4339 'GCS Bucket ID' )
44- flags .DEFINE_string ('location' , os .environ .get ('LOCATION' , 'us-central1' ),
45- 'GCP Location' )
40+ flags .DEFINE_string ('location' , os .environ .get ('LOCATION' ), 'Location' )
4641
4742
4843def _validate_params (request_json , required_params ):
@@ -72,11 +67,16 @@ def ingestion_helper(request):
7267
7368 if actionType == 'get_import_list' :
7469 # Gets the list of imports that are ready for ingestion.
70+ # Input:
71+ # importList: list of import names to filter by (optional)
7572 import_list = request_json .get ('importList' , [])
7673 imports = spanner .get_import_list (import_list )
7774 return jsonify (imports )
7875 elif actionType == 'acquire_ingestion_lock' :
7976 # Attempts to acquire the global lock for ingestion.
77+ # Input:
78+ # workflowId: ID of the workflow acquiring the lock
79+ # timeout: lock duration in seconds
8080 validation_error = _validate_params (request_json ,
8181 ['workflowId' , 'timeout' ])
8282 if validation_error :
@@ -89,6 +89,8 @@ def ingestion_helper(request):
8989 return ('Lock acquired' , 200 )
9090 elif actionType == 'release_ingestion_lock' :
9191 # Releases the global ingestion lock.
92+ # Input:
93+ # workflowId: ID of the workflow releasing the lock
9294 validation_error = _validate_params (request_json , ['workflowId' ])
9395 if validation_error :
9496 return (validation_error , 400 )
@@ -99,8 +101,12 @@ def ingestion_helper(request):
99101 return ('Lock released' , 200 )
100102 elif actionType == 'update_ingestion_status' :
101103 # Updates the status of imports after ingestion.
102- validation_error = _validate_params (request_json ,
103- ['importList' , 'workflowId' ])
104+ # Input:
105+ # importList: list of import names
106+ # workflowId: ID of the workflow
107+ # jobId: Dataflow job ID
108+ validation_error = _validate_params (
109+ request_json , ['importList' , 'workflowId' , 'jobId' ])
104110 if validation_error :
105111 return (validation_error , 400 )
106112 import_list = request_json ['importList' ]
@@ -113,6 +119,14 @@ def ingestion_helper(request):
113119 return ('Updated ingestion status' , 200 )
114120 elif actionType == 'update_import_status' :
115121 # Updates the status of a specific import job.
122+ # Input:
123+ # importName: name of the import
124+ # status: new status
125+ # jobId: Dataflow job ID (optional)
126+ # execTime: execution time in seconds (optional)
127+ # dataVolume: data volume in bytes (optional)
128+ # version: version string (optional)
129+ # schedule: cron schedule string (optional)
116130 validation_error = _validate_params (request_json ,
117131 ['importName' , 'status' ])
118132 if validation_error :
@@ -126,23 +140,28 @@ def ingestion_helper(request):
126140 200 )
127141 elif actionType == 'update_import_version' :
128142 # Updates the version of an import and marks it as READY.
129- validation_error = _validate_params (request_json ,
130- ['importName' , 'version' , 'reason' ])
143+ # Input:
144+ # importName: name of the import
145+ # version: version string
146+ # comment: audit log comment
147+ validation_error = _validate_params (
148+ request_json , ['importName' , 'version' , 'comment' ])
131149 if validation_error :
132150 return (validation_error , 400 )
133151 import_name = request_json ['importName' ]
134152 version = request_json ['version' ]
135- reason = request_json ['reason ' ]
153+ comment = request_json ['comment ' ]
136154 caller = import_utils .get_caller_identity (request )
137155 logging .info (
138- f"[ImportVersionAuditLog] Import { import_name } version { version } caller: { caller } reason : { reason } "
156+ f"[ImportVersionAuditLog] Import { import_name } version { version } caller: { caller } comment : { comment } "
139157 )
140158 if version == 'staging' :
141159 version = storage .get_staging_version (import_name )
142160 summary = storage .get_import_summary (import_name , version )
143161 params = import_utils .create_import_params (summary )
144162 params ['status' ] = 'READY'
145163 storage .update_version_file (import_name , version )
164+ spanner .update_version_history (import_name , version , comment )
146165 spanner .update_import_status (params )
147166 return (f'Updated import { import_name } to version { version } ' , 200 )
148167 else :
0 commit comments