Skip to content

Commit

Permalink
add get graph schema for cli
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Wang <[email protected]>
  • Loading branch information
doudoubobo committed Aug 16, 2024
1 parent 3eaf2a2 commit dbc65fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
17 changes: 17 additions & 0 deletions scripts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions scripts/gart_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
27 changes: 21 additions & 6 deletions scripts/generate_schema_for_protal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit dbc65fc

Please sign in to comment.