Skip to content

Commit

Permalink
allow local package
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed Sep 3, 2024
1 parent 3d91b5d commit 7060069
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions fedn/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
FEDN_AUTH_REFRESH_TOKEN = os.environ.get("FEDN_AUTH_REFRESH_TOKEN", False)
FEDN_CUSTOM_URL_PREFIX = os.environ.get("FEDN_CUSTOM_URL_PREFIX", "")


FEDN_ALLOW_LOCAL_PACKAGE = os.environ.get("FEDN_ALLOW_LOCAL_PACKAGE", False)
FEDN_PACKAGE_EXTRACT_DIR = os.environ.get("FEDN_PACKAGE_EXTRACT_DIR", "package")


Expand Down
30 changes: 21 additions & 9 deletions fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from werkzeug.security import safe_join
from werkzeug.utils import secure_filename

from fedn.common.config import get_controller_config, get_network_config
from fedn.common.config import FEDN_ALLOW_LOCAL_PACKAGE, get_controller_config, get_network_config
from fedn.common.log_config import logger
from fedn.network.combiner.interfaces import CombinerUnavailableError
from fedn.network.state import ReducerState, ReducerStateToString
Expand Down Expand Up @@ -512,7 +512,7 @@ def add_combiner(self, combiner_id, secure_grpc, address, remote_addr, fqdn, por

return jsonify(payload)

def add_client(self, client_id, preferred_combiner, remote_addr, name):
def add_client(self, client_id, preferred_combiner, remote_addr, name, package="remote"):
"""Add a client to the network.
:param client_id: The client id to add.
Expand All @@ -522,19 +522,31 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name):
:return: A json response with combiner assignment config.
:rtype: :class:`flask.Response`
"""
# Check if package has been set
package_object = self.statestore.get_compute_package()
if package_object is None:
if package == "remote":
package_object = self.statestore.get_compute_package()
if package_object is None:
return (
jsonify(
{
"success": False,
"status": "retry",
"message": "No compute package found. Set package in controller.",
}
),
203,
)
elif package == "local" and FEDN_ALLOW_LOCAL_PACKAGE is False:
return (
jsonify(
{
"success": False,
"status": "retry",
"message": "No compute package found. Set package in controller.",
"message": "Local package not allowed. Set FEDN_ALLOW_LOCAL_PACKAGE=True in controller config.",
}
),
203,
400,
)
elif package == "local" and FEDN_ALLOW_LOCAL_PACKAGE:
pass

# Assign client to combiner
if preferred_combiner:
Expand Down Expand Up @@ -572,7 +584,7 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name):
"status": "assigned",
"host": combiner.address,
"fqdn": combiner.fqdn,
"package": "remote", # TODO: Make this configurable
"package": package,
"ip": combiner.ip,
"port": combiner.port,
"helper_type": self.control.statestore.get_helper(),
Expand Down
2 changes: 1 addition & 1 deletion fedn/network/clients/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def assign(self):
"""
try:
retval = None
payload = {"name": self.name, "client_id": self.id, "preferred_combiner": self.preferred_combiner}
payload = {"name": self.name, "client_id": self.id, "preferred_combiner": self.preferred_combiner, "package": self.package}
retval = requests.post(
self.connect_string + FEDN_CUSTOM_URL_PREFIX + "/add_client",
json=payload,
Expand Down

0 comments on commit 7060069

Please sign in to comment.