diff --git a/scripts/controller.py b/scripts/controller.py index 9d59963..456f7ce 100755 --- a/scripts/controller.py +++ b/scripts/controller.py @@ -70,6 +70,23 @@ def resume(): return "Resumed", 200 +@app.route("/get-graph-schema", methods=["POST"]) +def get_graph_schema(): + subprocess.run( + [ + "/bin/bash", + "-c", + "/workspace/gart/scripts/generate_schema_for_protal.py", + ] + ) + schema_file_path = "/tmp/graph_schema_for_portal.json" + if not os.path.exists(schema_file_path): + return "No graph schema found yet", 400 + with open(schema_file_path, "r") as f: + schema = json.load(f) + return json.dumps(schema), 200 + + @app.route("/get-all-available-read-epochs", methods=["POST"]) def get_all_available_read_epochs(): all_epochs = get_all_available_read_epochs_internal()[0] diff --git a/scripts/gart_cli.py b/scripts/gart_cli.py index 7098ab4..2823580 100755 --- a/scripts/gart_cli.py +++ b/scripts/gart_cli.py @@ -180,5 +180,18 @@ def change_graph_version_gie(ctx, graph_version): click.echo(f"Changed graph version to {graph_version}: {response.text}") +@cli.command() +@click.pass_context +def get_graph_schema(ctx): + """Get graph schema.""" + endpoint = ctx.obj.get("endpoint") + if not endpoint: + click.echo('Please connect to an endpoint first using the "connect" command.') + return + + response = requests.post(f"{endpoint}/get-graph-schema") + click.echo(f"Graph schema: {response.text}") + + if __name__ == "__main__": cli(obj={}) diff --git a/scripts/generate_schema_for_protal.py b/scripts/generate_schema_for_protal.py index ede8001..b71818a 100755 --- a/scripts/generate_schema_for_protal.py +++ b/scripts/generate_schema_for_protal.py @@ -6,6 +6,7 @@ import yaml import os import time +import sys output_file_path = "/tmp/graph_schema_for_portal.yaml" json_output_file_path = "/tmp/graph_schema_for_portal.json" @@ -33,28 +34,42 @@ etcd_prefix = os.getenv("ETCD_PREFIX", "gart_meta_") rg_mapping_key = etcd_prefix + "gart_rg_mapping_yaml" -while True: + +try_max_times = 3 +try_times = 0 +while try_times < try_max_times: try: rg_mapping_str, _ = etcd_client.get(rg_mapping_key) if rg_mapping_str is not None: rg_mapping_str = rg_mapping_str.decode("utf-8") break - time.sleep(5) + try_times += 1 + time.sleep(2) except Exception as e: - time.sleep(5) + try_times += 1 + time.sleep(2) + +if try_times == try_max_times: + sys.exit(1) rg_mapping = yaml.load(rg_mapping_str, Loader=yaml.SafeLoader) table_schema_key = etcd_prefix + "gart_table_schema" -while True: +try_times = 0 +while try_times < try_max_times: try: table_schema_str, _ = etcd_client.get(table_schema_key) if table_schema_str is not None: table_schema_str = table_schema_str.decode("utf-8") break - time.sleep(5) + try_times += 1 + time.sleep(2) except Exception as e: - time.sleep(5) + try_times += 1 + time.sleep(2) + +if try_times == try_max_times: + sys.exit(1) table_schema = json.loads(table_schema_str)