Merge "take-1 for the NST selection function"
[optf/osdf.git] / solverapp.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2020 AT&T Intellectual Property
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #
16 # -------------------------------------------------------------------------
17 #
18
19 from flask import request, g
20
21 from osdf.apps.baseapp import app, run_app
22 from osdf.logging.osdf_logging import audit_log
23 from osdf.webapp.appcontroller import auth_basic
24 from runtime.model_api import create_model_data, retrieve_model_data, retrieve_all_models, delete_model_data
25 from runtime.models.api.model_request import OptimModelRequestAPI
26 from runtime.optim_engine import process_request
27
28
29 @app.route("/api/oof/optengine/v1", methods=["POST"])
30 @auth_basic.login_required
31 def opt_engine_rest_api():
32     """Perform OptimEngine optimization after validating the request
33     """
34     request_json = request.get_json()
35     return process_request(request_json)
36
37
38 @app.route("/api/oof/optmodel/v1", methods=["PUT", "POST"])
39 @auth_basic.login_required
40 def opt_model_create_rest_api():
41     """Perform OptimEngine optimization after validating the request
42     """
43     request_json = request.get_json()
44     OptimModelRequestAPI(request_json).validate()
45     return create_model_data(request_json)
46
47
48 @app.route("/api/oof/optmodel/v1/<model_id>", methods=["GET"])
49 @auth_basic.login_required
50 def opt_get_model_rest_api(model_id):
51     """Retrieve model data
52     """
53
54     return retrieve_model_data(model_id)
55
56
57 @app.route("/api/oof/optmodel/v1", methods=["GET"])
58 @auth_basic.login_required
59 def opt_get_all_models_rest_api():
60     """Retrieve all models data
61     """
62     return retrieve_all_models()
63
64
65 @app.route("/api/oof/optmodel/v1/<model_id>", methods=["DELETE"])
66 @auth_basic.login_required
67 def opt_delete_model_rest_api(model_id):
68     """Perform OptimEngine optimization after validating the request
69     """
70     return delete_model_data(model_id)
71
72
73 @app.route("/api/oof/optengine/healthcheck/v1", methods=["GET"])
74 def do_health_check():
75     """Simple health check"""
76     audit_log.info("A OptimEngine health check v1 request is processed!")
77     return "OK"
78
79
80 if __name__ == "__main__":
81     run_app()