sync for dev 033026
This commit is contained in:
@ -170,11 +170,10 @@ def get_php_summary():
|
||||
system_components.append(this_component)
|
||||
|
||||
if run_cosmostat_server():
|
||||
print(cosmostat_client.name)
|
||||
client_uuid = cosmostat_server.get_uuid_from_hostname(cosmostat_client.name)
|
||||
print(client_uuid)
|
||||
data_timestamp = cosmostat_server.get_system(client_uuid)
|
||||
print(data_timestamp)
|
||||
log_string = f"Cosmostat Client Name: {cosmostat_client.name} - UUID: {client_uuid}- Timestamp: {data_timestamp}"
|
||||
log_data(log_output = log_string, log_level = "log_output")
|
||||
component_age = {
|
||||
"component_name": "Data Timestamp",
|
||||
"info_strings": f"Data is {data_timestamp} seconds old"
|
||||
@ -221,7 +220,10 @@ def create_client():
|
||||
if not cosmostat_server.check_uuid(payload["uuid"]):
|
||||
result = run_create_client(payload)
|
||||
else:
|
||||
result = {"message": "object already exists, skipping creation"}
|
||||
result = {
|
||||
"message": "object already exists, skipping creation",
|
||||
"system_exists": "True"
|
||||
}
|
||||
return jsonify(result), 200
|
||||
|
||||
# api to validate Cosmostat Class
|
||||
@ -280,6 +282,7 @@ def run_update_client(this_client):
|
||||
|
||||
return {
|
||||
"status": update_status,
|
||||
"client_updated": "True",
|
||||
"uuid": this_client["uuid"],
|
||||
"redis_data": this_client,
|
||||
"timestamp_update": timestamp_update
|
||||
@ -296,6 +299,7 @@ def run_create_client(this_client):
|
||||
update_status = f'created client {this_client["short_id"]}'
|
||||
return {
|
||||
"status": update_status,
|
||||
"client_created": "True",
|
||||
"uuid": this_client["uuid"],
|
||||
"client_properties": this_client,
|
||||
"timestamp_update": timestamp_update
|
||||
@ -372,13 +376,15 @@ def get_client_details():
|
||||
# Cosmostat Client Reporter
|
||||
def client_update():
|
||||
api_url = f"{cosmostat_server_api()}update_client"
|
||||
print(api_url)
|
||||
payload = get_client_payload(get_client_redis_data(human_readable = False), "redis_data")
|
||||
log_data(log_output = f"API Update Called - {api_url}", log_level = "debug_output")
|
||||
log_data(log_output = "client_update - redis data from local client:", log_level = "noisy_test")
|
||||
log_data(log_output = payload, log_level = "noisy_test")
|
||||
# execute API call
|
||||
result = client_submission_handler(api_url, payload)
|
||||
client_api_initialize()
|
||||
if not result or not result.get('client_updated'):
|
||||
log_data(log_output = f"Client not updated, initializing", log_level = "log_output")
|
||||
result = client_api_initialize()
|
||||
return result
|
||||
|
||||
# Cosmostat Client Initializer
|
||||
@ -434,6 +440,7 @@ if __name__ == '__main__':
|
||||
######################################
|
||||
### Main Functions
|
||||
######################################
|
||||
log_data(log_output = f"Main Function Start", log_level = "log_output")
|
||||
|
||||
# instantiate and return the Client System object
|
||||
def new_cosmos_client():
|
||||
@ -480,9 +487,13 @@ if __name__ == '__main__':
|
||||
######################################
|
||||
|
||||
# local client System Class Object
|
||||
log_data(log_output = f"Cosmostat Client Start", log_level = "log_output")
|
||||
cosmostat_client = new_cosmos_client()
|
||||
cosmostat_client.update_system_state()
|
||||
|
||||
# remote client reporter
|
||||
if app_settings["cosmostat_server_reporter"] and not app_settings["cosmostat_server"]:
|
||||
log_data(log_output = f"Initialize Client Reporter", log_level = "log_output")
|
||||
client_api_initialize()
|
||||
|
||||
######################################
|
||||
@ -491,15 +502,19 @@ if __name__ == '__main__':
|
||||
|
||||
cosmostat_server = None
|
||||
if run_cosmostat_server():
|
||||
log_data(log_output = f"Cosmostat Server Start", log_level = "log_output")
|
||||
cosmostat_server = new_cosmostat_server()
|
||||
this_client = get_client_payload(get_php_summary(), "client_properties")
|
||||
timestamp_update = cosmostat_server.add_system(system_dictionary = this_client)
|
||||
# moving this here so all the bits exist
|
||||
client_update()
|
||||
|
||||
######################################
|
||||
# send initial stats update to redis
|
||||
######################################
|
||||
|
||||
if app_settings["push_redis"] and not app_settings["disable_local_api"]:
|
||||
log_data(log_output = f"Initial Redis Push", log_level = "log_output")
|
||||
update_redis_server()
|
||||
|
||||
######################################
|
||||
@ -507,6 +522,7 @@ if __name__ == '__main__':
|
||||
######################################
|
||||
|
||||
if app_settings["run_background"] and not app_settings["disable_local_api"]:
|
||||
log_data(log_output = f"Background Function Initializing", log_level = "log_output")
|
||||
log_data(log_output = "Loading flask background subroutine...", log_level = "log_output")
|
||||
|
||||
scheduler.add_job(id='background_loop',
|
||||
@ -523,16 +539,18 @@ if __name__ == '__main__':
|
||||
######################################
|
||||
# Flask API
|
||||
######################################
|
||||
print(f"gateway: {service_gateway_ip()} - port: {service_api_port()}")
|
||||
log_data(log_output = f"gateway: {service_gateway_ip()} - port: {service_api_port()}", log_level = "log_output")
|
||||
if not app_settings["disable_local_api"]:
|
||||
log_data(log_output = f"Main API Start", log_level = "log_output")
|
||||
app.run(debug=False, host=service_gateway_ip(), port=service_api_port())
|
||||
else:
|
||||
# if local API disabled, phone home if configured
|
||||
print("Internal API Disabled.")
|
||||
log_data(log_output = f"Internal API Disabled", log_level = "log_output")
|
||||
cosmostat_client.update_system_state()
|
||||
client_update()
|
||||
while True:
|
||||
if int(time.time()) % 5 == 0 and not cosmostat_client.check_system_timer():
|
||||
cosmostat_client.update_system_state()
|
||||
client_update()
|
||||
time.sleep(0.5)
|
||||
cosmostat_client.update_system_state()
|
||||
client_update()
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user