From 35791e0e356a5bd40f9e96255df184778a686fd2 Mon Sep 17 00:00:00 2001 From: SagarS Date: Tue, 12 Jul 2022 14:18:26 +0100 Subject: [CNFM] Adding sattus monitoring changes Change-Id: I35a1441a61e858f5724ea3dcc884ad9bc3a1c8b1 Signed-off-by: SagarS Issue-ID: SO-3950 --- .../subprocess/BuildingBlock/CnfInstantiateBB.bpmn | 72 ++++++---- .../subprocess/BuildingBlock/MonitorCnfmJob.bpmn | 160 +++++++++++++++++++++ .../adapter/cnfm/tasks/CnfInstantiateTask.java | 8 +- .../cnfm/tasks/CnfmHttpServiceProvider.java | 6 +- .../cnfm/tasks/CnfmHttpServiceProviderImpl.java | 43 +++++- .../cnfm/tasks/MonitorCnfmCreateJobTask.java | 152 ++++++++++++++++++++ .../adapter/vnfm/tasks/Constants.java | 1 + 7 files changed, 407 insertions(+), 35 deletions(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java 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 3caa2e6e4e..510cee700c 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 @@ -25,6 +25,8 @@ 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.Optional; import org.apache.groovy.util.Maps; import org.onap.logging.filter.base.ONAPComponents; @@ -55,6 +57,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; @@ -153,9 +156,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, 2004, 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 abf3508fe6..556d1a172b 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,11 @@ */ 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; @@ -33,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 bb789607e4..709c5c5758 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 @@ -20,9 +20,14 @@ 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; @@ -34,7 +39,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 { @@ -82,27 +86,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()) { - if (!response.hasBody()) { - LOGGER.error("Received response without body: {}", response); + 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..323141365d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Ericsson. All rights reserved. + * ================================================================================ + * Copyright (C) 2019 Samsung + * ================================================================================ + * 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.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse; +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 { + + private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; + public static final ImmutableSet OPERATION_FINISHED_STATES = + ImmutableSet.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK); + 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..326e764321 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 @@ -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"; -- cgit 1.2.3-korg