summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main/java/org
diff options
context:
space:
mode:
authorraviteja.karumuri <raviteja.karumuri@est.tech>2022-07-13 13:17:49 +0100
committerraviteja.karumuri <raviteja.karumuri@est.tech>2023-02-17 16:59:11 +0000
commitfb516859f920197eba4cbc1f5b82279f3e3753c6 (patch)
treeae72025fc67b49cfae46d892936ceb6449b5dcc8 /bpmn/so-bpmn-tasks/src/main/java/org
parentd0493f954a48021662b5b6d3ba45b262750690c9 (diff)
[SO] SO changes to support Delete AS
Issue-ID: SO-4084 Signed-off-by: raviteja.karumuri <raviteja.karumuri@est.tech> Change-Id: Ib75076bdd98291b48149a9ad859fd383a551cd45
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java123
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java7
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java55
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java9
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java (renamed from bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java)98
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java2
7 files changed, 251 insertions, 61 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
new file mode 100644
index 0000000000..ce0b3000e0
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
@@ -0,0 +1,123 @@
+/*-
+ * ============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.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import org.camunda.bpm.engine.delegate.BpmnError;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class performs CNF Delete
+ *
+ * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
+ */
+@Component
+public class CnfDeleteTask {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
+ private final ExceptionBuilder exceptionUtil;
+ private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
+ private final ExtractPojosForBB extractPojosForBB;
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
+ private static final String AS_INSTANCE_ID = "asInstanceid";
+ private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
+
+ @Autowired
+ public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil,
+ ExtractPojosForBB extractPojosForBB) {
+ this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
+ this.exceptionUtil = exceptionUtil;
+ this.extractPojosForBB = extractPojosForBB;
+ }
+
+ public void createTerminateAsRequest(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing createTerminateAsRequest task ...");
+
+ final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
+ terminateAsRequest.setTerminationType(TerminateAsRequest.TerminationTypeEnum.GRACEFUL);
+ terminateAsRequest.setGracefulTerminationTimeout(0);
+ terminateAsRequest.setAdditionalParams(new HashMap<>());
+
+ LOGGER.debug("Adding TerminateAsRequest to execution {}", terminateAsRequest);
+
+ execution.setVariable(TERMINATE_AS_REQUEST_OBJECT, terminateAsRequest);
+ LOGGER.debug("Finished executing terminateAsRequest task ...");
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to create TerminateAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
+ }
+ }
+
+ public void invokeCnfmToTerminateAsInstance(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing TerminateAsInstance task ...");
+
+ final TerminateAsRequest terminateAsRequest = execution.getVariable(TERMINATE_AS_REQUEST_OBJECT);
+ final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
+ final String asInstanceId = vnf.getVnfId();
+
+ Optional<URI> terminateStatusCheck =
+ cnfmHttpServiceProvider.invokeTerminateAsRequest(asInstanceId, terminateAsRequest);
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL,
+ terminateStatusCheck.orElseThrow(() -> new NoSuchElementException("Status check url Not found")));
+ execution.setVariable(MONITOR_JOB_NAME, "Terminate");
+ LOGGER.debug("Successfully invoked CNFM terminate AS request: {}", asInstanceId);
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM TerminateAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2002, exception);
+ }
+ }
+
+ public void invokeCnfmToDeleteAsInstance(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing DeleteAsInstance task ...");
+
+ final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
+ final String asInstanceId = vnf.getVnfId();
+
+ Optional<Boolean> response = cnfmHttpServiceProvider.invokeDeleteAsRequest(asInstanceId);
+ if (Boolean.TRUE.equals(response
+ .orElseThrow(() -> new BpmnError("Unable to complete DeleteAsRequest of ID: " + asInstanceId)))) {
+ LOGGER.debug("Successfully invoked CNFM delete AS request with ID: {}", asInstanceId);
+ }
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM DeleteAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2003, exception);
+ }
+ }
+}
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 105cca28c8..c7f3310391 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
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
import static java.util.Objects.isNull;
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.RESOURCE_ID_KEY;
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;
@@ -30,6 +31,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Optional;
import org.apache.groovy.util.Maps;
import org.onap.logging.filter.base.ONAPComponents;
@@ -63,6 +65,7 @@ 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 MONITOR_JOB_NAME = "MonitorJobName";
private static final String AS_INSTANCE_ID = "asInstanceid";
private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
private final ExceptionBuilder exceptionUtil;
@@ -98,6 +101,7 @@ public class CnfInstantiateTask {
final ModelInfo modelInfo = requestDetails.getModelInfo();
final CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
final ServiceInstance serviceInstance = generalBuildingBlock.getServiceInstance();
+ final String resourceId = executeBuildingBlock.getResourceId();
final CreateAsRequest createAsRequest = new CreateAsRequest().asdId(modelInfo.getModelVersionId())
.asInstanceName(requestDetails.getRequestInfo().getInstanceName())
@@ -105,7 +109,7 @@ public class CnfInstantiateTask {
CLOUD_REGION_PARAM_KEY, cloudConfiguration.getLcpCloudRegionId(), TENANT_ID_PARAM_KEY,
cloudConfiguration.getTenantId(), SERVICE_INSTANCE_ID_PARAM_KEY,
serviceInstance.getServiceInstanceId(), SERVICE_INSTANCE_NAME_PARAM_KEY,
- serviceInstance.getServiceInstanceName()));
+ serviceInstance.getServiceInstanceName(), RESOURCE_ID_KEY, resourceId));
LOGGER.debug("Adding CreateAsRequest to execution {}", createAsRequest);
@@ -130,7 +134,8 @@ public class CnfInstantiateTask {
"Unable to invoke CNFM for CreateAsRequest", ONAPComponents.SO);
}
- final AsInstance asInstance = optional.orElseThrow();
+ final AsInstance asInstance =
+ optional.orElseThrow(() -> new NoSuchElementException("AsInstance object is empty"));
execution.setVariable(AS_INSTANCE_ID, asInstance.getAsInstanceid());
LOGGER.debug("Successfully invoked CNFM response: {}", asInstance);
@@ -150,8 +155,8 @@ public class CnfInstantiateTask {
if (requestDetails != null && requestDetails.getRequestParameters() != null) {
List<Map<String, Object>> userParams = requestDetails.getRequestParameters().getUserParams();
if (userParams != null && !userParams.isEmpty()) {
- List deploymentItems = new ArrayList<Object>();
- List deploymentItemsReq = new ArrayList<AsInfoModificationRequestDeploymentItems>();
+ List<Object> deploymentItems = new ArrayList<>();
+ List<AsInfoModificationRequestDeploymentItems> deploymentItemsReq = new ArrayList<>();
for (Map<String, Object> userParam : userParams) {
if (userParam.containsKey("deploymentItems")) {
deploymentItems = (ArrayList<Object>) userParam.get("deploymentItems");
@@ -183,9 +188,10 @@ public class CnfInstantiateTask {
try {
final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT);
final String asInstanceId = execution.getVariable(AS_INSTANCE_ID);
- Optional<URI> cnf_status_check_url =
+ Optional<URI> cnfStatusCheckURL =
cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId);
- execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnf_status_check_url.get());
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnfStatusCheckURL.orElseThrow());
+ execution.setVariable(MONITOR_JOB_NAME, "Instantiate");
LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId);
} catch (final Exception exception) {
LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", 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 cb6a96c152..5b8ab355a0 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
@@ -25,6 +25,7 @@ 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.cnfm.lcm.model.TerminateAsRequest;
/**
* @author Sagar Shetty (sagar.shetty@est.tech)
@@ -38,5 +39,9 @@ public interface CnfmHttpServiceProvider {
Optional<URI> invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId);
- Optional<AsLcmOpOcc> getInstantiateOperationJobStatus(final String url);
+ Optional<AsLcmOpOcc> getOperationJobStatus(final String url);
+
+ Optional<Boolean> invokeDeleteAsRequest(final String asInstanceId);
+
+ Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest);
}
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 1035f4314e..0edeb4089c 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
@@ -26,6 +26,7 @@ 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.cnfm.lcm.model.TerminateAsRequest;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
@@ -111,14 +112,14 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
}
@Override
- public Optional<AsLcmOpOcc> getInstantiateOperationJobStatus(final String url) {
+ public Optional<AsLcmOpOcc> getOperationJobStatus(final String url) {
try {
final ResponseEntity<AsLcmOpOcc> 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());
+ LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: {}", url, httpStatus.value());
return Optional.empty();
}
@@ -134,4 +135,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
}
}
+ @Override
+ public Optional<Boolean> invokeDeleteAsRequest(String asInstanceId) {
+ try {
+
+ final String url = cnfmUrlProvider.getDeleteAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.deleteHttpRequest(url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (!(httpStatus.is2xxSuccessful())) {
+ LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value());
+ return Optional.empty();
+ }
+ return Optional.of(Boolean.TRUE);
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing delete request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ public Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest) {
+ try {
+
+ final String url = cnfmUrlProvider.getTerminateAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM to terminate by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.postHttpRequest(terminateAsRequest, url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (httpStatus.is2xxSuccessful()) {
+ URI statusUri = response.getHeaders().getLocation();
+ if (statusUri == null) {
+ LOGGER.error("Received response without status URL while terminating of instance with ID: {}",
+ asInstanceId);
+ return Optional.empty();
+ }
+ return Optional.of(statusUri);
+ }
+ LOGGER.error("Unable to invoke HTTP DELETE while terminating by using URL: {}, Response Code: {}", url,
+ httpStatus.value());
+ return Optional.empty();
+
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing terminate request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
index cef2f3f818..d7247b40d0 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
@@ -51,4 +51,13 @@ public class CnfmUrlProvider {
.pathSegment("instantiate").build().toString();
}
+ public String getDeleteAsRequestUrl(String asInstanceId) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId).build()
+ .toString();
+ }
+
+ public String getTerminateAsRequestUrl(String asInstanceId) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId)
+ .pathSegment("terminate").build().toString();
+ }
}
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/MonitorCnfmJobTask.java
index eb1cd1c1b6..f84120e558 100644
--- 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/MonitorCnfmJobTask.java
@@ -18,73 +18,75 @@
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.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.logging.filter.base.ONAPComponents;
+import java.util.Set;
+import org.camunda.bpm.engine.delegate.BpmnError;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum;
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
+ * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
*/
@Component
-public class MonitorCnfmCreateJobTask {
+public class MonitorCnfmJobTask {
- public static final ImmutableSet<OperationStateEnum> 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);
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
+ public static final Set<OperationStateEnum> OPERATION_FINISHED_STATES =
+ Set.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK);
+ private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmJobTask.class);
protected final ExceptionBuilder exceptionUtil;
private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
@Autowired
- public MonitorCnfmCreateJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider,
+ public MonitorCnfmJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider,
final ExceptionBuilder exceptionUtil) {
this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
this.exceptionUtil = exceptionUtil;
}
/**
- * Get the current operation status of instantiation job
- *
+ * Get the current operation status of cnfm job
+ *
* @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
*/
public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
try {
LOGGER.debug("Executing getCurrentOperationStatus ...");
- final URI operationStatusURL = execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL);
+ final Optional<URI> operationStatusURL = Optional.of(execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL));
LOGGER.debug("Executing getCurrentOperationStatus for CNF... :{}", operationStatusURL);
- final Optional<AsLcmOpOcc> instantiateOperationJobStatus =
- cnfmHttpServiceProvider.getInstantiateOperationJobStatus(operationStatusURL.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());
- }
+ final Optional<AsLcmOpOcc> operationalJobStatus =
+ cnfmHttpServiceProvider.getOperationJobStatus(String.valueOf(operationStatusURL
+ .orElseThrow(() -> new BpmnError("Operational Status check url Not found"))));
- LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}",
- asLcmOpOccResponse.getId(), asLcmOpOccResponse.getOperationState());
+ final AsLcmOpOcc asLcmOpOccResponse = operationalJobStatus
+ .orElseThrow(() -> new BpmnError("Unable to get operational Job status from the CNFM"));
+
+ if (asLcmOpOccResponse.getOperationState() != null) {
+ final OperationStateEnum operationStatus = asLcmOpOccResponse.getOperationState();
+ LOGGER.debug("Operation {} with {} and operation retrieval status : {}", asLcmOpOccResponse.getId(),
+ operationStatus, operationStatus);
+ execution.setVariable(OPERATION_STATUS_PARAM_NAME, operationStatus);
+ } else {
+ LOGGER.debug("Operation {} without operationStatus", asLcmOpOccResponse.getId());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1206,
+ new Exception("Operation Status is empty"));
}
- execution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, instantiateOperationJobStatus.orElseThrow());
+ execution.setVariable(CNF_STATUS_RESPONSE_PARAM_NAME, asLcmOpOccResponse);
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, ONAPComponents.SO);
-
+ LOGGER.error("Unable to invoke get current Operation status");
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1209, exception);
}
}
@@ -93,36 +95,30 @@ public class MonitorCnfmCreateJobTask {
*
* @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
*/
- public void timeOutLogFailue(final BuildingBlockExecution execution) {
- final String message = "CNF Instantiation operation time out";
+ public void timeOutLogFailure(final BuildingBlockExecution execution) {
+ String message = "CNF" + execution.getVariable(MONITOR_JOB_NAME) + "operation time out";
LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message, ONAPComponents.SO);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1205, new Exception(message));
}
/**
- * Check the final status of instantiation throw exception if not completed successfully
- *
+ * Check the final status of cnfm job 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";
+ final AsLcmOpOcc cnfStautusResponse = execution.getVariable(CNF_STATUS_RESPONSE_PARAM_NAME);
+ if ((operationStatusOption == OperationStateEnum.FAILED)
+ || (operationStatusOption == OperationStateEnum.FAILED_TEMP)) {
+ final String message = "Unable to" + execution.getVariable(MONITOR_JOB_NAME) + "CNF jobId: "
+ + (cnfStautusResponse != null ? cnfStautusResponse.getId() : "null");
LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message, ONAPComponents.SO);
- } else {
- if (operationStatusOption != OperationStateEnum.COMPLETED) {
- final String message = "Unable to instantiate jobId: "
- + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null")
- + " OperationStatus: " + operationStatusOption;
- LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message, ONAPComponents.SO);
- }
- LOGGER.debug("Successfully completed CNF instatiation of job status {}", cnfInstantiateStautusResponse);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1206, new Exception());
+ } else if ((operationStatusOption == OperationStateEnum.COMPLETED)) {
+ String monitorJobName = execution.getVariable(MONITOR_JOB_NAME);
+ LOGGER.debug("Successfully completed CNF {} job", monitorJobName);
}
}
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 37d6221b77..267bdcbe86 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,7 +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 CNF_STATUS_RESPONSE_PARAM_NAME = "cnfStatusResponse";
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";