-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_transfer.py
117 lines (102 loc) · 4.27 KB
/
data_transfer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import os
import concurrent.futures
import datetime
def main():
# Ask the user if the volumes have been provisioned and setup_volumes.py has been run
volumes_ready = input("\nHave the volumes been provisioned and setup_volumes.py run (y/n)? ")
# Proceed only if the answer is 'y'
if volumes_ready.lower() == 'y':
pass
else:
print("Please ensure that volumes are provisioned and setup_volumes.py is run before proceeding.")
quit()
# Ask the user if the config.yaml has been verified to be correct
config_verified = input("\nHas the config.yaml been verified to be correct (y/n)? ")
# Proceed only if the answer is 'y'
if config_verified.lower() == 'y':
# Run validate_endpoints.py and print its output in real time
try:
os.system('python validate_endpoints.py')
except Exception as e:
print("Failed to run validate_endpoints.py")
print("Error:", e)
quit()
else:
print("Please verify the config.yaml before proceeding.")
quit()
endpoints_verified = input("\nAre the endpoints valid or acceptable (y/n)? ")
# Proceed only if the answer is 'y'
if endpoints_verified.lower() == 'y':
# Run src_connect_test.py and print its output in real time
try:
os.system('python src_connect_test.py')
except Exception as e:
print("Failed to run src_connect_test.py")
print("Error:", e)
quit()
else:
print("Please verify the config.yaml and your endpoints before proceeding.")
quit()
src_connect_verified = input("\nis this the expected source output (y/n)? ")
# Proceed only if the answer is 'y'
if src_connect_verified.lower() == 'y':
# Run dest_connect_test.py and print its output in real time
try:
os.system('python dest_connect_test.py')
except Exception as e:
print("Failed to run dest_connect_test.py")
print("Error:", e)
quit()
else:
print("Please verify the config.yaml")
quit()
dest_connect_verified = input("\nis this the expected destination output (y/n)? ")
# Proceed only if the answer is 'y'
if dest_connect_verified.lower() == 'y':
# Run reset.py and print its output in real time
try:
os.system('python reset.py')
except Exception as e:
print("Failed to run reset.py")
print("Error:", e)
quit()
# Run repair_ledger.py and print its output in real time
try:
os.system('python repair_ledger.py')
except Exception as e:
print("Failed to run repair_ledger.py")
print("Error:", e)
quit()
else:
print("Please verify the config.yaml")
quit()
def run_script(script_name):
"""Function to run a python script using os.system and print outputs."""
print(f"Running {script_name}...")
# Run the script and directly print the output
os.system(f'python {script_name}')
final_approval = input("\nDo you want to begin the data transfer (y/n)? ")
if final_approval.lower() == 'y':
print('Executing src_sync_mvol.py and dest_sync_mvol.py.')
# Record start time
start_time = datetime.datetime.now()
# Scripts to run concurrently
scripts = ["src_sync_mvol.py", "dest_sync_mvol.py"]
# Using ThreadPoolExecutor to run scripts concurrently
with concurrent.futures.ThreadPoolExecutor() as executor:
# Map the run_script function to the scripts
executor.map(run_script, scripts)
# Record end time
end_time = datetime.datetime.now()
# Calculate the duration
duration = (end_time - start_time).total_seconds()
# Print the time details
print('\n\nALL DATA IS MOVED. RUN repair_ledger.py TO DO A FINAL DATA INTEGRITY CHECK.')
print("Start time:", start_time.strftime("%Y-%m-%d %H:%M:%S"))
print("End time:", end_time.strftime("%Y-%m-%d %H:%M:%S"))
print("Total duration:", duration, "seconds")
else:
print("Please verify the config.yaml and your endpoints before proceeding.")
quit()
if __name__ == "__main__":
main()