aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src
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
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')
-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
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java126
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java14
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java140
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTaskTest.java (renamed from bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTaskTest.java)39
11 files changed, 535 insertions, 96 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";
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java
new file mode 100644
index 0000000000..4764aa00f1
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java
@@ -0,0 +1,126 @@
+/*-
+ * ============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.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.net.URI;
+import java.util.Optional;
+import javax.swing.text.html.Option;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+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.BBObjectNotFoundException;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
+import org.reactivestreams.Publisher;
+
+/**
+ * @author raviteja.kaumuri@est.tech
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class CnfDeleteTaskTest {
+
+ @Mock
+ private CnfmHttpServiceProvider cnfmHttpServiceProvider;
+ @Mock
+ private ExceptionBuilder exceptionUtil;
+ @Mock
+ private ExtractPojosForBB extractPojosForBB;
+ private CnfDeleteTask cnfDeleteTask;
+ private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
+ private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private final BuildingBlockExecution stubbedExecution = new StubbedBuildingBlockExecution();
+
+ @Before
+ public void setup() {
+ cnfDeleteTask = new CnfDeleteTask(cnfmHttpServiceProvider, exceptionUtil, extractPojosForBB);
+ }
+
+ @Test
+ public void test_createTerminateAsRequest_success() {
+ cnfDeleteTask.createTerminateAsRequest(stubbedExecution);
+ assertNotNull(stubbedExecution.getVariable(TERMINATE_AS_REQUEST_OBJECT));
+ }
+
+ @Test
+ public void test_invokeCnfmToTerminateAsInstance_success() throws BBObjectNotFoundException {
+ stubbedExecution.setVariable(TERMINATE_AS_REQUEST_OBJECT, getTerminateAsRequest());
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenReturn(getGenericVnf());
+ when(cnfmHttpServiceProvider.invokeTerminateAsRequest(Mockito.anyString(),
+ Mockito.any(TerminateAsRequest.class))).thenReturn(getURI());
+ cnfDeleteTask.invokeCnfmToTerminateAsInstance(stubbedExecution);
+ URI returnedContent = stubbedExecution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL);
+ assertEquals(getURI().orElseThrow().getPath(), returnedContent.getPath());
+ }
+
+ @Test
+ public void test_invokeCnfmToTerminateAsInstance_Exception() throws BBObjectNotFoundException {
+ stubbedExecution.setVariable(TERMINATE_AS_REQUEST_OBJECT, getTerminateAsRequest());
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
+ cnfDeleteTask.invokeCnfmToTerminateAsInstance(stubbedExecution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2002),
+ any(Exception.class));
+ }
+
+ @Test
+ public void test_invokeCnfmToDeleteAsInstance_success() throws BBObjectNotFoundException {
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenReturn(getGenericVnf());
+ when(cnfmHttpServiceProvider.invokeDeleteAsRequest(Mockito.anyString())).thenReturn(Optional.of(Boolean.TRUE));
+ CnfDeleteTask mockCnfDeleteTask = Mockito.spy(cnfDeleteTask);
+ mockCnfDeleteTask.invokeCnfmToDeleteAsInstance(stubbedExecution);
+ verify(mockCnfDeleteTask, times(1)).invokeCnfmToDeleteAsInstance(stubbedExecution);
+ }
+
+ @Test
+ public void test_invokeCnfmToDeleteAsInstance_Exception() throws BBObjectNotFoundException {
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
+ cnfDeleteTask.invokeCnfmToDeleteAsInstance(stubbedExecution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2003),
+ any(Exception.class));
+ }
+
+ private GenericVnf getGenericVnf() {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("12345");
+ return genericVnf;
+ }
+
+ private TerminateAsRequest getTerminateAsRequest() {
+ return new TerminateAsRequest();
+ }
+
+ private Optional<URI> getURI() {
+ return Optional.of(URI.create("test_sample"));
+ }
+}
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
index f4d8bb8439..79b47776f2 100644
--- 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
@@ -33,19 +33,20 @@ import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT
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.Optional;
import java.util.UUID;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.onap.so.bpmn.BaseTaskTest;
+import org.mockito.junit.MockitoJUnitRunner;
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.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;
@@ -54,12 +55,13 @@ import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
/**
* @author raviteja.kaumuri@est.tech
*/
-public class CnfInstantiateTaskTest extends BaseTaskTest {
+@RunWith(MockitoJUnitRunner.class)
+public class CnfInstantiateTaskTest {
+ @Mock
+ protected ExceptionBuilder exceptionUtil;
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";
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java
index aac685fe37..aab44cee3d 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java
@@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import java.net.URI;
@@ -33,9 +34,12 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
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.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -49,10 +53,13 @@ public class CnfmHttpServiceProviderImplTest {
@Mock
private CnfmUrlProvider cnfmUrlProvider;
@Mock
- private HttpRestServiceProvider httpRestServiceProvider;
+ private HttpRestServiceProviderImpl httpRestServiceProvider;
@Mock
private ResponseEntity<AsInstance> responseEntity;
+ @Mock
+ private ResponseEntity<Void> responseEntityVoid;
+ private ResponseEntity<AsLcmOpOcc> responseEntityAsLCM;
private final String createURL = "http://so-cnfm-lcm.onap:9888/so/so-cnfm/v1/api/aslcm/v1/as_instances";
private final String instantiateURL = "http://so-cnfm-lcm.onap:9888/so/so-cnfm/v1/api/aslcm/v1/as_instances"
+ getAsInstance().getAsInstanceid() + "/instantiate";
@@ -60,6 +67,7 @@ public class CnfmHttpServiceProviderImplTest {
private final URI uri = URI.create("sample");
private final CreateAsRequest createAsRequest = new CreateAsRequest();
private final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest();
+ private final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
@Before
public void setup() {
@@ -69,7 +77,7 @@ public class CnfmHttpServiceProviderImplTest {
}
@Test
- public void invokeCreateAsRequest_withStatuscodeSuccess_hasBody() {
+ public void invokeCreateAsRequest_withStatuscode_Success_hasBody() {
when(cnfmUrlProvider.getCreateAsRequestUrl()).thenReturn(createURL);
when(responseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
@@ -90,7 +98,7 @@ public class CnfmHttpServiceProviderImplTest {
@Test
- public void invokeCreateAsRequest_withStatuscodeSuccess_hasBody_emptyInstanceID() {
+ public void invokeCreateAsRequest_withStatuscode_Success_hasBody_emptyInstanceID() {
AsInstance emptyInstanceID = getAsInstance();
emptyInstanceID.setAsInstanceid(null);
@@ -103,7 +111,7 @@ public class CnfmHttpServiceProviderImplTest {
}
@Test
- public void invokeCreateAsRequest_withStatuscodeNotSuccess_hasBody_emptyInstanceID() {
+ public void invokeCreateAsRequest_withStatuscode_NotSuccess_hasBody_emptyInstanceID() {
AsInstance emptyInstanceID = getAsInstance();
emptyInstanceID.setAsInstanceid(null);
@@ -115,7 +123,8 @@ public class CnfmHttpServiceProviderImplTest {
@Test
- public void InstantiateAsRequest_withStatuscodeSuccess() {
+ public void invokeInstantiateAsRequest_withStatuscode_Success() {
+
final String asinstanceId = getAsInstance().getAsInstanceid();
when(cnfmUrlProvider.getInstantiateAsRequestUrl(asinstanceId)).thenReturn(instantiateURL);
when(responseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
@@ -125,6 +134,115 @@ public class CnfmHttpServiceProviderImplTest {
assertEquals(uri.toString(), returnedContent.orElseThrow().toString());
}
+ @Test
+ public void invokeInstantiateAsRequest_withStatuscode_Success_NoStatusURI() {
+
+ final String asinstanceId = getAsInstance().getAsInstanceid();
+ final HttpHeaders httpHeaders = getHttpHeaders();
+ httpHeaders.setLocation(null);
+ when(cnfmUrlProvider.getInstantiateAsRequestUrl(asinstanceId)).thenReturn(instantiateURL);
+ when(responseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ when(responseEntity.getHeaders()).thenReturn(httpHeaders);
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeInstantiateAsRequest(instantiateAsRequest, asinstanceId);
+ assertFalse(returnedContent.isPresent());
+ }
+
+ @Test
+ public void invokeInstantiateAsRequest_withStatuscode_NotSuccess_NoStatusURI() {
+
+ final String asinstanceId = getAsInstance().getAsInstanceid();
+ when(cnfmUrlProvider.getInstantiateAsRequestUrl(asinstanceId)).thenReturn(instantiateURL);
+ when(responseEntity.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeInstantiateAsRequest(instantiateAsRequest, asinstanceId);
+ assertFalse(returnedContent.isPresent());
+ }
+
+ @Test
+ public void test_getOperationJobStatus_statuscode_Accepted() {
+
+ responseEntityAsLCM = getResponseEntityAsLCM(HttpStatus.ACCEPTED);
+ when(httpRestServiceProvider.getHttpResponse(Mockito.anyString(), eq(AsLcmOpOcc.class)))
+ .thenReturn(responseEntityAsLCM);
+ final Optional<AsLcmOpOcc> returnedContent = cnfmHttpServiceProviderImpl.getOperationJobStatus("sample URL");
+ assertEquals(returnedContent.orElseThrow().getAsInstanceId(), getAsLcmOpOcc().getAsInstanceId());
+ }
+
+ @Test
+ public void test_getOperationJobStatus_statuscode_NotFound() {
+
+ responseEntityAsLCM = getResponseEntityAsLCM(HttpStatus.NOT_FOUND);
+ when(httpRestServiceProvider.getHttpResponse(Mockito.anyString(), eq(AsLcmOpOcc.class)))
+ .thenReturn(responseEntityAsLCM);
+ final Optional<AsLcmOpOcc> returnedContent = cnfmHttpServiceProviderImpl.getOperationJobStatus("sample URL");
+ assertFalse(returnedContent.isPresent());
+ }
+
+ @Test
+ public void invokeDeleteAsRequest_withStatuscode_Success() {
+
+ when(cnfmUrlProvider.getDeleteAsRequestUrl(Mockito.anyString())).thenReturn("deleteURL");
+ when(httpRestServiceProvider.deleteHttpRequest(Mockito.anyString(), eq(Void.class)))
+ .thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ final Optional<Boolean> returnedContent = cnfmHttpServiceProviderImpl.invokeDeleteAsRequest("2345");
+ assertTrue(returnedContent.orElseThrow());
+ }
+
+ @Test
+ public void invokeDeleteAsRequest_withStatuscode_BadRequest() {
+
+ when(cnfmUrlProvider.getDeleteAsRequestUrl(Mockito.anyString())).thenReturn("deleteURL");
+ when(httpRestServiceProvider.deleteHttpRequest(Mockito.anyString(), eq(Void.class)))
+ .thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+ final Optional<Boolean> returnedContent = cnfmHttpServiceProviderImpl.invokeDeleteAsRequest("2345");
+ assertTrue(returnedContent.isEmpty());
+ }
+
+ @Test
+ public void invokeTerminateAsRequest_withStatuscode_Success() {
+
+ when(cnfmUrlProvider.getTerminateAsRequestUrl(Mockito.anyString())).thenReturn("terminateURL");
+ when(httpRestServiceProvider.postHttpRequest(Mockito.any(TerminateAsRequest.class), Mockito.anyString(),
+ eq(Void.class))).thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ when(responseEntityVoid.getHeaders()).thenReturn(getHttpHeaders());
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeTerminateAsRequest("12356", terminateAsRequest);
+ assertTrue(returnedContent.isPresent());
+ assertEquals(uri.getPath(), returnedContent.orElseThrow().getPath());
+ }
+
+ @Test
+ public void invokeTerminateAsRequest_withStatuscode_Success_NullStatusURI() {
+
+ final HttpHeaders httpHeaders = getHttpHeaders();
+ httpHeaders.setLocation(null);
+ when(cnfmUrlProvider.getTerminateAsRequestUrl(Mockito.anyString())).thenReturn("terminateURL");
+ when(httpRestServiceProvider.postHttpRequest(Mockito.any(TerminateAsRequest.class), Mockito.anyString(),
+ eq(Void.class))).thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ when(responseEntityVoid.getHeaders()).thenReturn(httpHeaders);
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeTerminateAsRequest("12356", terminateAsRequest);
+ assertTrue(returnedContent.isEmpty());
+ }
+
+ @Test
+ public void invokeTerminateAsRequest_withStatuscode_BadRequest() {
+
+ when(cnfmUrlProvider.getTerminateAsRequestUrl(Mockito.anyString())).thenReturn("terminateURL");
+ when(httpRestServiceProvider.postHttpRequest(Mockito.any(TerminateAsRequest.class), Mockito.anyString(),
+ eq(Void.class))).thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+ // when(responseEntityVoid.getHeaders()).thenReturn(getHttpHeaders());
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeTerminateAsRequest("12356", terminateAsRequest);
+ assertTrue(returnedContent.isEmpty());
+ }
+
private AsInstance getAsInstance() {
AsInstance asInstance = new AsInstance();
asInstance.setAsInstanceid("12345");
@@ -136,4 +254,16 @@ public class CnfmHttpServiceProviderImplTest {
httpHeaders.setLocation(uri);
return httpHeaders;
}
+
+ private ResponseEntity<AsLcmOpOcc> getResponseEntityAsLCM(HttpStatus httpStatus) {
+ ResponseEntity<AsLcmOpOcc> asLcmOpOccResponseEntity =
+ new ResponseEntity<AsLcmOpOcc>(getAsLcmOpOcc(), httpStatus);
+ return asLcmOpOccResponseEntity;
+ }
+
+ private AsLcmOpOcc getAsLcmOpOcc() {
+ AsLcmOpOcc asLcmOpOcc = new AsLcmOpOcc();
+ asLcmOpOcc.setAsInstanceId("12345");
+ return asLcmOpOcc;
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTaskTest.java
index c32f6dd905..1ef3bc8753 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTaskTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -45,13 +44,13 @@ import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
* @author Raviteja Karumuri (raviteja.karumuri@est.tech)
*/
@RunWith(MockitoJUnitRunner.class)
-public class MonitorCnfmCreateJobTaskTest {
+public class MonitorCnfmJobTaskTest {
private final BuildingBlockExecution stubbedExecution = new StubbedBuildingBlockExecution();
public static final String CREATE_CNF_STATUS_RESPONSE_PARAM_NAME = "createCnfStatusResponse";
private final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
public static final String OPERATION_STATUS_PARAM_NAME = "operationStatus";
- private MonitorCnfmCreateJobTask monitorCnfmCreateJobTask;
+ private MonitorCnfmJobTask monitorCnfmCreateJobTask;
@Mock
private CnfmHttpServiceProvider mockedCnfmHttpServiceProvider;
@Mock
@@ -59,14 +58,13 @@ public class MonitorCnfmCreateJobTaskTest {
@Before
public void setup() {
- monitorCnfmCreateJobTask = new MonitorCnfmCreateJobTask(mockedCnfmHttpServiceProvider, exceptionUtil);
+ monitorCnfmCreateJobTask = new MonitorCnfmJobTask(mockedCnfmHttpServiceProvider, exceptionUtil);
}
@Test
- public void getCurrentOperationStatus_completed() {
+ public void test_getCurrentOperationStatus_completed() {
stubbedExecution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, URI.create("sampleURL"));
- when(mockedCnfmHttpServiceProvider.getInstantiateOperationJobStatus(Mockito.anyString()))
- .thenReturn(getAsLcmOpOcc());
+ when(mockedCnfmHttpServiceProvider.getOperationJobStatus(Mockito.anyString())).thenReturn(getAsLcmOpOcc());
monitorCnfmCreateJobTask.getCurrentOperationStatus(stubbedExecution);
assertEquals(AsLcmOpOcc.OperationStateEnum.COMPLETED,
stubbedExecution.getVariable(OPERATION_STATUS_PARAM_NAME));
@@ -75,16 +73,17 @@ public class MonitorCnfmCreateJobTaskTest {
@Test
public void test_getCurrentOperationStatus_Exception() {
stubbedExecution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, URI.create("sampleURL"));
- when(mockedCnfmHttpServiceProvider.getInstantiateOperationJobStatus(Mockito.anyString()))
+ when(mockedCnfmHttpServiceProvider.getOperationJobStatus(Mockito.anyString()))
.thenThrow(new RuntimeException());
monitorCnfmCreateJobTask.getCurrentOperationStatus(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1209), anyString(),
- any());
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1209),
+ any(Exception.class));
}
@Test
public void test_checkIfOperationWasSuccessful_status_completed() {
- final MonitorCnfmCreateJobTask mockedMonitorCnfmCreateJobTask = Mockito.spy(monitorCnfmCreateJobTask);
+ stubbedExecution.setVariable(OPERATION_STATUS_PARAM_NAME, AsLcmOpOcc.OperationStateEnum.COMPLETED);
+ final MonitorCnfmJobTask mockedMonitorCnfmCreateJobTask = Mockito.spy(monitorCnfmCreateJobTask);
mockedMonitorCnfmCreateJobTask.checkIfOperationWasSuccessful(stubbedExecution);
verify(mockedMonitorCnfmCreateJobTask, times(1)).checkIfOperationWasSuccessful(stubbedExecution);
}
@@ -96,16 +95,8 @@ public class MonitorCnfmCreateJobTaskTest {
stubbedExecution.setVariable(OPERATION_STATUS_PARAM_NAME, AsLcmOpOcc.OperationStateEnum.FAILED);
stubbedExecution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, mockedAsLcmOpOcc.orElseThrow());
monitorCnfmCreateJobTask.checkIfOperationWasSuccessful(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1207), anyString(),
- any());
- }
-
- @Test
- public void test_checkIfOperationWasSuccessful_status_Null() {
- stubbedExecution.setVariable(OPERATION_STATUS_PARAM_NAME, null);
- monitorCnfmCreateJobTask.checkIfOperationWasSuccessful(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1206), anyString(),
- any());
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1206),
+ any(Exception.class));
}
@Test
@@ -138,9 +129,9 @@ public class MonitorCnfmCreateJobTaskTest {
@Test
public void test_timeOutLogFailure() {
- monitorCnfmCreateJobTask.timeOutLogFailue(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1205), anyString(),
- any());
+ monitorCnfmCreateJobTask.timeOutLogFailure(stubbedExecution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1205),
+ any(Exception.class));
}
private Optional<AsLcmOpOcc> getAsLcmOpOcc() {