Skip to content

Commit

Permalink
Feature/SK-553 | Add pagination option to REST-API (#482)
Browse files Browse the repository at this point in the history
Co-authored-by: Fredrik Wrede <[email protected]>
  • Loading branch information
niklastheman and Wrede authored Nov 1, 2023
1 parent 202bac9 commit 1cd03e3
Show file tree
Hide file tree
Showing 11 changed files with 1,746 additions and 937 deletions.
32 changes: 21 additions & 11 deletions .ci/tests/examples/wait_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,31 @@ def _test_rounds(n_rounds):
return n == n_rounds


def _test_nodes(n_nodes, node_type, reducer_host='localhost', reducer_port='8090'):
def _test_nodes(n_nodes, node_type, reducer_host='localhost', reducer_port='8092'):
try:
resp = requests.get(
f'http://{reducer_host}:{reducer_port}/netgraph', verify=False)

endpoint = "list_clients" if node_type == "client" else "list_combiners"

response = requests.get(
f'http://{reducer_host}:{reducer_port}/{endpoint}', verify=False)

if response.status_code == 200:

data = json.loads(response.content)

count = 0
if node_type == "client":
arr = data.get('result')
count = sum(element.get('status') == "online" for element in arr)
else:
count = data.get('count')

_eprint(f'Active {node_type}s: {count}.')
return count == n_nodes

except Exception as e:
_eprint(f'Reques exception econuntered: {e}.')
return False
if resp.status_code == 200:
gr = json.loads(resp.content)
n = sum(values.get('type') == node_type and values.get(
'status') == 'active' for values in gr['nodes'])
_eprint(f'Active {node_type}s: {n}.')
return n == n_nodes
_eprint(f'Reducer returned {resp.status_code}.')
return False


def rounds(n_rounds=3):
Expand Down
16 changes: 16 additions & 0 deletions fedn/fedn/common/tracer/mongotracer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from datetime import datetime

from google.protobuf.json_format import MessageToDict

Expand All @@ -18,6 +19,7 @@ def __init__(self, mongo_config, network_id):
self.rounds = self.mdb['control.rounds']
self.sessions = self.mdb['control.sessions']
self.validations = self.mdb['control.validations']
self.clients = self.mdb['network.clients']
except Exception as e:
print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
self.status = None
Expand Down Expand Up @@ -82,3 +84,17 @@ def set_round_data(self, round_data):
"""
self.rounds.update_one({'round_id': str(round_data['round_id'])}, {
'$push': {'reducer': round_data}}, True)

def update_client_status(self, client_name, status):
""" Update client status in statestore.
:param client_name: The client name
:type client_name: str
:param status: The client status
:type status: str
:return: None
"""
datetime_now = datetime.now()
filter_query = {"name": client_name}

update_query = {"$set": {"last_seen": datetime_now, "status": status}}
self.clients.update_one(filter_query, update_query)
Loading

0 comments on commit 1cd03e3

Please sign in to comment.