-
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
Open
KatHellg
wants to merge
11
commits into
master
Choose a base branch
from
fix/SK-1127
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+326
−43
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
035f652
session_id flag added
131e045
minor code fix
ef2543d
added new line end of session cmd file
794a0b1
fixed acc to feedback
c83e928
code fix
7c24f1a
fixed conflict
4a1d035
conflict + minor fix
282c81b
spelling fix:)
2500829
resolving conflict
f285468
trying to add get_client function again
581cfbc
header prints removed
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,17 +60,47 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ | |
if _token: | ||
headers["Authorization"] = _token | ||
|
||
click.echo(f"\nListing clients: {url}\n") | ||
click.echo(f"Headers: {headers}") | ||
|
||
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}" | ||
|
||
|
||
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 +238,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 +269,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 +319,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 +346,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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.