def test_request_vfmod(self):
     req_json = json_from_file("./test/placement-tests/request_vfmod.json")
     policies = pol.get_local_policies("test/policy-local-files/", self.lp)
     req_info = req_json['requestInfo']
     demands = req_json['placementInfo']['placementDemands']
     request_parameters = req_json['placementInfo']['requestParameters']
     service_info = req_json['serviceInfo']
     conductor.request(req_info, demands, request_parameters, service_info, self.template_fields,
                       self.osdf_config, policies)
Exemple #2
0
    def do_slice_selection(self):
        req_info = self.request_json['requestInfo']
        app_info = self.slice_config['app_info'][self.model_type]
        mdc_from_json(self.request_json)
        requirements = self.request_json.get(app_info['requirements_field'], {})
        model_info = self.request_json.get(app_info['model_info'])
        model_name = model_info['name']
        policies = self.get_app_policies(model_name, app_info['app_name'])
        request_parameters = self.get_request_parameters(requirements, model_info)

        demands = [
            {
                "resourceModuleName": model_name,
                "resourceModelInfo": {}
            }
        ]

        try:
            template_fields = {
                'location_enabled': False,
                'version': '2020-08-13'
            }
            resp = conductor.request(req_info, demands, request_parameters, {}, template_fields,
                                     self.osdf_config, policies)
        except RequestException as e:
            resp = e.response.json()
            error = resp['plans'][0]['message']
            if isinstance(error, list) and "Unable to find any" in error[0]:
                return self.response_processor.get_slice_selection_response([])
            error_log.error('Error from conductor {}'.format(error))
            return self.response_processor.process_error_response(error)

        debug_log.debug("Response from conductor {}".format(str(resp)))
        recommendations = resp["plans"][0].get("recommendations")
        subnets = [subnet['domainType'] for subnet in self.request_json['subnetCapabilities']] \
            if self.request_json.get('subnetCapabilities') else []
        return self.response_processor.process_response(recommendations, model_info, subnets, self.model_type)
Exemple #3
0
    def get_conductor(self, req_info, request_parameters, policies,
                      model_name):
        demands = [{"resourceModuleName": model_name, "resourceModelInfo": {}}]

        try:
            template_fields = {
                'location_enabled': False,
                'version': '2020-08-13'
            }
            resp = conductor.request(req_info, demands, request_parameters, {},
                                     template_fields, self.osdf_config,
                                     policies)
        except RequestException as e:
            resp = e.response.json()
            error = resp['plans'][0]['message']
            if "Unable to find any" in error:
                return self.get_nst_selection_response([])
            error_log.error('Error from conductor {}'.format(error))
            return self.error_response(error)
        debug_log.debug(
            "Response from conductor in get_conductor method {}".format(
                str(resp)))
        recommendations = resp["plans"][0].get("recommendations")
        return self.process_response(recommendations, model_name)
Exemple #4
0
def process_placement_opt(request_json, policies, osdf_config):
    """Perform the work for placement optimization (e.g. call SDC artifact and make conductor request)

    NOTE: there is scope to make the requests to policy asynchronous to speed up overall performance
    :param request_json: json content from original request
    :param policies: flattened policies corresponding to this request
    :param osdf_config: configuration specific to OSDF app
    :param prov_status: provStatus retrieved from Subscriber policy
    :return: None, but make a POST to callback URL
    """

    try:
        mdc_from_json(request_json)
        rc = get_rest_client(request_json, service="so")
        req_id = request_json["requestInfo"]["requestId"]
        transaction_id = request_json['requestInfo']['transactionId']

        metrics_log.info(MH.inside_worker_thread(req_id))
        license_info = None
        if request_json.get('licenseInfo', {}).get('licenseDemands'):
            license_info = license_optim(request_json)

        # Conductor only handles placement, only call Conductor if placementDemands exist
        if request_json.get('placementInfo', {}).get('placementDemands'):
            metrics_log.info(MH.requesting("placement/conductor", req_id))
            req_info = request_json['requestInfo']
            demands = request_json['placementInfo']['placementDemands']
            request_parameters = request_json['placementInfo'][
                'requestParameters']
            service_info = request_json['serviceInfo']
            template_fields = {
                'location_enabled': True,
                'version': '2017-10-10'
            }
            resp = conductor.request(req_info, demands, request_parameters,
                                     service_info, template_fields,
                                     osdf_config, policies)
            if resp["plans"][0].get("recommendations"):
                placement_response = conductor_response_processor(
                    resp, req_id, transaction_id)
            else:  # "solved" but no solutions found
                placement_response = conductor_no_solution_processor(
                    resp, req_id, transaction_id)
            if license_info:  # Attach license solution if it exists
                placement_response['solutionInfo'][
                    'licenseInfo'] = license_info
        else:  # License selection only scenario
            placement_response = {
                "transactionId": transaction_id,
                "requestId": req_id,
                "requestStatus": "completed",
                "statusMessage": "License selection completed successfully",
                "solutionInfo": {
                    "licenseInfo": license_info
                }
            }
    except Exception as err:
        error_log.error("Error for {} {}".format(req_id,
                                                 traceback.format_exc()))

        try:
            body = build_json_error_body(err)
            metrics_log.info(MH.sending_response(req_id, "ERROR"))
            rc.request(json=body, noresponse=True)
        except RequestException:
            error_log.error(
                "Error sending asynchronous notification for {} {}".format(
                    req_id, traceback.format_exc()))
        return

    try:
        metrics_log.info(
            MH.calling_back_with_body(req_id, rc.url, placement_response))
        rc.request(json=placement_response, noresponse=True)
    except RequestException:  # can't do much here but log it and move on
        error_log.error(
            "Error sending asynchronous notification for {} {}".format(
                req_id, traceback.format_exc()))