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-553 | Add pagination option to REST-API #482

Merged
merged 23 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
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
Loading