@@ -22,52 +22,46 @@ def fetch_products_mark_completed(
22
22
- Any exceptions that occur during the execution.
23
23
"""
24
24
25
- try :
26
- # Establish MongoDB connection
27
- db = get_mongo_db (mongo_conn_id )
28
- requests_collection = db ["PrivateCloudRequest" ]
29
- requested_projects_collection = db ["PrivateCloudRequestData" ]
25
+ # Establish MongoDB connection
26
+ db = get_mongo_db (mongo_conn_id )
27
+ requests_collection = db ["PrivateCloudRequest" ]
28
+ requested_projects_collection = db ["PrivateCloudRequestData" ]
30
29
31
- product_requests = requests_collection .find (
32
- {"decisionStatus" : "APPROVED" }, projection = {"_id" : True , "licencePlate" : True , "decisionDataId" : True }
33
- )
34
-
35
- for request in product_requests :
36
- request_id = request ["_id" ]
37
- licence_plate = request ["licencePlate" ]
38
- decision_data_id = ObjectId (request ["decisionDataId" ])
39
- # a call to the RequestedProject table to get cluster
40
- requested_project_document = requested_projects_collection .find_one (
41
- {"_id" : decision_data_id }, projection = {"cluster" : True }
42
- )
43
- cluster = requested_project_document .get ("cluster" ).lower ()
44
- # start of provisioner logic
45
- workflow_name = f"{ cluster } -{ licence_plate } -{ request_id } "
46
- provisioner_workflow_url = f"{ provisioner_api_url } /{ workflow_name } "
47
- request_status_in_provisioner = requests .get (provisioner_workflow_url ).json ()
48
- if not keys_exist (request_status_in_provisioner , "metadata" , "labels" , "workflows.argoproj.io/phase" ):
49
- continue
30
+ product_requests = requests_collection .find (
31
+ {"decisionStatus" : "APPROVED" }, projection = {"_id" : True , "licencePlate" : True , "decisionDataId" : True }
32
+ )
50
33
51
- request_phase = request_status_in_provisioner ["metadata" ]["labels" ]["workflows.argoproj.io/phase" ]
52
- if request_phase == "Running" :
53
- continue
54
- elif request_phase == "Error" or request_phase == "Failed" :
55
- # TODO: add resend logic here in the future
56
- continue
57
- elif request_phase == "Succeeded" :
58
- # Call the callback URL to mark the product as Provisioned
59
- mark_provisioned_url = f"{ mark_provisioned_url } /{ licence_plate } /provision"
60
- kc = Keycloak (kc_auth_url , kc_realm , kc_client_id , kc_client_secret )
61
- access_token = kc .get_access_token ()
62
- headers = {"Authorization" : f"Bearer { access_token } " , "Content-Type" : "application/json" }
63
- response = requests .post (mark_provisioned_url , headers = headers , json = {})
34
+ for request in product_requests :
35
+ request_id = request ["_id" ]
36
+ licence_plate = request ["licencePlate" ]
37
+ decision_data_id = ObjectId (request ["decisionDataId" ])
38
+ # a call to the RequestedProject table to get cluster
39
+ requested_project_document = requested_projects_collection .find_one (
40
+ {"_id" : decision_data_id }, projection = {"cluster" : True }
41
+ )
42
+ cluster = requested_project_document .get ("cluster" ).lower ()
43
+ # start of provisioner logic
44
+ workflow_name = f"{ cluster } -{ licence_plate } -{ request_id } "
45
+ provisioner_workflow_url = f"{ provisioner_api_url } /{ workflow_name } "
46
+ request_status_in_provisioner = requests .get (provisioner_workflow_url ).json ()
47
+ if not keys_exist (request_status_in_provisioner , "metadata" , "labels" , "workflows.argoproj.io/phase" ):
48
+ continue
64
49
65
- if response .status_code != 200 :
66
- print (
67
- f"Error while marking { licence_plate } as Provisioned: { response .status_code } - { response .reason } "
68
- )
69
- else :
70
- print (f"Marked { licence_plate } as Provisioned" )
50
+ request_phase = request_status_in_provisioner ["metadata" ]["labels" ]["workflows.argoproj.io/phase" ]
51
+ if request_phase == "Running" :
52
+ continue
53
+ elif request_phase == "Error" or request_phase == "Failed" :
54
+ # TODO: add resend logic here in the future
55
+ continue
56
+ elif request_phase == "Succeeded" :
57
+ # Call the callback URL to mark the product as Provisioned
58
+ mark_provisioned_url = f"{ mark_provisioned_url } /{ licence_plate } /provision"
59
+ kc = Keycloak (kc_auth_url , kc_realm , kc_client_id , kc_client_secret )
60
+ access_token = kc .get_access_token ()
61
+ headers = {"Authorization" : f"Bearer { access_token } " , "Content-Type" : "application/json" }
62
+ response = requests .post (mark_provisioned_url , headers = headers , json = {})
71
63
72
- except Exception as e :
73
- print (f"[fetch_products_mark_completed] Error: { e } " )
64
+ if response .status_code != 200 :
65
+ print (f"Error while marking { licence_plate } as Provisioned: { response .status_code } - { response .reason } " )
66
+ else :
67
+ print (f"Marked { licence_plate } as Provisioned" )
0 commit comments