Skip to content

Commit

Permalink
Update dummy oa (NVIDIA#500)
Browse files Browse the repository at this point in the history
* Update dummy overseer agent to include dummy info

* Update key string
Add handling shutdown on dummy overseer agent
  • Loading branch information
IsaacYangSLA authored May 9, 2022
1 parent 28282fa commit 3b9be42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 8 additions & 1 deletion nvflare/ha/dummy_overseer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def initialize(self, fl_ctx: FLContext):

name, fl_port, admin_port = self.sp_end_point.split(":")
self._psp = SP(name, fl_port, admin_port, DummyOverseerAgent.SSID, True)
self._overseer_info = {"primary_sp": self._psp, "sp_list": [self._psp], "system": "ready"}

def get_primary_sp(self) -> SP:
"""Return current primary service provider. The PSP is static in the dummy agent."""
Expand All @@ -54,7 +55,7 @@ def get_primary_sp(self) -> SP:
def promote_sp(self, sp_end_point, headers=None):
resp = Response()
resp.status_code = 200
resp.content = json.dumps({"error": "this functionality is not supported by the dummy agent"})
resp.content = json.dumps({"Error": "this functionality is not supported by the dummy agent"})
return resp

def start(self, update_callback=None, conditional_cb=False):
Expand All @@ -69,6 +70,12 @@ def pause(self):
def resume(self):
self._flag.set()

def set_state(self, state):
resp = Response()
resp.status_code = 200
resp.content = json.dumps({"Error": "this functionality is not supported by the dummy agent"})
return resp

def end(self):
self._flag.set()
self._asked_to_exit = True
Expand Down
10 changes: 8 additions & 2 deletions nvflare/ha/ha_admin_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,11 @@ def promote_sp(self, args, api):

def shutdown_system(self, args, api):
print("Shutting down the system...")
api.overseer_agent.set_state("shutdown")
return {"status": APIStatus.SUCCESS, "details": "Set state to shutdown in overseer."}
resp = api.overseer_agent.set_state("shutdown")
if json.loads(resp.text).get("Error"):
return {
"status": APIStatus.ERROR_RUNTIME,
"details": "Error: {}".format(json.loads(resp.text).get("Error")),
}
else:
return {"status": APIStatus.SUCCESS, "details": "Set state to shutdown in overseer."}
4 changes: 2 additions & 2 deletions nvflare/ha/overseer/overseer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def heartbeat():
project = req.get("project")
role = req.get("role")
if project is None or role is None:
return jsonify({"error": "project and role must be provided"})
return jsonify({"Error": "project and role must be provided"})
now = datetime.utcnow()
update_sp_state(project, now)
if role == "server":
sp_end_point = req.get("sp_end_point")
if sp_end_point is None:
return jsonify({"error": "sp_end_point is not provided"})
return jsonify({"Error": "sp_end_point is not provided"})
incoming_sp = dict(sp_end_point=sp_end_point, project=project)
psp = simple_PSP_policy(incoming_sp, now)
elif role in ["client", "admin"]:
Expand Down

0 comments on commit 3b9be42

Please sign in to comment.