-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started on replacing mongostatestore
- Loading branch information
1 parent
0ec6d6c
commit 4ebb1eb
Showing
26 changed files
with
382 additions
and
1,710 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
from fedn.network.api.v1.graphql.schema import schema | ||
|
||
custom_url_prefix = os.environ.get("FEDN_CUSTOM_URL_PREFIX", False) | ||
# statestore_config,modelstorage_config,network_id,control=set_statestore_config() | ||
api = API(statestore, control) | ||
app = Flask(__name__) | ||
for bp in _routes: | ||
|
@@ -55,89 +54,6 @@ def graphql_endpoint(): | |
app.add_url_rule(f"{custom_url_prefix}/api/v1/graphql", view_func=graphql_endpoint, methods=["POST"]) | ||
|
||
|
||
@app.route("/get_model_trail", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_model_trail(): | ||
"""Get the model trail for a given session. | ||
param: session: The session id to get the model trail for. | ||
type: session: str | ||
return: The model trail for the given session as a json object. | ||
rtype: json | ||
""" | ||
return api.get_model_trail() | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_model_trail", view_func=get_model_trail, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_model_ancestors", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_model_ancestors(): | ||
"""Get the ancestors of a model. | ||
param: model: The model id to get the ancestors for. | ||
type: model: str | ||
param: limit: The maximum number of ancestors to return. | ||
type: limit: int | ||
return: A list of model objects that the model derives from. | ||
rtype: json | ||
""" | ||
model = request.args.get("model", None) | ||
limit = request.args.get("limit", None) | ||
|
||
return api.get_model_ancestors(model, limit) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_model_ancestors", view_func=get_model_ancestors, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_model_descendants", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_model_descendants(): | ||
"""Get the ancestors of a model. | ||
param: model: The model id to get the child for. | ||
type: model: str | ||
param: limit: The maximum number of descendants to return. | ||
type: limit: int | ||
return: A list of model objects that are descendents of the provided model id. | ||
rtype: json | ||
""" | ||
model = request.args.get("model", None) | ||
limit = request.args.get("limit", None) | ||
|
||
return api.get_model_descendants(model, limit) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_model_descendants", view_func=get_model_descendants, methods=["GET"]) | ||
|
||
|
||
@app.route("/list_models", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def list_models(): | ||
"""Get models from the statestore. | ||
param: | ||
session_id: The session id to get the model trail for. | ||
limit: The maximum number of models to return. | ||
type: limit: int | ||
param: skip: The number of models to skip. | ||
type: skip: int | ||
Returns: | ||
_type_: json | ||
""" | ||
session_id = request.args.get("session_id", None) | ||
limit = request.args.get("limit", None) | ||
skip = request.args.get("skip", None) | ||
include_active = request.args.get("include_active", None) | ||
|
||
return api.get_models(session_id, limit, skip, include_active) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/list_models", view_func=list_models, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_model", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_model(): | ||
|
@@ -253,139 +169,6 @@ def get_combiner(): | |
app.add_url_rule(f"{custom_url_prefix}/get_combiner", view_func=get_combiner, methods=["GET"]) | ||
|
||
|
||
@app.route("/list_rounds", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def list_rounds(): | ||
"""Get all rounds from the statestore. | ||
return: All rounds as a json object. | ||
rtype: json | ||
""" | ||
return api.get_all_rounds() | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/list_rounds", view_func=list_rounds, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_round", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_round(): | ||
"""Get a round from the statestore. | ||
param: round_id: The round id to get. | ||
type: round_id: str | ||
return: The round as a json object. | ||
rtype: json | ||
""" | ||
round_id = request.args.get("round_id", None) | ||
if round_id is None: | ||
return jsonify({"success": False, "message": "Missing round id."}), 400 | ||
return api.get_round(round_id) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_round", view_func=get_round, methods=["GET"]) | ||
|
||
|
||
@app.route("/start_session", methods=["GET", "POST"]) | ||
@jwt_auth_required(role="admin") | ||
def start_session(): | ||
"""Start a new session. | ||
return: The response from control. | ||
rtype: json | ||
""" | ||
json_data = request.get_json() | ||
return api.start_session(**json_data) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/start_session", view_func=start_session, methods=["GET", "POST"]) | ||
|
||
|
||
@app.route("/list_sessions", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def list_sessions(): | ||
"""Get all sessions from the statestore. | ||
return: All sessions as a json object. | ||
rtype: json | ||
""" | ||
limit = request.args.get("limit", None) | ||
skip = request.args.get("skip", None) | ||
|
||
return api.get_all_sessions(limit, skip) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/list_sessions", view_func=list_sessions, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_session", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_session(): | ||
"""Get a session from the statestore. | ||
param: session_id: The session id to get. | ||
type: session_id: str | ||
return: The session as a json object. | ||
rtype: json | ||
""" | ||
session_id = request.args.get("session_id", None) | ||
if session_id is None: | ||
return ( | ||
jsonify({"success": False, "message": "Missing session id."}), | ||
400, | ||
) | ||
return api.get_session(session_id) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_session", view_func=get_session, methods=["GET"]) | ||
|
||
|
||
@app.route("/set_active_package", methods=["PUT"]) | ||
@jwt_auth_required(role="admin") | ||
def set_active_package(): | ||
id = request.args.get("id", None) | ||
return api.set_active_compute_package(id) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/set_active_package", view_func=set_active_package, methods=["PUT"]) | ||
|
||
|
||
@app.route("/set_package", methods=["POST"]) | ||
@jwt_auth_required(role="admin") | ||
def set_package(): | ||
""" Set the compute package in the statestore. | ||
Usage with curl: | ||
curl -k -X POST \ | ||
-F [email protected] \ | ||
-F helper="kerashelper" \ | ||
http://localhost:8092/set_package | ||
param: file: The compute package file to set. | ||
type: file: file | ||
return: The response from the statestore. | ||
rtype: json | ||
""" | ||
helper_type = request.form.get("helper", None) | ||
name = request.form.get("name", None) | ||
description = request.form.get("description", None) | ||
|
||
if helper_type is None: | ||
return ( | ||
jsonify({"success": False, "message": "Missing helper type."}), | ||
400, | ||
) | ||
try: | ||
file = request.files["file"] | ||
except KeyError: | ||
return jsonify({"success": False, "message": "Missing file."}), 400 | ||
return api.set_compute_package(file=file, helper_type=helper_type, name=name, description=description) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/set_package", view_func=set_package, methods=["POST"]) | ||
|
||
|
||
@app.route("/get_package", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_package(): | ||
|
@@ -400,24 +183,6 @@ def get_package(): | |
app.add_url_rule(f"{custom_url_prefix}/get_package", view_func=get_package, methods=["GET"]) | ||
|
||
|
||
@app.route("/list_compute_packages", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def list_compute_packages(): | ||
"""Get the compute package from the statestore. | ||
return: The compute package as a json object. | ||
rtype: json | ||
""" | ||
limit = request.args.get("limit", None) | ||
skip = request.args.get("skip", None) | ||
include_active = request.args.get("include_active", None) | ||
|
||
return api.list_compute_packages(limit=limit, skip=skip, include_active=include_active) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/list_compute_packages", view_func=list_compute_packages, methods=["GET"]) | ||
|
||
|
||
@app.route("/download_package", methods=["GET"]) | ||
@jwt_auth_required(role="client") | ||
def download_package(): | ||
|
@@ -444,60 +209,6 @@ def get_package_checksum(): | |
app.add_url_rule(f"{custom_url_prefix}/get_package_checksum", view_func=get_package_checksum, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_latest_model", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_latest_model(): | ||
"""Get the latest model from the statestore. | ||
return: The initial model as a json object. | ||
rtype: json | ||
""" | ||
return api.get_latest_model() | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_latest_model", view_func=get_latest_model, methods=["GET"]) | ||
|
||
|
||
@app.route("/set_current_model", methods=["PUT"]) | ||
@jwt_auth_required(role="admin") | ||
def set_current_model(): | ||
"""Set the initial model in the statestore and upload to model repository. | ||
Usage with curl: | ||
curl -k -X PUT | ||
-F id=<model-id> | ||
http://localhost:8092/set_current_model | ||
param: id: The model id to set. | ||
type: id: str | ||
return: boolean. | ||
rtype: json | ||
""" | ||
id = request.args.get("id", None) | ||
if id is None: | ||
return jsonify({"success": False, "message": "Missing model id."}), 400 | ||
return api.set_current_model(id) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/set_current_model", view_func=set_current_model, methods=["PUT"]) | ||
|
||
# Get initial model endpoint | ||
|
||
|
||
@app.route("/get_initial_model", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_initial_model(): | ||
"""Get the initial model from the statestore. | ||
return: The initial model as a json object. | ||
rtype: json | ||
""" | ||
return api.get_initial_model() | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_initial_model", view_func=get_initial_model, methods=["GET"]) | ||
|
||
|
||
@app.route("/set_initial_model", methods=["POST"]) | ||
@jwt_auth_required(role="admin") | ||
def set_initial_model(): | ||
|
@@ -553,39 +264,6 @@ def get_client_config(): | |
app.add_url_rule(f"{custom_url_prefix}/get_client_config", view_func=get_client_config, methods=["GET"]) | ||
|
||
|
||
@app.route("/get_events", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def get_events(): | ||
"""Get the events from the statestore. | ||
return: The events as a json object. | ||
rtype: json | ||
""" | ||
# TODO: except filter with request.get_json() | ||
kwargs = request.args.to_dict() | ||
|
||
return api.get_events(**kwargs) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/get_events", view_func=get_events, methods=["GET"]) | ||
|
||
|
||
@app.route("/list_validations", methods=["GET"]) | ||
@jwt_auth_required(role="admin") | ||
def list_validations(): | ||
"""Get all validations from the statestore. | ||
return: All validations as a json object. | ||
rtype: json | ||
""" | ||
# TODO: except filter with request.get_json() | ||
kwargs = request.args.to_dict() | ||
return api.get_all_validations(**kwargs) | ||
|
||
|
||
if custom_url_prefix: | ||
app.add_url_rule(f"{custom_url_prefix}/list_validations", view_func=list_validations, methods=["GET"]) | ||
|
||
|
||
@app.route("/add_combiner", methods=["POST"]) | ||
@jwt_auth_required(role="combiner") | ||
def add_combiner(): | ||
|
Oops, something went wrong.