9
9
10
10
host = env_vars ['NODE1_IP' ]
11
11
port = "50010"
12
+ endpoint = "http://" + host + ":6080"
13
+ new_lease_value = 50000000000000
14
+
15
+ def get_current_lease (endpoint ):
16
+ """Fetches the current maxLeasedUid from the Dgraph Zero /state endpoint."""
17
+ try :
18
+ response = requests .get (f"{ endpoint } /state" )
19
+ response .raise_for_status () # Raise an exception for HTTP errors
20
+ data = response .json ()
21
+ # Extracting the maxLeasedUid from the JSON response
22
+ max_leased_uid = data .get ('maxUID' , None )
23
+ if max_leased_uid is not None :
24
+ print (f"Current maxLeasedUid: { max_leased_uid } " )
25
+ return max_leased_uid
26
+ else :
27
+ print ("Error: maxLeasedUid not found in the response." )
28
+ return None
29
+ except requests .RequestException as e :
30
+ print (f"Error fetching current lease: { e } " )
31
+ return None
32
+
33
+ def increase_lease (endpoint , new_value ):
34
+ """Increases the lease value if it's below the new_value."""
35
+ current_value = get_current_lease (endpoint )
36
+ current_value = int (current_value )
37
+ if current_value is None :
38
+ print ("Unable to fetch the current lease value. Exiting." )
39
+ return
40
+
41
+ if current_value < new_value :
42
+ try :
43
+ # Assuming a POST request with form data to increase lease size
44
+ data = {'what' : 'uids' , 'num' : new_value }
45
+ response = requests .get (f"{ endpoint } /assign" , params = data )
46
+ response .raise_for_status () # Raise an exception for HTTP errors
47
+ print (f"Lease increased to { new_value } ." )
48
+ except requests .RequestException as e :
49
+ print (f"Error increasing lease: { e } " )
50
+ print (f"Response Content: { response .content } " ) # Debug print to see response content
51
+ else :
52
+ print (f"Current lease ({ current_value } ) is already greater than or equal to { new_value } . No action taken." )
12
53
13
54
14
55
def main (json_file ):
@@ -54,16 +95,15 @@ def convert_datetime_format(date_str):
54
95
continue
55
96
else :
56
97
return date_str # If the format is not correct, return the original string
57
-
98
+
58
99
output_format = "%Y-%m-%dT%H:%M:%S.%fZ"
59
100
output_str = dt .strftime (output_format )
60
101
output_str = output_str [:26 ] + 'Z' # Keep only the first 2 decimal places of the seconds part
61
102
return output_str
62
103
63
104
def process_json_data (golden_records ):
64
-
105
+ increase_lease ( endpoint , new_lease_value )
65
106
for golden_record in golden_records :
66
-
67
107
golden_record ['goldenRecord' ]['uniqueGoldenRecordData' ]['auxDateCreated' ] = convert_datetime_format (golden_record ['goldenRecord' ]['uniqueGoldenRecordData' ]['auxDateCreated' ])
68
108
for interaction in golden_record ['interactionsWithScore' ]:
69
109
interaction ['interaction' ]['uniqueInteractionData' ]['auxDateCreated' ] = convert_datetime_format (
@@ -73,7 +113,7 @@ def process_json_data(golden_records):
73
113
response = send_golden_record_to_api (golden_record )
74
114
if response :
75
115
print ("After Restore Golden ID--" + response .text )
76
-
116
+
77
117
def send_golden_record_to_api (golden_record_payload ):
78
118
get_expanded_golden_record_url = f'http://{ host } :{ port } /JeMPI/restoreGoldenRecord'
79
119
# Normalize date fields in the payload
0 commit comments