Search in sources :

Example 1 with ServiceModelList

use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.

the class ActivateVnfOperationalEnvironment method execute.

/**
 * The Point-Of-Entry from APIH with VID request to send activate request
 *
 * @param requestId - String
 * @param request - CloudOrchestrationRequest object
 * @return void - nothing
 */
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    String vnfOperationalEnvironmentId = request.getOperationalEnvironmentId();
    String vidWorkloadContext = request.getRequestDetails().getRequestParameters().getWorkloadContext();
    List<ServiceModelList> serviceModelVersionIdList = request.getRequestDetails().getRequestParameters().getManifest().getServiceModelList();
    String ecompOperationalEnvironmentId = null;
    AAIResultWrapper wrapper = getAAIOperationalEnvironment(vnfOperationalEnvironmentId);
    Optional<Relationships> optRelationships = wrapper.getRelationships();
    if (optRelationships.isPresent()) {
        Relationships relationships = optRelationships.get();
        List<AAIResourceUri> operationalEnvironments = relationships.getRelatedUris(Types.OPERATIONAL_ENVIRONMENT);
        if (!operationalEnvironments.isEmpty()) {
            ecompOperationalEnvironmentId = operationalEnvironments.get(0).getURIKeys().get(AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId);
        }
    }
    logger.debug("  vnfOperationalEnvironmentId   : {}", vnfOperationalEnvironmentId);
    logger.debug("  ecompOperationalEnvironmentId : {}", ecompOperationalEnvironmentId);
    OperationalEnvironment operationalEnv = wrapper.asBean(OperationalEnvironment.class).get();
    String workloadContext = operationalEnv.getWorkloadContext();
    logger.debug("  aai workloadContext: {}", workloadContext);
    if (!vidWorkloadContext.equals(workloadContext)) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
        throw new ValidateException.Builder(" The vid workloadContext did not match from aai record. " + " vid workloadContext:" + vidWorkloadContext + " aai workloadContext:" + workloadContext, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    }
    if (ecompOperationalEnvironmentId == null) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
        throw new ValidateException.Builder(" The ECOMP OE was not in aai record; the value of relationship.relationship-data key: " + AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    }
    processActivateSDCRequest(requestId, ecompOperationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment)

Example 2 with ServiceModelList

use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.

the class ActivateVnfOperationalEnvironmentTest method processActivateSDCRequestTest_202.

@Test
public void processActivateSDCRequestTest_202() throws Exception {
    String distributionId = "TEST_distributionId";
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("statusCode", "202");
    jsonObject.put("message", "Success");
    jsonObject.put("distributionId", distributionId);
    // prepare request detail
    List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
    ServiceModelList serviceModelList1 = new ServiceModelList();
    serviceModelList1.setRecoveryAction(RecoveryAction.retry);
    serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
    serviceModelVersionIdList.add(serviceModelList1);
    wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
    activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 3 with ServiceModelList

use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.

the class ActivateVnfOperationalEnvironmentTest method processActivateSDCRequestTest_409.

@Test
public void processActivateSDCRequestTest_409() throws ApiException, JsonProcessingException {
    // ERROR in asdc
    JSONObject jsonMessages = new JSONObject();
    jsonMessages.put("message", "Failure");
    jsonMessages.put("messageId", "SVC4675");
    jsonMessages.put("text", "Error: Service state is invalid for this action.");
    JSONObject jsonServException = new JSONObject();
    jsonServException.put("policyException", jsonMessages);
    // jsonServException.put("serviceException", jsonMessages);
    JSONObject jsonErrorResponse = new JSONObject();
    jsonErrorResponse.put("requestError", jsonServException);
    // prepare request detail
    List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
    ServiceModelList serviceModelList1 = new ServiceModelList();
    serviceModelList1.setRecoveryAction(RecoveryAction.retry);
    serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
    serviceModelVersionIdList.add(serviceModelList1);
    InfraActiveRequests iar = new InfraActiveRequests();
    iar.setRequestId(requestId);
    iar.setRequestStatus("PENDING");
    wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestId)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonErrorResponse.toString()).withStatus(HttpStatus.SC_CONFLICT)));
    wireMockServer.stubFor(post(urlPathEqualTo("/infraActiveRequests/")).withRequestBody(containing("operationalEnvId\":\"1dfe7154-eae0-44f2-8e7a-8e5e7882e55d\"")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    thrown.expect(ValidateException.class);
    activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 4 with ServiceModelList

use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.

the class ActivateVnfOperationalEnvironmentTest method executionTest.

@Test
public void executionTest() throws Exception {
    List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
    ServiceModelList serviceModelList1 = new ServiceModelList();
    serviceModelList1.setRecoveryAction(RecoveryAction.retry);
    serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
    serviceModelVersionIdList.add(serviceModelList1);
    RequestDetails requestDetails = new RequestDetails();
    RequestParameters requestParameters = new RequestParameters();
    Manifest manifest = new Manifest();
    manifest.setServiceModelList(serviceModelVersionIdList);
    requestParameters.setManifest(manifest);
    requestParameters.setWorkloadContext(workloadContext);
    requestDetails.setRequestParameters(requestParameters);
    request.setOperationalEnvironmentId(vnfOperationalEnvironmentId);
    request.setRequestDetails(requestDetails);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("statusCode", "202");
    jsonObject.put("message", "Success");
    jsonObject.put("distributionId", sdcDistributionId);
    wireMockServer.stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/activateOperationalEnvironmentWithRelationship.json").withStatus(HttpStatus.SC_ACCEPTED)));
    wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
    activateVnf.execute(requestId, request);
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Manifest(org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest) RequestDetails(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails) RequestParameters(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestParameters) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 5 with ServiceModelList

use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.

the class ActivateVnfOperationalEnvironment method processActivateSDCRequest.

/**
 * The Method to send the Activation Requests to SDC
 *
 * @param requestId - String
 * @param operationalEnvironmentId - String
 * @param serviceModelVersionIdList - List<ServiceModelList> list
 * @param workloadContext - String
 * @return jsonResponse - JSONObject object
 */
public void processActivateSDCRequest(String requestId, String operationalEnvironmentId, List<ServiceModelList> serviceModelVersionIdList, String workloadContext, String vnfOperationalEnvironmentId) throws ApiException {
    JSONObject jsonResponse = null;
    int retryCount = 0;
    try {
        retryCount = Integer.parseInt(sdcRetryCount);
    } catch (NumberFormatException e) {
        retryCount = DEFAULT_ACTIVATE_RETRY_COUNT;
    }
    // loop through the serviceModelVersionId, and send request SDC
    for (ServiceModelList serviceModelList : serviceModelVersionIdList) {
        String serviceModelVersionId = serviceModelList.getServiceModelVersionId();
        String recoveryAction = serviceModelList.getRecoveryAction().toString().toUpperCase();
        // should insert 1 row
        OperationalEnvServiceModelStatus serviceModelStatus = dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId, DISTRIBUTION_STATUS_SENT, recoveryAction, retryCount, workloadContext, vnfOperationalEnvironmentId);
        client.save(serviceModelStatus);
        String distributionId = "";
        jsonResponse = sdcClientHelper.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext);
        String statusCode = jsonResponse.get("statusCode").toString();
        if (statusCode.equals(String.valueOf(Response.Status.ACCEPTED.getStatusCode()))) {
            distributionId = jsonResponse.get("distributionId").toString();
            // should insert 1 row
            OperationalEnvDistributionStatus distStatus = dbHelper.insertRecordToOperationalEnvDistributionStatus(distributionId, operationalEnvironmentId, serviceModelVersionId, requestId, DISTRIBUTION_STATUS_SENT, "");
            client.save(distStatus);
        } else {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
            String dbErrorMessage = " Failure calling SDC: statusCode: " + statusCode + "; messageId: " + jsonResponse.get("messageId") + "; message: " + jsonResponse.get("message");
            requestDb.updateInfraFailureCompletion(dbErrorMessage, requestId, operationalEnvironmentId);
            throw new ValidateException.Builder(dbErrorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        }
    }
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) JSONObject(org.json.JSONObject) OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)

Aggregations

ServiceModelList (org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList)5 JSONObject (org.json.JSONObject)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 BaseTest (org.onap.so.apihandlerinfra.BaseTest)3 AAIFluentTypeBuilder (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder)2 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)2 OperationalEnvironment (org.onap.aai.domain.yang.OperationalEnvironment)1 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)1 Relationships (org.onap.aaiclient.client.aai.entities.Relationships)1 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)1 Manifest (org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest)1 RequestDetails (org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails)1 RequestParameters (org.onap.so.apihandlerinfra.tenantisolationbeans.RequestParameters)1 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)1 OperationalEnvDistributionStatus (org.onap.so.db.request.beans.OperationalEnvDistributionStatus)1 OperationalEnvServiceModelStatus (org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)1