From: raviteja.karumuri Date: Tue, 31 Jan 2023 11:13:01 +0000 (+0000) Subject: [SO] Pending Create changes for SO-API and BPMN-INFRA to support CNF's through ASD X-Git-Tag: 1.12.1~11 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=so.git;a=commitdiff_plain;h=fa660d2d8a9b2b6f3190bf5c3c26dcf4fa15c146 [SO] Pending Create changes for SO-API and BPMN-INFRA to support CNF's through ASD Issue-ID: SO-4069 Signed-off-by: raviteja.karumuri Change-Id: I91e6d2dfc3ce84f7fe496b9b87c2a4ac6f521673 --- diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn index a94e6aa2ca..6e1996acd8 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn @@ -6,13 +6,13 @@ - Flow_1xcu3yl + Flow_149m8py - + SequenceFlow_016sgof Flow_1s7gtbc - + Flow_1s7gtbc Flow_1luy180 @@ -22,52 +22,72 @@ Flow_0xq0uda Flow_1xcu3yl - + Flow_1luy180 Flow_0xq0uda - + + + + + + + + + + + Flow_1xcu3yl + Flow_149m8py + + + + + + + + + + - - + + - - + + - - - - - - + + - - - + + + - + - + - - - - + - + - + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn new file mode 100644 index 0000000000..be683b9ca6 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn @@ -0,0 +1,160 @@ + + + + + SequenceFlow_1x3tbl0 + + + SequenceFlow_1543qy7 + + + SequenceFlow_1x3tbl0 + SequenceFlow_1v4yr3f + + SequenceFlow_0s1plu9 + + + SequenceFlow_153a3kp + SequenceFlow_1vmxw9g + SequenceFlow_0is7myf + + + SequenceFlow_1vmxw9g + SequenceFlow_0etw572 + + PT15S + + + + SequenceFlow_0is7myf + + + + + SequenceFlow_0etw572 + SequenceFlow_0s1plu9 + SequenceFlow_153a3kp + + + + ${MonitorCnfmCreateJobTask.hasOperationFinished(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))} + + + + + SequenceFlow_0bcgtzj + + + + SequenceFlow_1i1o9sh + + PT3H + + + + + + + SequenceFlow_1i1o9sh + SequenceFlow_0bcgtzj + + + + SequenceFlow_1v4yr3f + SequenceFlow_1543qy7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java index ab20a08e74..105cca28c8 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java @@ -26,6 +26,10 @@ import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_R import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_ID_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_NAME_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.Optional; import org.apache.groovy.util.Maps; import org.onap.logging.filter.base.ONAPComponents; @@ -37,6 +41,7 @@ import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.cnfm.lcm.model.AsInstance; import org.onap.so.cnfm.lcm.model.CreateAsRequest; import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; +import org.onap.so.cnfm.lcm.model.AsInfoModificationRequestDeploymentItems; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; @@ -57,6 +62,7 @@ import org.springframework.stereotype.Component; public class CnfInstantiateTask { private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject"; private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest"; + private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; private static final String AS_INSTANCE_ID = "asInstanceid"; private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class); private final ExceptionBuilder exceptionUtil; @@ -80,9 +86,9 @@ public class CnfInstantiateTask { final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails(); LOGGER.debug("RequestDetails: {}", requestDetails); - if (isNull(requestDetails) && isNull(requestDetails.getModelInfo()) - && isNull(requestDetails.getRequestInfo()) && isNull(requestDetails.getCloudConfiguration()) - && isNull(generalBuildingBlock)) { + if (isNull(requestDetails) || isNull(requestDetails.getModelInfo()) + || isNull(requestDetails.getRequestInfo()) + || isNull(requestDetails.getCloudConfiguration()) && isNull(generalBuildingBlock)) { LOGGER.error("Missing Mandatory attribute from RequestDetails: {} or GeneralBuildingBlock: {}", requestDetails, generalBuildingBlock); exceptionUtil.buildAndThrowWorkflowException(execution, 2000, @@ -137,9 +143,31 @@ public class CnfInstantiateTask { public void createAsInstanceRequest(final BuildingBlockExecution execution) { try { LOGGER.debug("Executing createAsInstanceRequest task ..."); - + final ExecuteBuildingBlock executeBuildingBlock = + (ExecuteBuildingBlock) execution.getVariable("buildingBlock"); + final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails(); final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest(); - + if (requestDetails != null && requestDetails.getRequestParameters() != null) { + List> userParams = requestDetails.getRequestParameters().getUserParams(); + if (userParams != null && !userParams.isEmpty()) { + List deploymentItems = new ArrayList(); + List deploymentItemsReq = new ArrayList(); + for (Map userParam : userParams) { + if (userParam.containsKey("deploymentItems")) { + deploymentItems = (ArrayList) userParam.get("deploymentItems"); + break; + } + } + for (Object deploymentItem : deploymentItems) { + Map deploymentItemMap = (Map) deploymentItem; + AsInfoModificationRequestDeploymentItems item = new AsInfoModificationRequestDeploymentItems(); + item.setDeploymentItemsId(deploymentItemMap.get("deploymentItemsId").toString()); + item.setLifecycleParameterKeyValues(deploymentItemMap.get("lifecycleParameterKeyValues")); + deploymentItemsReq.add(item); + } + instantiateAsRequest.setDeploymentItems(deploymentItemsReq); + } + } LOGGER.debug("Adding InstantiateAsRequest to execution {}", instantiateAsRequest); execution.setVariable(INSTANTIATE_AS_REQUEST_OBJECT, instantiateAsRequest); @@ -155,9 +183,10 @@ public class CnfInstantiateTask { try { final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT); final String asInstanceId = execution.getVariable(AS_INSTANCE_ID); - cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId); + Optional cnf_status_check_url = + cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId); + execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnf_status_check_url.get()); LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId); - } catch (final Exception exception) { LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", exception); exceptionUtil.buildAndThrowWorkflowException(execution, 2005, exception); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java index 5e9112f3e0..cb6a96c152 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java @@ -19,8 +19,10 @@ */ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; +import java.net.URI; import java.util.Optional; import org.onap.so.cnfm.lcm.model.AsInstance; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc; import org.onap.so.cnfm.lcm.model.CreateAsRequest; import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; @@ -34,6 +36,7 @@ public interface CnfmHttpServiceProvider { Optional invokeCreateAsRequest(final CreateAsRequest createAsRequest); - void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId); + Optional invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId); + Optional getInstantiateOperationJobStatus(final String url); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java index 3f78896b5d..1035f4314e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java @@ -17,13 +17,15 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; import static org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks.CnfmHttpServiceConfiguration.CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN; +import java.net.URI; import java.util.Optional; import org.onap.so.cnfm.lcm.model.AsInstance; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc; import org.onap.so.cnfm.lcm.model.CreateAsRequest; +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; import org.onap.so.rest.exceptions.HttpResouceNotFoundException; import org.onap.so.rest.exceptions.InvalidRestRequestException; import org.onap.so.rest.exceptions.RestProcessingException; @@ -35,7 +37,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; @Service public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { @@ -83,24 +84,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { } @Override - public void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { + public Optional invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { try { final String url = cnfmUrlProvider.getInstantiateAsRequestUrl(asInstanceId); final ResponseEntity response = httpServiceProvider.postHttpRequest(instantiateAsRequest, url, AsInstance.class); - final HttpStatus httpStatus = response.getStatusCode(); - if (httpStatus.is2xxSuccessful() && !(response.hasBody())) { - LOGGER.error("Response received without body: {}", response); + if (httpStatus.is2xxSuccessful()) { + URI statusUri = response.getHeaders().getLocation(); + if (statusUri == null) { + LOGGER.error("Received response without status URL for instance ID: {}", asInstanceId); + return Optional.empty(); + } + return Optional.of(statusUri); } LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); + return Optional.empty(); } catch (final RestProcessingException | InvalidRestRequestException | HttpResouceNotFoundException httpInvocationException) { LOGGER.error("Unexpected error while processing instantiation request", httpInvocationException); + return Optional.empty(); } } + @Override + public Optional getInstantiateOperationJobStatus(final String url) { + try { + final ResponseEntity response = httpServiceProvider.getHttpResponse(url, AsLcmOpOcc.class); + + final HttpStatus httpStatus = response.getStatusCode(); + + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: ", url, httpStatus.value()); + return Optional.empty(); + } + + if (!response.hasBody()) { + LOGGER.error("CNFM status response recieved without body: {}", response); + return Optional.empty(); + } + return Optional.of(response.getBody()); + } catch (final RestProcessingException | InvalidRestRequestException + | HttpResouceNotFoundException httpInvocationException) { + LOGGER.error("Unexpected error while processing job request", httpInvocationException); + throw httpInvocationException; + } + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java new file mode 100644 index 0000000000..06b44e4512 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; + +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_CNF_STATUS_RESPONSE_PARAM_NAME; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME; +import java.net.URI; +import java.util.Optional; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.collect.ImmutableSet; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum; + + +/** + * @author sagar.shetty@est.tech + */ +@Component +public class MonitorCnfmCreateJobTask { + + public static final ImmutableSet OPERATION_FINISHED_STATES = + ImmutableSet.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK); + private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmCreateJobTask.class); + protected final ExceptionBuilder exceptionUtil; + private final CnfmHttpServiceProvider cnfmHttpServiceProvider; + + @Autowired + public MonitorCnfmCreateJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, + final ExceptionBuilder exceptionUtil) { + this.cnfmHttpServiceProvider = cnfmHttpServiceProvider; + this.exceptionUtil = exceptionUtil; + } + + /** + * Get the current operation status of instantiation job + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void getCurrentOperationStatus(final BuildingBlockExecution execution) { + try { + LOGGER.debug("Executing getCurrentOperationStatus ..."); + final URI operation_status_url = execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL); + LOGGER.debug("Executing getCurrentOperationStatus for CNF... :{}", operation_status_url.toString()); + final Optional instantiateOperationJobStatus = + cnfmHttpServiceProvider.getInstantiateOperationJobStatus(operation_status_url.toString()); + if (instantiateOperationJobStatus.isPresent()) { + final AsLcmOpOcc asLcmOpOccResponse = instantiateOperationJobStatus.get(); + if (asLcmOpOccResponse.getOperationState() != null) { + final OperationStateEnum operationStatus = asLcmOpOccResponse.getOperationState(); + LOGGER.debug("Operation {} with {} and operation retrieval status : {}", asLcmOpOccResponse.getId(), + operationStatus, asLcmOpOccResponse.getOperationState()); + execution.setVariable(OPERATION_STATUS_PARAM_NAME, asLcmOpOccResponse.getOperationState()); + } + + LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}", + asLcmOpOccResponse.getId(), asLcmOpOccResponse.getOperationState()); + } + execution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, instantiateOperationJobStatus.get()); + LOGGER.debug("Finished executing getCurrentOperationStatus for CNF..."); + } catch (final Exception exception) { + final String message = "Unable to invoke get current Operation status"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1209, message); + + } + } + + /** + * Log and throw exception on timeout for job status + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void timeOutLogFailue(final BuildingBlockExecution execution) { + final String message = "CNF Instantiation operation time out"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message); + } + + /** + * Check the final status of instantiation throw exception if not completed successfully + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) { + LOGGER.debug("Executing CNF checkIfOperationWasSuccessful ..."); + final OperationStateEnum operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); + final AsLcmOpOcc cnfInstantiateStautusResponse = execution.getVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME); + if (operationStatusOption == null) { + final String message = "Unable to instantiate CNF jobId: " + + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null") + + "Unable to retrieve OperationStatus"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message); + } else { + final OperationStateEnum operationStatus = operationStatusOption; + if (operationStatus != OperationStateEnum.COMPLETED) { + final String message = "Unable to instantiate jobId: " + + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null") + + " OperationStatus: " + operationStatus; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message); + } + LOGGER.debug("Successfully completed CNF instatiation of job status {}", cnfInstantiateStautusResponse); + } + } + + /** + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + * @return boolean to indicate whether job has competed or not + */ + public boolean hasOperationFinished(final BuildingBlockExecution execution) { + LOGGER.debug("Executing hasOperationFinished ..."); + + final OperationStateEnum operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); + if (operationStatusOption != null) { + return OPERATION_FINISHED_STATES.contains(operationStatusOption); + } + LOGGER.debug("OperationStatus is not present yet... "); + LOGGER.debug("Finished executing hasOperationFinished ..."); + return false; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java index 6afd7799f8..37d6221b77 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ @@ -33,6 +33,7 @@ public class Constants { public static final String CREATE_VNF_REQUEST_PARAM_NAME = "createVnfRequest"; public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; + public static final String CREATE_CNF_STATUS_RESPONSE_PARAM_NAME = "createCnfStatusResponse"; public static final String INPUT_PARAMETER = "inputParameter"; public static final String DELETE_VNF_RESPONSE_PARAM_NAME = "deleteVnfResponse"; public static final String DELETE_VNF_NODE_STATUS = "deleteVnfNodeStatus"; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java new file mode 100644 index 0000000000..f4d8bb8439 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY; +import java.net.URI; +import java.util.Optional; +import java.util.Collections; +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.cnfm.lcm.model.AsInstance; +import org.onap.so.cnfm.lcm.model.CreateAsRequest; +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; + + +/** + * @author raviteja.kaumuri@est.tech + */ +public class CnfInstantiateTaskTest extends BaseTaskTest { + + private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject"; + private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest"; + private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; + private static final String MONITOR_JOB_NAME = "MonitorJobName"; + private static final String MODEL_INSTANCE_NAME = "instanceTest"; + private static final String AS_INSTANCE_ID = "asInstanceid"; + private static final String CLOUD_OWNER = "CloudOwner"; + private static final String LCP_CLOUD_REGION_ID = "RegionOne"; + private static final String CNF_ID = UUID.randomUUID().toString(); + private static final String CNF_NAME = "CNF_NAME"; + private static final String JOB_ID = UUID.randomUUID().toString(); + + @Mock + private CnfmHttpServiceProvider mockedCnfmHttpServiceProvider; + + private final BuildingBlockExecution stubbedExecution = new StubbedBuildingBlockExecution(); + + @Test + public void testCreateCreateASRequest_withValidValues_storesRequestInExecution() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + stubbedExecution.setVariable(INPUT_PARAMETER, + new InputParameter(Collections.emptyMap(), Collections.emptyList())); + + objUnderTest.createCreateAsRequest(stubbedExecution); + + final CreateAsRequest actual = stubbedExecution.getVariable(CREATE_AS_REQUEST_OBJECT); + assertNotNull(actual); + assertEquals(MODEL_INSTANCE_NAME, actual.getAsInstanceName()); + + assertEquals(CLOUD_OWNER, actual.getAdditionalParams().get(CLOUD_OWNER_PARAM_KEY).toString()); + assertEquals(LCP_CLOUD_REGION_ID, actual.getAdditionalParams().get(CLOUD_REGION_PARAM_KEY).toString()); + assertEquals(StubbedBuildingBlockExecution.getTenantId(), + actual.getAdditionalParams().get(TENANT_ID_PARAM_KEY).toString()); + } + + @Test + public void testCreateCreateASRequest_ForBBThrowsException_exceptionBuilderCalled() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + + final BuildingBlockExecution stubbedExecutionNoReqDetails = new StubbedBuildingBlockExecution(); + final ExecuteBuildingBlock executeBuildingBlock = stubbedExecutionNoReqDetails.getVariable("buildingBlock"); + executeBuildingBlock.setRequestDetails(null); + + doThrow(BpmnError.class).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), + eq(2000), anyString(), any()); + objUnderTest.createCreateAsRequest(stubbedExecutionNoReqDetails); + final CreateAsRequest actual = stubbedExecutionNoReqDetails.getVariable(CREATE_AS_REQUEST_OBJECT); + + assertNull(actual); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2000), anyString(), + any()); + + } + + @Test + public void invokeCnfmWithCreateAsRequest_validValues_storesResponseInExecution() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + stubbedExecution.setVariable(CREATE_AS_REQUEST_OBJECT, new CreateAsRequest()); + + when(mockedCnfmHttpServiceProvider.invokeCreateAsRequest(any(CreateAsRequest.class))) + .thenReturn(getAsInstance()); + + objUnderTest.invokeCnfmWithCreateAsRequest(stubbedExecution); + + assertEquals(JOB_ID, stubbedExecution.getVariable(AS_INSTANCE_ID)); + } + + @Test + public void invokeCnfmWithCreateAsRequest_ForBBThrowsException_exceptionBuilderCalled() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + stubbedExecution.setVariable(CREATE_AS_REQUEST_OBJECT, new CreateAsRequest()); + + when(mockedCnfmHttpServiceProvider.invokeCreateAsRequest(any(CreateAsRequest.class))) + .thenReturn(Optional.empty()); + doThrow(BpmnError.class).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), + eq(2003), anyString(), any()); + + objUnderTest.invokeCnfmWithCreateAsRequest(stubbedExecution); + + assertNull(stubbedExecution.getVariable(AS_INSTANCE_ID)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2003), anyString(), + any()); + + } + + @Test + public void testcreateAsInstanceRequest_withValidValues_storesRequestInExecution() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + + objUnderTest.createAsInstanceRequest(stubbedExecution); + + final InstantiateAsRequest actual = stubbedExecution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT); + assertNotNull(actual); + assertNotNull(actual.getDeploymentItems()); + } + + private Optional getAsInstance() { + final AsInstance response = new AsInstance(); + response.setAsInstanceid(JOB_ID); + return Optional.of(response); + } + + private GenericVnf getGenericVnf() { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(CNF_ID); + genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); + genericVnf.setVnfName(CNF_NAME); + return genericVnf; + } + + private ModelInfoGenericVnf getModelInfoGenericVnf() { + final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); + return modelInfoGenericVnf; + } + + private CnfInstantiateTask getCnfInstantiateTask() { + return new CnfInstantiateTask(mockedCnfmHttpServiceProvider, exceptionUtil); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java new file mode 100644 index 0000000000..3b16feda18 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.jetbrains.kotlin.codegen.intrinsics.LateinitIsInitialized; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.serviceinstancebeans.CloudConfiguration; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.RequestInfo; +import org.onap.so.serviceinstancebeans.RequestParameters; + +/** + * + * @author Raviteja Karumuri (raviteja.karumuri@est.tech) + * + */ +public class StubbedBuildingBlockExecution implements BuildingBlockExecution { + + private static final String CLOUD_OWNER = "CloudOwner"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String LCP_CLOUD_REGION_ID = "RegionOne"; + private static final String MODEL_VERSION_ID = UUID.randomUUID().toString(); + private static final String SERVICE_INSTANCE_ID = UUID.randomUUID().toString(); + private static final String DEPLOYMENT_ID = UUID.randomUUID().toString(); + private static final String SERVICE_INSTANCE_NAME = "test"; + private static final String INSTANCE_NAME = "instanceTest"; + private static final String TENANT_ID = UUID.randomUUID().toString(); + private final Map execution = new HashMap<>(); + private final GeneralBuildingBlock generalBuildingBlock; + + StubbedBuildingBlockExecution() { + + generalBuildingBlock = getGeneralBuildingBlockValue(); + setVariable(BUILDING_BLOCK, getExecuteBuildingBlock()); + } + + @Override + public GeneralBuildingBlock getGeneralBuildingBlock() { + return generalBuildingBlock; + } + + @SuppressWarnings("unchecked") + @Override + public T getVariable(final String key) { + return (T) execution.get(key); + } + + @Override + public T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { + return null; + } + + @Override + public void setVariable(final String key, final Serializable value) { + execution.put(key, value); + } + + @Override + public Map getLookupMap() { + return Collections.emptyMap(); + } + + @Override + public String getFlowToBeCalled() { + return null; + } + + @Override + public int getCurrentSequence() { + return 0; + } + + public static String getTenantId() { + return TENANT_ID; + } + + private GeneralBuildingBlock getGeneralBuildingBlockValue() { + final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); + buildingBlock.setServiceInstance(getServiceInstance()); + return buildingBlock; + } + + private ExecuteBuildingBlock getExecuteBuildingBlock() { + ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + executeBuildingBlock.setRequestDetails(getRequestDetails()); + return executeBuildingBlock; + } + + private RequestDetails getRequestDetails() { + RequestDetails requestDetails = new RequestDetails(); + requestDetails.setModelInfo(getModelInfo()); + requestDetails.setCloudConfiguration(getCloudConfiguration()); + requestDetails.setRequestInfo(getRequestInfo()); + requestDetails.setRequestParameters(getRequestParameters()); + return requestDetails; + } + + private ModelInfo getModelInfo() { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId(MODEL_VERSION_ID); + return modelInfo; + } + + private ServiceInstance getServiceInstance() { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID); + serviceInstance.setServiceInstanceName(SERVICE_INSTANCE_NAME); + return serviceInstance; + } + + private RequestInfo getRequestInfo() { + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setInstanceName(INSTANCE_NAME); + return requestInfo; + } + + private RequestParameters getRequestParameters() { + Map deploymentItemMap = new HashMap<>(); + deploymentItemMap.put("deploymentItemsId", DEPLOYMENT_ID); + deploymentItemMap.put("lifecycleParameterKeyValues", new Object()); + List deploymentItems = new ArrayList<>(); + deploymentItems.add(deploymentItemMap); + Map userParamsMap = new HashMap<>(); + userParamsMap.put("deploymentItems", deploymentItems); + userParamsMap.put("namespace", "Namespace"); + List> userParams = new ArrayList<>(); + userParams.add(userParamsMap); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(userParams); + return requestParameters; + } + + private CloudConfiguration getCloudConfiguration() { + final CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setCloudOwner(CLOUD_OWNER); + cloudConfiguration.setLcpCloudRegionId(LCP_CLOUD_REGION_ID); + cloudConfiguration.setTenantId(TENANT_ID); + return cloudConfiguration; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index b358f26cb2..cb48d007b5 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -1131,6 +1131,34 @@ public class ServiceInstancesTest extends BaseTest { assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } + @Test + public void createCnfInstanceNoALaCarte() throws IOException { + + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("serviceCnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + // expected response + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/cnfs"; + ResponseEntity response = + sendRequest(inputStream("/CnfWithServiceRelatedInstance.json"), uri, HttpMethod.POST, headers); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + assertTrue(response.getBody().contains("1882939")); + } + @Test public void createVfModuleInstance() throws IOException { wireMockServer.stubFor(get(urlMatching( diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/CnfWithServiceRelatedInstance.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/CnfWithServiceRelatedInstance.json new file mode 100644 index 0000000000..e23c18a866 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/CnfWithServiceRelatedInstance.json @@ -0,0 +1,47 @@ +{ + "requestDetails": { + "modelInfo": { + "modelType": "cnf", + "modelInvariantId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe", + "modelName": "cnf..base..module-0", + "modelVersion": "1.0", + "modelCustomizationName": "test" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "requestInfo": { + "instanceName": "CNFTEST-1", + "source": "VID", + "suppressRollback": true, + "requestorId": "xxxxxx", + "productFamilyId": "FamilyID" + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "ff305d54-75b4-431b-adb2-eb6b9e5ff000", + "modelInfo": { + "modelType": "service", + "modelInvariantId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "modelVersionId": "5df8b6de-2083-11e7-93ae-92361f002672", + "modelName": "cnf", + "modelVersion": "1.0", + "modelCustomizationId": "f78914d9-423b-11e7-93f8-0050569a7967" + } + } + } + ], + "requestParameters": { + "userParams": [] + }, + "platform": { + "platformName": "platformName" + }, + "lineOfBusiness": { + "lineOfBusinessName": "lobName" + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/serviceCnf_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/serviceCnf_Response.json new file mode 100644 index 0000000000..6df019b98f --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/serviceCnf_Response.json @@ -0,0 +1,25 @@ +{ + "modelName": "Infra_v10_Service", + "description": "MSO aLaCarte CNF", + "modelUUID": "5df8b6de-2083-11e7-93ae-92361f002672", + "modelInvariantUUID": "9647dfc4-2083-11e7-93ae-92361f002671", + "created": "2023-02-08 12:45:39.000", + "modelVersion": "2.0", + "serviceType": "NA", + "serviceRole": "NA", + "environmentContext": "Luna", + "workloadContext": "Oxygen", + "category": null, + "_links": { + "self": { + "href": "http://localhost:8090/service/5df8b6de-2083-11e7-93ae-92361f002672" + }, + "service": { + "href": "http://localhost:8090/service/5df8b6de-2083-11e7-93ae-92361f002672{?projection}", + "templated": true + }, + "vnfCustomizations": { + "href": "http://localhost:8090/service/5df8b6de-2083-11e7-93ae-92361f002672/vnfCustomizations" + } + } +}