in Simulation/container/script.py [0:0]
def start_process(procnum):
try:
print("Starting Process number", procnum)
print("Current Working Dir", os.getcwd())
file_object = open(os.getcwd() + "/simdata/worker_" + str(workerNo) + "_thread_" + str(procnum) +".txt", "a")
list_times = []
ssl_context = SSLContext(PROTOCOL_TLSv1_2 )
# Place your certificate file (sf-class2-root.crt) in this folder for testing the simulation. For your own use cases
# which might be sensitive and production environments should consider changing to alternative and more secure solutions.
#ssl_context.load_verify_locations(os.getcwd() + '/sf-class2-root.crt')
ssl_context.load_verify_locations('/usr/local/simulation_tutorial/sf-class2-root.crt')
ssl_context.verify_mode = CERT_REQUIRED
#TODO Add your Keyspaces username and password
auth_provider = PlainTextAuthProvider(username=keyspaces_username, password=keyspaces_password)
global cluster
cluster = Cluster(['cassandra.YOUR-REGION-HERE.amazonaws.com'],
ssl_context=ssl_context,
auth_provider=auth_provider, port=9142, protocol_version=4)
global session
session = cluster.connect(keyspace=KEYSPACE,
wait_for_all_pools=True)
list_ids = []
for i in range(requests):
list_ids.append(random.randint(0,5565))
global household_id
for i in range(len(list_ids)):
# ToDO make the id between 1-150
query= "SELECT * FROM feature_store.energy_data_features WHERE id='" + str(household_id[list_ids[i]][0]) + "';"
try:
t_now = time.time()
rows = session.execute(query)
list_times.append(str(workerNo) + "," + str(procnum) + "," + str(time.time() - t_now) + "," + str(t_now))
except:
print("Failed at worker", workerNo)
print("Failed Request", i)
pass
#global simulation_name
for s in list_times:
file_object.write(s + '\n')
file_object.close()
s3 = boto3.resource('s3')
s3.Bucket(s3_bucket_name).upload_file(os.getcwd() + "/simdata/worker_" + str(workerNo) + "_thread_" + str(procnum) +".txt", "simulation_results/" + str(simulation_name) + "/worker_" + str(workerNo) + "_thread_" + str(procnum) +".txt")
print("Thread complete")
except:
print("Thread Failed")
raise Exception('Thread Failed')