Skip to content

Commit

Permalink
move cli impl to coordinator api
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Wang <jiede.wl@alibaba-inc.com>
  • Loading branch information
doudoubobo committed Sep 20, 2024
1 parent 2bd8362 commit 5ce964d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
20 changes: 13 additions & 7 deletions coordinator/flex/server/controllers/graph_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import sys
import requests

GRAPH_ID = None

def get_graph_schema():
property_data_type_mapping = {}
Expand Down Expand Up @@ -103,8 +104,8 @@ def get_graph_schema():

table_schema = json.loads(table_schema_str)

result_dict["name"] = "graph_schema"
result_dict["description"] = "graph schema for portal"
result_dict["name"] = GRAPH_ID
result_dict["id"] = GRAPH_ID
vertex_types_array = []
edge_types_array = []
schema_dict = {}
Expand Down Expand Up @@ -221,8 +222,10 @@ def create_graph(create_graph_request): # noqa: E501
if isinstance(create_graph_request, dict):
result_dict["graph_id"] = create_graph_request["name"]
else:
result_dict["graph_id"] = "0"
create_graph_request = json.loads(create_graph_request)
result_dict["graph_id"] = create_graph_request["name"]
global GRAPH_ID
GRAPH_ID = result_dict["graph_id"]
create_graph_request = create_graph_request["schema"]
create_graph_request_yaml = yaml.dump(create_graph_request)
gart_controller_server = os.getenv("GART_CONTROLLER_SERVER", "127.0.0.1:8080")
Expand All @@ -249,8 +252,10 @@ def create_graph_by_pgql(create_graph_by_pgql_request): # noqa: E501
if isinstance(create_graph_by_pgql_request, dict):
result_dict["graph_id"] = create_graph_by_pgql_request["name"]
else:
result_dict["graph_id"] = "0"
create_graph_by_pgql_request = json.loads(create_graph_by_pgql_request)
result_dict["graph_id"] = create_graph_by_pgql_request["name"]
global GRAPH_ID
GRAPH_ID = result_dict["graph_id"]
create_graph_by_pgql_request = create_graph_by_pgql_request["schema"]
gart_controller_server = os.getenv("GART_CONTROLLER_SERVER", "127.0.0.1:8080")
if not gart_controller_server.startswith(("http://", "https://")):
Expand All @@ -276,8 +281,10 @@ def create_graph_by_yaml(create_graph_by_yaml_request): # noqa: E501
if isinstance(create_graph_by_yaml_request, dict):
result_dict["graph_id"] = create_graph_by_yaml_request["name"]
else:
result_dict["graph_id"] = "0"
create_graph_by_yaml_request = json.loads(create_graph_by_yaml_request)
result_dict["graph_id"] = create_graph_by_yaml_request["name"]
global GRAPH_ID
GRAPH_ID = result_dict["graph_id"]
create_graph_request_yaml = create_graph_by_yaml_request["schema"]
gart_controller_server = os.getenv("GART_CONTROLLER_SERVER", "127.0.0.1:8080")
if not gart_controller_server.startswith(("http://", "https://")):
Expand Down Expand Up @@ -370,7 +377,7 @@ def get_graph_all_available_versions(graph_id): # noqa: E501
gart_controller_server = os.getenv("GART_CONTROLLER_SERVER", "127.0.0.1:8080")
if not gart_controller_server.startswith(("http://", "https://")):
gart_controller_server = f"http://{gart_controller_server}"
response = requests.post(f"{gart_controller_server}/get-all-available-read-epochs")
response = requests.get(f"{gart_controller_server}/get-all-available-read-epochs")
result = []
all_versions = response.json()
for idx in range(len(all_versions)):
Expand Down Expand Up @@ -469,7 +476,6 @@ def list_graphs(): # noqa: E501
result_dict = get_graph_schema()
if not result_dict:
return ([GetGraphResponse.from_dict(result_dict)], 500)
result_dict["id"] = "0"
return ([GetGraphResponse.from_dict(result_dict)], 200)


Expand Down
4 changes: 2 additions & 2 deletions scripts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def resume():
return "Resumed", 200


@app.route("/get-graph-schema", methods=["POST"])
@app.route("/get-graph-schema", methods=["GET"])
def get_graph_schema():
subprocess.run(
[
Expand All @@ -134,7 +134,7 @@ def get_graph_schema():
return json.dumps(schema), 200


@app.route("/get-all-available-read-epochs", methods=["POST"])
@app.route("/get-all-available-read-epochs", methods=["GET"])
def get_all_available_read_epochs():
all_epochs = get_all_available_read_epochs_internal()[0]
if len(all_epochs) == 0:
Expand Down
37 changes: 25 additions & 12 deletions scripts/gart_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import click
import os
import json
import yaml
import socket
import requests
from urllib.parse import urlparse

CONFIG_FILE_PATH = "/tmp/gart_cli_config.json"
GRAPH_ID = "graph_id"


def save_config(config):
Expand Down Expand Up @@ -68,7 +70,7 @@ def resume_data_loading(ctx):
click.echo('Please connect to an endpoint first using the "connect" command.')
return

response = requests.post(f"{endpoint}/control/resume")
response = requests.post(f"{endpoint}/api/v1/service/resume")
click.echo(f"Resumed data loading: {response.text}")


Expand All @@ -81,7 +83,7 @@ def pause_data_loading(ctx):
click.echo('Please connect to an endpoint first using the "connect" command.')
return

response = requests.post(f"{endpoint}/control/pause")
response = requests.post(f"{endpoint}/api/v1/service/pause")
click.echo(f"Paused data loading: {response.text}")


Expand All @@ -94,7 +96,7 @@ def get_all_available_versions(ctx):
click.echo('Please connect to an endpoint first using the "connect" command.')
return

response = requests.post(f"{endpoint}/get-all-available-read-epochs")
response = requests.get(f"{endpoint}/api/v1/graph/{GRAPH_ID}/versions")
click.echo(f"Available versions: {response.text}")


Expand All @@ -107,9 +109,8 @@ def get_version_by_timestamp(ctx, timestamp):
if not endpoint:
click.echo('Please connect to an endpoint first using the "connect" command.')
return
response = requests.post(
f"{endpoint}/get-read-epoch-by-timestamp", data={"timestamp": timestamp}
)
response = requests.get(
f"{endpoint}/api/v1/graph/{GRAPH_ID}/versions/timestamp?timestamp={timestamp}")
click.echo(f"Version at {timestamp}: {response.text}")


Expand All @@ -123,10 +124,22 @@ def submit_config(ctx, config_path):
click.echo('Please connect to an endpoint first using the "connect" command.')
return

with open(config_path, "rb") as file:
files = {"file": (config_path, file)}
with open(config_path, "r") as file:
yaml_content = file.read()
dict_content = yaml.load(yaml_content, Loader=yaml.FullLoader)
graph_name = dict_content["loadingConfig"]["database"]
payload = {
"name": graph_name,
"description": graph_name,
"schema": yaml_content # Assuming your schema accepts YAML as a string
}
try:
response = requests.post(f"{endpoint}/submit-config", files=files)
response = requests.post(
f"{endpoint}/api/v1/graph/yaml",
headers={"Content-Type": "application/json"},
data=json.dumps(payload)
)
# response = requests.post(f"{endpoint}/api/v1/graph/yaml", files=files)
response.raise_for_status()
click.echo(f"Success: Server responded with {response.status_code} status")
except requests.exceptions.HTTPError as e:
Expand All @@ -150,7 +163,7 @@ def submit_pgql_config(ctx, config_path):
with open(config_path, "rb") as file:
files = {"file": (config_path, file)}
try:
response = requests.post(f"{endpoint}/submit-pgql-config", files=files)
response = requests.post(f"{endpoint}/api/v1/graph/pgql", files=files)
response.raise_for_status()
click.echo(f"Success: Server responded with {response.status_code} status")
except requests.exceptions.HTTPError as e:
Expand Down Expand Up @@ -199,7 +212,7 @@ def change_graph_version_gie(ctx, graph_version):
return

response = requests.post(
f"{endpoint}/change-read-epoch", data={"read_epoch": graph_version}
f"{endpoint}/api/v1/graph/{GRAPH_ID}/versions", data={"read_epoch": graph_version}
)
click.echo(f"Changed graph version to {graph_version}: {response.text}")

Expand All @@ -213,7 +226,7 @@ def get_graph_schema(ctx):
click.echo('Please connect to an endpoint first using the "connect" command.')
return

response = requests.post(f"{endpoint}/get-graph-schema")
response = requests.get(f"{endpoint}/api/v1/graph/{GRAPH_ID}/schema")
click.echo(f"Graph schema: {response.text}")


Expand Down

0 comments on commit 5ce964d

Please sign in to comment.