Skip to content
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

Feature/SK-996 | Users should be able to choose not to upload a package but instead use the "localpackage" approach #702

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion fedn/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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
21 changes: 4 additions & 17 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 FEDN_ALLOW_LOCAL_PACKAGE, get_controller_config, get_network_config
from fedn.common.config import 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 @@ -522,10 +522,6 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
:return: A json response with combiner assignment config.
:rtype: :class:`flask.Response`
"""
local_package = FEDN_ALLOW_LOCAL_PACKAGE
if local_package:
local_package = True

if package == "remote":
package_object = self.statestore.get_compute_package()
if package_object is None:
Expand All @@ -540,18 +536,8 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
203,
)
helper_type = self.control.statestore.get_helper()
elif package == "local" and local_package is False:
print("Local package not allowed. Set FEDN_ALLOW_LOCAL_PACKAGE=True in controller config.")
return (
jsonify(
{
"success": False,
"message": "Local package not allowed. Set FEDN_ALLOW_LOCAL_PACKAGE=True in controller config.",
}
),
400,
)
elif package == "local" and local_package is True:
else:
# Else package is "local":
helper_type = ""

# Assign client to combiner
Expand Down Expand Up @@ -582,6 +568,7 @@ def add_client(self, client_id, preferred_combiner, remote_addr, name, package):
"combiner": combiner.name,
"ip": remote_addr,
"status": "available",
"package": package,
}
# Add client to network
self.control.network.add_client(client_config)
Expand Down
14 changes: 12 additions & 2 deletions fedn/network/storage/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,22 @@ def set_client(self, client_data):
"""
client_data["updated_at"] = str(datetime.now())
try:
self.clients.update_one({"client_id": client_data["client_id"]}, {"$set": client_data}, True)
# self.clients.update_one({"client_id": client_data["client_id"]}, {"$set": client_data}, True)
self.clients.update_one(
{"client_id": client_data["client_id"]},
{"$set": {k: v for k, v in client_data.items() if v is not None}},
upsert=True
)
except KeyError:
# If client_id is not present, use name as identifier, for backwards compatibility
id = str(uuid.uuid4())
client_data["client_id"] = id
self.clients.update_one({"name": client_data["name"]}, {"$set": client_data}, True)
# self.clients.update_one({"name": client_data["name"]}, {"$set": client_data}, True)
self.clients.update_one(
{"client_id": client_data["client_id"]},
{"$set": {k: v for k, v in client_data.items() if v is not None}},
upsert=True
)

def get_client(self, client_id):
"""Get client by client_id.
Expand Down
Loading