From 404c69f3731cf7532148fbc36d9b79cc7862ec31 Mon Sep 17 00:00:00 2001 From: Fredrik Wrede Date: Wed, 18 Sep 2024 09:36:42 +0000 Subject: [PATCH 1/3] grpc-proxy --- fedn/cli/client_cmd.py | 24 ++++++++++++++++++------ fedn/network/clients/client.py | 21 +++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 8a68399ed..0b163e4d8 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -3,11 +3,10 @@ import click import requests -from fedn.common.exceptions import InvalidClientConfig -from fedn.network.clients.client import Client - from fedn.cli.main import main from fedn.cli.shared import CONTROLLER_DEFAULTS, apply_config, get_api_url, get_token, print_response +from fedn.common.exceptions import InvalidClientConfig +from fedn.network.clients.client import Client def validate_client_config(config): @@ -27,8 +26,7 @@ def validate_client_config(config): @main.group("client") @click.pass_context def client_cmd(ctx): - """:param ctx: - """ + """:param ctx:""" pass @@ -79,7 +77,10 @@ def list_clients(ctx, protocol: str, host: str, port: str, token: str = None, n_ @click.option("-s", "--secure", required=False, default=False) @click.option("-pc", "--preshared-cert", required=False, default=False) @click.option("-v", "--verify", is_flag=True, help="Verify SSL/TLS for REST service") -@click.option("-c", "--preferred-combiner", type=str,required=False, default="",help="name of the preferred combiner") +@click.option("-c", "--preferred-combiner", type=str, required=False, default="", help="name of the preferred combiner") +@click.option("--combiner", type=str, required=False, default="", help="Skip combiner assignment from discover service and attatch directly to combiner host.") +@click.option("--combiner-port", type=str, required=False, default="12080", help="Combiner port, need to be used with --combiner") +@click.option("--proxy-server", type=str, required=False, default="", help="gRPC proxy server, need to be used together with --combiner") @click.option("-va", "--validator", required=False, default=True) @click.option("-tr", "--trainer", required=False, default=True) @click.option("-in", "--init", required=False, default=None, help="Set to a filename to (re)init client from file state.") @@ -102,6 +103,9 @@ def client_cmd( preshared_cert, verify, preferred_combiner, + combiner, + combiner_port, + proxy_server, validator, trainer, init, @@ -143,6 +147,9 @@ def client_cmd( "preshared_cert": preshared_cert, "verify": verify, "preferred_combiner": preferred_combiner, + "combiner": combiner, + "combiner_port": combiner_port, + "proxy_server": proxy_server, "validator": validator, "trainer": trainer, "logfile": logfile, @@ -156,6 +163,11 @@ def client_cmd( click.echo(f"\nClient configuration loaded from file: {init}") click.echo("Values set in file override defaults and command line arguments...\n") + # proxy_server needs combiner check + if config["proxy_server"]: + if not config["combiner"]: + click.echo("--proxy-server/proxy_server requires a combiner host in --combiner/combiner") + return try: validate_client_config(config) except InvalidClientConfig as e: diff --git a/fedn/network/clients/client.py b/fedn/network/clients/client.py index 8508291ff..132482071 100644 --- a/fedn/network/clients/client.py +++ b/fedn/network/clients/client.py @@ -62,18 +62,6 @@ def __init__(self, config): self.id = config["client_id"] or str(uuid.uuid4()) - self.connector = ConnectorClient( - host=config["discover_host"], - port=config["discover_port"], - token=config["token"], - name=config["name"], - remote_package=config["remote_compute_context"], - force_ssl=config["force_ssl"], - verify=config["verify"], - combiner=config["preferred_combiner"], - id=self.id, - ) - # Validate client name match = re.search(VALID_NAME_REGEX, config["name"]) if not match: @@ -94,8 +82,13 @@ def __init__(self, config): self.inbox = queue.Queue() - # Attach to the FEDn network (get combiner) - combiner_config = self.assign() + # Attach to the FEDn network (get combiner or attach directly) + if config["combiner"]: + combiner_config = {"status": "assigned", "host": config["combiner"], "port": config["combiner_port"], "helper_type": ""} + if config["proxy_server"]: + combiner_config["fqdn"] = config["proxy_server"] + else: + combiner_config = self.assign() self.connect(combiner_config) self._initialize_dispatcher(self.config) From 548833df0cd308c3353f36802c2a44fab7d8d4ad Mon Sep 17 00:00:00 2001 From: Fredrik Wrede Date: Sun, 22 Sep 2024 07:07:59 +0000 Subject: [PATCH 2/3] fix --- fedn/cli/client_cmd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fedn/cli/client_cmd.py b/fedn/cli/client_cmd.py index 0b163e4d8..fb124dcf6 100644 --- a/fedn/cli/client_cmd.py +++ b/fedn/cli/client_cmd.py @@ -16,9 +16,12 @@ def validate_client_config(config): """ try: if config["discover_host"] is None or config["discover_host"] == "": - raise InvalidClientConfig("Missing required configuration: discover_host") + if config["combiner"] is None or config["combiner"] == "": + raise InvalidClientConfig("Missing required configuration: discover_host or combiner") if "discover_port" not in config.keys(): config["discover_port"] = None + if config["remote_compute_context"] and config["discover_host"] is None: + raise InvalidClientConfig("Remote compute context requires discover_host") except Exception: raise InvalidClientConfig("Could not load config from file. Check config") From a9092a1420489b4190eed3babfa33b1bdea6b230 Mon Sep 17 00:00:00 2001 From: Fredrik Wrede Date: Mon, 23 Sep 2024 15:26:30 +0000 Subject: [PATCH 3/3] fix --- fedn/network/clients/client.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fedn/network/clients/client.py b/fedn/network/clients/client.py index 132482071..e7604a68a 100644 --- a/fedn/network/clients/client.py +++ b/fedn/network/clients/client.py @@ -88,6 +88,17 @@ def __init__(self, config): if config["proxy_server"]: combiner_config["fqdn"] = config["proxy_server"] else: + self.connector = ConnectorClient( + host=config["discover_host"], + port=config["discover_port"], + token=config["token"], + name=config["name"], + remote_package=config["remote_compute_context"], + force_ssl=config["force_ssl"], + verify=config["verify"], + combiner=config["preferred_combiner"], + id=self.id, + ) combiner_config = self.assign() self.connect(combiner_config)