-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/SK-1127 | add session_id flag #742
base: master
Are you sure you want to change the base?
Changes from 10 commits
035f652
131e045
ef2543d
794a0b1
c83e928
7c24f1a
4a1d035
282c81b
2500829
f285468
581cfbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,12 +65,46 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ | |
|
||
try: | ||
response = requests.get(url, headers=headers) | ||
print_response(response, "clients") | ||
print_response(response, "clients", None) | ||
except requests.exceptions.ConnectionError: | ||
click.echo(f"Error: Could not connect to {url}") | ||
|
||
@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") | ||
@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") | ||
@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") | ||
@click.option("-t", "--token", required=False, help="Authentication token") | ||
@click.option("-id", "--id", required=True, help="Client ID") | ||
@client_cmd.command("get") | ||
@click.pass_context | ||
def get_client(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think id should be required... |
||
"""Return: | ||
------ | ||
- result: client with given id | ||
|
||
@client_cmd.command("start") | ||
""" | ||
url = get_api_url(protocol=protocol, host=host, port=port, endpoint="clients") | ||
headers = {} | ||
|
||
|
||
_token = get_token(token) | ||
|
||
if _token: | ||
headers["Authorization"] = _token | ||
|
||
if id: | ||
url = f"{url}{id}" | ||
|
||
|
||
click.echo(f"\nRetrieving client: {url}\n") | ||
click.echo(f"Headers: {headers}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove print of hearder |
||
try: | ||
response = requests.get(url, headers=headers) | ||
print_response(response, "client", id) | ||
except requests.exceptions.ConnectionError: | ||
click.echo(f"Error: Could not connect to {url}") | ||
|
||
|
||
@client_cmd.command("start-v1") | ||
@click.option("-d", "--discoverhost", required=False, help="Hostname for discovery services(reducer).") | ||
@click.option("-p", "--discoverport", required=False, help="Port for discovery services (reducer).") | ||
@click.option("--token", required=False, help="Set token provided by reducer if enabled") | ||
|
@@ -208,18 +242,18 @@ def _complement_client_params(config: dict): | |
click.echo(f"Protocol missing, complementing api_url with protocol: {result}") | ||
|
||
|
||
@client_cmd.command("start-v2") | ||
@client_cmd.command("start") | ||
@click.option("-u", "--api-url", required=False, help="Hostname for fedn api.") | ||
@click.option("-p", "--api-port", required=False, help="Port for discovery services (reducer).") | ||
@click.option("--token", required=False, help="Set token provided by reducer if enabled") | ||
@click.option("-n", "--name", required=False, default="client" + str(uuid.uuid4())[:8]) | ||
@click.option("-n", "--name", required=False) | ||
@click.option("-i", "--client-id", required=False) | ||
@click.option("--local-package", is_flag=True, help="Enable local compute package") | ||
@click.option("-c", "--preferred-combiner", type=str, required=False, default="", help="name of the preferred combiner") | ||
@click.option("--combiner", type=str, required=False, default=None, help="Skip combiner assignment from discover service and attach directly to combiner host.") | ||
@click.option("--combiner-port", type=str, required=False, default=None, help="Combiner port, need to be used with --combiner") | ||
@click.option("-va", "--validator", required=False, default=True) | ||
@click.option("-tr", "--trainer", required=False, default=True) | ||
@click.option("-va", "--validator", required=False, default=None) | ||
@click.option("-tr", "--trainer", required=False, default=None) | ||
@click.option("-h", "--helper_type", required=False, default=None) | ||
@click.option("-in", "--init", required=False, default=None, help="Set to a filename to (re)init client from file state.") | ||
@click.pass_context | ||
|
@@ -239,8 +273,6 @@ def client_start_v2_cmd( | |
helper_type: str, | ||
init: str, | ||
): | ||
click.echo(click.style("\n*** fedn client start-v2 is experimental ***\n", blink=True, bold=True, fg="red")) | ||
|
||
package = "local" if local_package else "remote" | ||
|
||
config = { | ||
|
@@ -291,6 +323,8 @@ def client_start_v2_cmd( | |
config["name"] = name | ||
if config["name"]: | ||
click.echo(f"Input param name: {name} overrides value from file") | ||
elif config["name"] is None: | ||
config["name"] = "client" + str(uuid.uuid4())[:8] | ||
|
||
if client_id and client_id != "": | ||
config["client_id"] = client_id | ||
|
@@ -316,11 +350,15 @@ def client_start_v2_cmd( | |
config["validator"] = validator | ||
if config["validator"] is not None: | ||
click.echo(f"Input param validator: {validator} overrides value from file") | ||
elif config["validator"] is None: | ||
config["validator"] = True | ||
|
||
if trainer is not None: | ||
config["trainer"] = trainer | ||
if config["trainer"] is not None: | ||
click.echo(f"Input param trainer: {trainer} overrides value from file") | ||
elif config["trainer"] is None: | ||
config["trainer"] = True | ||
|
||
if helper_type and helper_type != "": | ||
config["helper_type"] = helper_type | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,11 +88,46 @@ def list_combiners(ctx, protocol: str, host: str, port: str, token: str = None, | |
if _token: | ||
headers["Authorization"] = _token | ||
|
||
|
||
click.echo(f"\nListing combiners: {url}\n") | ||
click.echo(f"Headers: {headers}") | ||
try: | ||
response = requests.get(url, headers=headers) | ||
print_response(response, "combiners", None) | ||
except requests.exceptions.ConnectionError: | ||
click.echo(f"Error: Could not connect to {url}") | ||
|
||
|
||
@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") | ||
@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") | ||
@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") | ||
@click.option("-t", "--token", required=False, help="Authentication token") | ||
@click.option("-id", "--id", required=True, help="Combiner ID") | ||
@combiner_cmd.command("get") | ||
@click.pass_context | ||
def get_combiner(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): | ||
"""Return: | ||
------ | ||
- result: combiner with given id | ||
|
||
""" | ||
url = get_api_url(protocol=protocol, host=host, port=port, endpoint="combiners") | ||
headers = {} | ||
|
||
|
||
_token = get_token(token) | ||
|
||
if _token: | ||
headers["Authorization"] = _token | ||
|
||
if id: | ||
url = f"{url}{id}" | ||
|
||
|
||
click.echo(f"\nRetrieving combiner: {url}\n") | ||
click.echo(f"Headers: {headers}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
try: | ||
response = requests.get(url, headers=headers) | ||
print_response(response, "combiners") | ||
print_response(response, "combiner", id) | ||
except requests.exceptions.ConnectionError: | ||
click.echo(f"Error: Could not connect to {url}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,20 @@ def model_cmd(ctx): | |
@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") | ||
@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") | ||
@click.option("-t", "--token", required=False, help="Authentication token") | ||
@click.option("-session_id", "--session_id", required=False, help="models in session with given session id") | ||
@click.option("--n_max", required=False, help="Number of items to list") | ||
@model_cmd.command("list") | ||
@click.pass_context | ||
def list_models(ctx, protocol: str, host: str, port: str, token: str = None, n_max: int = None): | ||
def list_models(ctx, protocol: str, host: str, port: str, token: str = None, session_id: str = None, n_max: int = None): | ||
"""Return: | ||
------ | ||
- count: number of models | ||
- result: list of models | ||
|
||
""" | ||
url = get_api_url(protocol=protocol, host=host, port=port, endpoint="models") | ||
|
||
|
||
headers = {} | ||
|
||
if n_max: | ||
|
@@ -38,11 +41,49 @@ def list_models(ctx, protocol: str, host: str, port: str, token: str = None, n_m | |
if _token: | ||
headers["Authorization"] = _token | ||
|
||
if session_id: | ||
url = f"{url}?session_id={session_id}" | ||
|
||
click.echo(f"\nListing models: {url}\n") | ||
click.echo(f"Headers: {headers}") | ||
try: | ||
response = requests.get(url, headers=headers) | ||
print_response(response, "models", None) | ||
except requests.exceptions.ConnectionError: | ||
click.echo(f"Error: Could not connect to {url}") | ||
|
||
|
||
@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)") | ||
@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)") | ||
@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)") | ||
@click.option("-t", "--token", required=False, help="Authentication token") | ||
@click.option("-id", "--id", required=True, help="Model ID") | ||
@model_cmd.command("get") | ||
@click.pass_context | ||
def get_model(ctx, protocol: str, host: str, port: str, token: str = None, id: str = None): | ||
"""Return: | ||
------ | ||
- result: model with given id | ||
|
||
""" | ||
url = get_api_url(protocol=protocol, host=host, port=port, endpoint="models") | ||
|
||
|
||
headers = {} | ||
|
||
|
||
_token = get_token(token) | ||
|
||
if _token: | ||
headers["Authorization"] = _token | ||
|
||
if id: | ||
url = f"{url}{id}" | ||
|
||
click.echo(f"\nRetrieving model: {url}\n") | ||
click.echo(f"Headers: {headers}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
try: | ||
response = requests.get(url, headers=headers) | ||
print_response(response, "models") | ||
print_response(response, "model", id) | ||
except requests.exceptions.ConnectionError: | ||
click.echo(f"Error: Could not connect to {url}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should handle more than just ConnectionError, there are plenty of other error related to http requests. You don't have do do this know but make an other issue of it. For example create a utility function that handles all requests and checks the response for error:
import requests
from requests.exceptions import HTTPError, Timeout, ConnectionError, RequestException
def make_request(method, url, **kwargs):
"""
A reusable function to handle HTTP(S) requests with error handling.