Search in sources :

Example 1 with ServiceInfo

use of org.onap.so.client.oof.beans.ServiceInfo in project so by onap.

the class OofHomingV2 method callOof.

/**
 * Generates the request payload then sends to Oof to perform homing and licensing for the provided demands
 *
 * @param execution
 */
public void callOof(BuildingBlockExecution execution) {
    logger.trace("Started Oof Homing Call Oof");
    try {
        GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
        RequestContext requestContext = bb.getRequestContext();
        String requestId = requestContext.getMsoRequestId();
        ServiceInstance serviceInstance = bb.getCustomer().getServiceSubscription().getServiceInstances().get(0);
        Customer customer = bb.getCustomer();
        String timeout = execution.getVariable("timeout");
        if (isBlank(timeout)) {
            timeout = env.getProperty("oof.timeout", "PT30M");
        }
        OofRequest oofRequest = new OofRequest();
        RequestInfo requestInfo = buildRequestInfo(requestId, timeout);
        oofRequest.setRequestInformation(requestInfo);
        ServiceInfo serviceInfo = buildServiceInfo(serviceInstance);
        oofRequest.setServiceInformation(serviceInfo);
        PlacementInfo placementInfo = buildPlacementInfo(customer);
        placementInfo = buildPlacementDemands(serviceInstance, placementInfo);
        oofRequest.setPlacementInformation(placementInfo);
        LicenseInfo licenseInfo = buildLicenseInfo(serviceInstance);
        oofRequest.setLicenseInformation(licenseInfo);
        if (!placementInfo.getPlacementDemands().isEmpty() || !licenseInfo.getLicenseDemands().isEmpty()) {
            oofClient.postDemands(oofRequest);
        } else {
            logger.debug(SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
            throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
        }
        // Variables for ReceiveWorkflowMessage subflow
        execution.setVariable("asyncCorrelator", requestId);
        execution.setVariable("asyncMessageType", "OofResponse");
        execution.setVariable("asyncTimeout", timeout);
        logger.trace("Completed Oof Homing Call Oof");
    } catch (BpmnError e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
    } catch (BadResponseException e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
    } catch (Exception e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while " + "preparing oof request: " + e + "   Stack:" + ExceptionUtils.getFullStackTrace(e));
    }
}
Also used : LicenseInfo(org.onap.so.client.oof.beans.LicenseInfo) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) RequestInfo(org.onap.so.client.oof.beans.RequestInfo) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInfo(org.onap.so.client.oof.beans.ServiceInfo) PlacementInfo(org.onap.so.client.oof.beans.PlacementInfo) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) OofRequest(org.onap.so.client.oof.beans.OofRequest) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 2 with ServiceInfo

use of org.onap.so.client.oof.beans.ServiceInfo in project so by onap.

the class OofHomingV2 method buildServiceInfo.

/**
 * Builds the request information section for the homing/licensing request
 */
private ServiceInfo buildServiceInfo(ServiceInstance serviceInstance) {
    logger.trace("Building service information");
    ServiceInfo info = new ServiceInfo();
    ModelInfoServiceInstance modelInfo = serviceInstance.getModelInfoServiceInstance();
    if (isNotBlank(modelInfo.getModelInvariantUuid()) && isNotBlank(modelInfo.getModelUuid())) {
        info.setServiceInstanceId(serviceInstance.getServiceInstanceId());
        if (modelInfo.getServiceType() != null && modelInfo.getServiceType().length() > 0) {
            // temp solution
            info.setServiceName(modelInfo.getServiceType());
        }
        info.setModelInfo(buildModelInfo(serviceInstance.getModelInfoServiceInstance()));
    } else {
        throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + MODEL_VERSION_ID + ", " + MODEL_INVARIANT_ID);
    }
    return info;
}
Also used : ServiceInfo(org.onap.so.client.oof.beans.ServiceInfo) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 3 with ServiceInfo

use of org.onap.so.client.oof.beans.ServiceInfo in project so by onap.

the class OofClientTestIT method testPostDemands_success.

@Test
public void testPostDemands_success() throws BadResponseException, JsonProcessingException {
    String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}";
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setModelCustomizationName("modelCustomizationName-Service");
    modelInfo.setModelInvariantId("modelInvariantId-Service");
    modelInfo.setModelName("modelName-Service");
    modelInfo.setModelType("modelType-Service");
    modelInfo.setModelVersion("modelVersion-Service");
    modelInfo.setModelVersionId("modelVersionId-Service");
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setModelInfo(modelInfo);
    serviceInfo.setServiceInstanceId("serviceInstanceId");
    serviceInfo.setServiceName("serviceName");
    SubscriberInfo subscriberInfo = new SubscriberInfo();
    subscriberInfo.setGlobalSubscriberId("globalSubscriberId");
    subscriberInfo.setSubscriberCommonSiteId("subscriberCommonSiteId");
    subscriberInfo.setSubscriberName("subscriberName");
    ResourceModelInfo resourceModelInfo = new ResourceModelInfo();
    resourceModelInfo.setModelType("modelType");
    resourceModelInfo.setModelCustomizationName("modelCustomizationName");
    resourceModelInfo.setModelInvariantId("invarianteId");
    resourceModelInfo.setModelName("modelName");
    resourceModelInfo.setModelVersion("version");
    resourceModelInfo.setModelVersionId("versionId");
    PlacementDemand placementDemand = new PlacementDemand();
    placementDemand.setResourceModelInfo(resourceModelInfo);
    placementDemand.setResourceModuleName("resourceModuleName");
    placementDemand.setServiceResourceId("serviceResourceId");
    placementDemand.setTenantId("tenantId");
    OofRequestParameters oofRequestParameters = new OofRequestParameters();
    oofRequestParameters.setCustomerLatitude("customerLatitude");
    oofRequestParameters.setCustomerLongitude("customerLongitude");
    oofRequestParameters.setCustomerName("customerName");
    ArrayList<PlacementDemand> placementDemands = new ArrayList<>();
    placementDemands.add(placementDemand);
    PlacementInfo placementInfo = new PlacementInfo();
    placementInfo.setPlacementDemands(placementDemands);
    placementInfo.setRequestParameters(oofRequestParameters);
    placementInfo.setSubscriberInfo(subscriberInfo);
    RequestInfo requestInfo = new RequestInfo();
    requestInfo.setTransactionId("transactionId");
    List<String> optimizer = new ArrayList<>();
    optimizer.add("optimizer1");
    optimizer.add("optimizer2");
    requestInfo.setOptimizers(optimizer);
    requestInfo.setCallbackUrl("callBackUrl");
    requestInfo.setNumSolutions(1);
    requestInfo.setRequestId("requestId");
    requestInfo.setSourceId("sourceId");
    requestInfo.setTimeout(30L);
    requestInfo.setRequestType("requestType");
    OofRequest oofRequest = new OofRequest();
    oofRequest.setRequestInformation(requestInfo);
    oofRequest.setPlacementInformation(placementInfo);
    oofRequest.setServiceInformation(serviceInfo);
    oofRequest.setLicenseInformation(new LicenseInfo());
    wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
    client.postDemands(oofRequest);
    String oofRequestOutput = oofRequest.toJsonString();
    JSONAssert.assertEquals("{\n" + "  \"requestInfo\" : {\n" + "    \"transactionId\" : \"transactionId\",\n" + "    \"requestId\" : \"requestId\",\n" + "    \"callbackUrl\" : \"callBackUrl\",\n" + "    \"sourceId\" : \"sourceId\",\n" + "    \"requestType\" : \"requestType\",\n" + "    \"numSolutions\" : 1,\n" + "    \"optimizers\" : [ \"optimizer1\", \"optimizer2\" ],\n" + "    \"timeout\" : 30\n" + "  },\n" + "  \"serviceInfo\" : {\n" + "    \"serviceInstanceId\" : \"serviceInstanceId\",\n" + "    \"serviceName\" : \"serviceName\",\n" + "    \"modelInfo\" : {\n" + "      \"modelType\" : \"modelType-Service\",\n" + "      \"modelInvariantId\" : \"modelInvariantId-Service\",\n" + "      \"modelVersionId\" : \"modelVersionId-Service\",\n" + "      \"modelName\" : \"modelName-Service\",\n" + "      \"modelVersion\" : \"modelVersion-Service\",\n" + "      \"modelCustomizationName\" : \"modelCustomizationName-Service\"\n" + "    }\n" + "  },\n" + "  \"placementInfo\" : {\n" + "    \"requestParameters\" : {\n" + "      \"customerLatitude\" : \"customerLatitude\",\n" + "      \"customerLongitude\" : \"customerLongitude\",\n" + "      \"customerName\" : \"customerName\"\n" + "    },\n" + "    \"subscriberInfo\" : {\n" + "      \"globalSubscriberId\" : \"globalSubscriberId\",\n" + "      \"subscriberName\" : \"subscriberName\",\n" + "      \"subscriberCommonSiteId\" : \"subscriberCommonSiteId\"\n" + "    },\n" + "    \"placementDemands\" : [ {\n" + "      \"resourceModuleName\" : \"resourceModuleName\",\n" + "      \"serviceResourceId\" : \"serviceResourceId\",\n" + "      \"tenantId\" : \"tenantId\",\n" + "      \"resourceModelInfo\" : {\n" + "        \"modelType\" : \"modelType\",\n" + "        \"modelInvariantId\" : \"invarianteId\",\n" + "        \"modelVersionId\" : \"versionId\",\n" + "        \"modelName\" : \"modelName\",\n" + "        \"modelVersion\" : \"version\",\n" + "        \"modelCustomizationName\" : \"modelCustomizationName\"\n" + "      }\n" + "    } ]\n" + "  },\n" + "  \"licenseInfo\" : { \n" + "    \"licenseDemands\" : [ ]\n" + "}\n" + "}", oofRequestOutput.replace("\r\n", "\n"), false);
}
Also used : LicenseInfo(org.onap.so.client.oof.beans.LicenseInfo) ModelInfo(org.onap.so.client.oof.beans.ModelInfo) ResourceModelInfo(org.onap.so.client.oof.beans.ResourceModelInfo) ResourceModelInfo(org.onap.so.client.oof.beans.ResourceModelInfo) ArrayList(java.util.ArrayList) PlacementDemand(org.onap.so.client.oof.beans.PlacementDemand) RequestInfo(org.onap.so.client.oof.beans.RequestInfo) ServiceInfo(org.onap.so.client.oof.beans.ServiceInfo) PlacementInfo(org.onap.so.client.oof.beans.PlacementInfo) OofRequestParameters(org.onap.so.client.oof.beans.OofRequestParameters) OofRequest(org.onap.so.client.oof.beans.OofRequest) SubscriberInfo(org.onap.so.client.oof.beans.SubscriberInfo) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Aggregations

ServiceInfo (org.onap.so.client.oof.beans.ServiceInfo)3 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)2 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)2 LicenseInfo (org.onap.so.client.oof.beans.LicenseInfo)2 OofRequest (org.onap.so.client.oof.beans.OofRequest)2 PlacementInfo (org.onap.so.client.oof.beans.PlacementInfo)2 RequestInfo (org.onap.so.client.oof.beans.RequestInfo)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)1 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)1 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)1 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)1 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)1 BadResponseException (org.onap.so.client.exception.BadResponseException)1 ModelInfo (org.onap.so.client.oof.beans.ModelInfo)1 OofRequestParameters (org.onap.so.client.oof.beans.OofRequestParameters)1 PlacementDemand (org.onap.so.client.oof.beans.PlacementDemand)1 ResourceModelInfo (org.onap.so.client.oof.beans.ResourceModelInfo)1 SubscriberInfo (org.onap.so.client.oof.beans.SubscriberInfo)1