Merge "call of the route app optmizer from osdfapp.py"
[optf/osdf.git] / osdfapp.py
index 348a88c..bd5efa7 100755 (executable)
@@ -45,6 +45,8 @@ from requests import RequestException
 from schematics.exceptions import DataError
 from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log
 from osdf.models.api.placementRequest import PlacementAPI
+from osdf.operation.responses import osdf_response_for_request_accept as req_accept
+from osdf.optimizers.routeopt.simple_route_opt import RouteOpt
 
 ERROR_TEMPLATE = osdf.ERROR_TEMPLATE
 
@@ -93,6 +95,13 @@ def handle_data_error(e):
     return response
 
 
+@app.route("/api/oof/v1/healthcheck", methods=["GET"])
+def do_osdf_health_check():
+    """Simple health check"""
+    audit_log.info("A health check request is processed!")
+    return "OK"
+
+
 @app.route("/api/oof/v1/placement", methods=["POST"])
 @auth_basic.login_required
 def do_placement_opt():
@@ -107,11 +116,23 @@ def do_placement_opt():
     PlacementAPI(request_json).validate()
     policies = get_policies(request_json, "placement")
     audit_log.info(MH.new_worker_thread(req_id, "[for placement]"))
-    t = Thread(target=process_placement_opt, args=(request_json, policies, osdf_config, ""))
+    t = Thread(target=process_placement_opt, args=(request_json, policies, osdf_config))
     t.start()
     audit_log.info(MH.accepted_valid_request(req_id, request))
-    return osdf.operation.responses.osdf_response_for_request_accept(
-        req_id=req_id, text="Accepted placement request. Response will be posted to callback URL")
+    return req_accept(request_id=req_id,
+                      transaction_id=request_json['requestInfo']['transactionId'],
+                      request_status="accepted", status_message="")
+
+
+@app.route("/api/oof/v1/route", methods=["POST"])
+@auth_basic.login_required
+def do_route_calc():
+    """Perform the basic route calculations and returnn the vpn-bindings
+    TODO:Need to add the new class for the route in the API and model to provide this function
+    """
+    request_json = request.get_json()
+    audit_log.info("Calculate Route request received!")
+    return RouteOpt.getRoute(request_json)
 
 
 @app.errorhandler(500)