summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy3
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceData.groovy270
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy1
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/PnfNotificationEvent.java42
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java17
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java17
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy301
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java15
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java15
9 files changed, 669 insertions, 12 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy
index c8b48c6703..1578f0f7c0 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy
@@ -347,8 +347,9 @@ public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
logger.info(" ***** Started prepare3rdONAPRequest *****")
String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
- String extAPIPath = sppartnerUrl + '/serviceOrder'
+ String extAPIPath = UrnPropertiesReader.getVariable("extapi.endpoint", execution) + '/serviceOrder'
execution.setVariable("ExternalAPIURL", extAPIPath)
+ execution.setVariable("SPPartnerUrl",sppartnerUrl)
// ExternalAPI message format
String externalId = execution.getVariable("resourceName")
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceData.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceData.groovy
new file mode 100644
index 0000000000..a1f68f9b06
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceData.groovy
@@ -0,0 +1,270 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * 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.scripts
+
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.core.domain.Resource
+import org.onap.so.bpmn.core.domain.ServiceDecomposition
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+/**
+ * This groovy class supports the <class>DoCompareServiceInstanceData.bpmn</class> process.
+ *
+ * Inputs:
+ * @param - serviceInstanceData-original
+ * @param - serviceInstanceId
+ * @param - uuiRequest
+ * @param - model-invariant-id-original
+ * @param - model-version-id-original
+ * @param - msoRequestId
+ * @param - isDebugLogEnabled
+ *
+ * Outputs:
+ * @param - addResourceList
+ * @param - delResourceList
+ * @param - uuiRequest-add
+ * @param - uuiRequest-del
+ *
+ */
+public class DoCompareServiceInstanceData extends AbstractServiceTaskProcessor {
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ private static final Logger logger = LoggerFactory.getLogger( DoCompareServiceInstanceData.class);
+
+ public void preProcessRequest (DelegateExecution execution) {
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ logger.info("INFO"," ***** preProcessRequest *****", isDebugEnabled)
+ try {
+ checkInput("serviceInstanceData-original", execution, isDebugEnabled)
+ checkInput("serviceInstanceId", execution, isDebugEnabled)
+ checkInput("uuiRequest", execution, isDebugEnabled)
+ checkInput("model-invariant-id-original", execution, isDebugEnabled)
+ checkInput("model-version-id-original", execution, isDebugEnabled)
+ checkInput("msoRequestId", execution, isDebugEnabled)
+ } catch (Exception ex){
+ String msg = "Exception in preProcessRequest " + ex.getMessage()
+ logger.info("INFO", msg, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.info("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
+ }
+
+ private void checkInput(String inputName, DelegateExecution execution, isDebugEnabled) {
+ String msg
+ Object inputValue = execution.getVariable(inputName)
+ if (inputValue == null) {
+ msg = "Input" + inputName + "is null"
+ logger.info("INFO", msg, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ }
+
+
+ public void prepareDecomposeService_Original(DelegateExecution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ logger.debug( " ***** Inside prepareDecomposeService_Original of update generic e2e service ***** ")
+ String modelInvariantUuid = execution.getVariable("model-invariant-id-original")
+ String modelUuid = execution.getVariable("model-version-id-original")
+ //here modelVersion is not set, we use modelUuid to decompose the service.
+ String serviceModelInfo = """{
+ "modelInvariantUuid":"${modelInvariantUuid}",
+ "modelUuid":"${modelUuid}",
+ "modelVersion":""
+ }"""
+
+ execution.setVariable("serviceModelInfo_Original", serviceModelInfo)
+
+ logger.debug( " ***** Completed prepareDecomposeService_Original of update generic e2e service ***** ")
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Original() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void processDecomposition_Original(DelegateExecution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ logger.debug( " ***** Inside processDecomposition_Original() of update generic e2e service flow ***** ")
+ try {
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ execution.setVariable("serviceDecomposition_Original", serviceDecomposition)
+ } catch (Exception ex) {
+ String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. processDecomposition_Original() - " + ex.getMessage()
+ logger.debug( exceptionMessage)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void doCompareUuiRquestInput(DelegateExecution execution) {
+
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ logger.info("INFO", "======== Start doCompareUuiRquestInput Process ======== ", isDebugEnabled)
+
+ String uuiRequest_Target = execution.getVariable("uuiRequest")
+ Map<String, Object> serviceParametersObject_Target = getServiceParametersObject(uuiRequest_Target)
+ Map<String, Object> serviceRequestInputs_Target = (Map<String, Object>) serviceParametersObject_Target.get("requestInputs")
+ List<Object> resources_Target = (List<Object>) serviceParametersObject_Target.get("resources")
+
+ String uuiRequest_Original = ((ServiceInstance) execution.getVariable("serviceInstanceData-original")).getInputParameters()
+ Map<String, Object> serviceParametersObject_Original = getServiceParametersObject(uuiRequest_Original)
+ Map<String, Object> serviceRequestInputs_Original = (Map<String, Object>) serviceParametersObject_Original.get("requestInputs")
+ List<Object> resources_Original = (List<Object>) serviceParametersObject_Original.get("resources")
+
+ logger.info("INFO", "uuiRequest is: " + uuiRequest_Target, isDebugEnabled)
+
+ //the resources which are included by resources_Target but resources_Original are the resources going to be added
+ ArrayList<Object> resourceList_Add = findResourceListIncluded(resources_Target, resources_Original)
+ HashMap<String, Object> serviceRequestInputs_Add = getServiceRequestInputsIncluded(resourceList_Add, serviceRequestInputs_Target, serviceParametersObject_Target)
+ String uuiRequest_add = loadUuiRequestJsonString(uuiRequest_Target, resourceList_Add, serviceRequestInputs_Add)
+ execution.setVariable("uuiRequest", uuiRequest_add)
+ logger.info("INFO", "uuiRequest will be changed to: " + uuiRequest_add, isDebugEnabled)
+
+ //the resources which are included by resources_Original but resources_Target are the resources going to be deleted
+ ArrayList<Object> resourceList_Del = findResourceListIncluded(resources_Original, resources_Target)
+ HashMap<String, Object> serviceRequestInputs_Del = getServiceRequestInputsIncluded(resourceList_Del, serviceRequestInputs_Original, serviceParametersObject_Original)
+ String uuiRequest_del = loadUuiRequestJsonString(uuiRequest_Original, resourceList_Del, serviceRequestInputs_Del)
+ execution.setVariable("uuiRequest-del", uuiRequest_del)
+ logger.info("INFO", "uuiRequest-del: " + uuiRequest_del, isDebugEnabled)
+
+ List<Resource> addResourceList = findResourceList(resourceList_Add, execution)
+ execution.setVariable("addResourceList", addResourceList)
+ logger.info("INFO", "addResourceList: " + addResourceList, isDebugEnabled)
+
+ List<Resource> delResourceList = findResourceList(resourceList_Del, execution)
+ execution.setVariable("delResourceList", delResourceList)
+ logger.info("INFO", "delResourceList: " + delResourceList, isDebugEnabled)
+
+ logger.info("INFO", "======== COMPLETED doCompareUuiRquestInput Process ======== ", isDebugEnabled)
+ }
+
+ private List<Resource> findResourceList(ArrayList<Object> uuiResourceList, DelegateExecution execution) {
+ HashSet<String> addResourceCustomizationUuidSet = getCustomizationUuidSet(uuiResourceList)
+ Set<Resource> resourceSet = new HashSet<>()
+ ServiceDecomposition serviceDecomposition_Original = execution.getVariable("serviceDecomposition_Original")
+ List<Resource> allSR_original = serviceDecomposition_Original.getServiceResources()
+ for (Resource resource : allSR_original) {
+ if (addResourceCustomizationUuidSet.contains(resource.getModelInfo().getModelCustomizationUuid())) {
+ resourceSet.add(resource)
+ }
+ }
+ List<Resource> resourceList = new ArrayList<String>(resourceSet)
+ resourceList
+ }
+
+ private HashSet<String> getCustomizationUuidSet(ArrayList<Object> resourceList_Add) {
+ Set<String> addRsourceCustomizationUuidSet = new HashSet<>()
+ for (Map<String, Object> resourceAdded : resourceList_Add) {
+ addRsourceCustomizationUuidSet.add(resourceAdded.get("rsourceCustomizationUuid"))
+ }
+ addRsourceCustomizationUuidSet
+ }
+
+ private String loadUuiRequestJsonString(String uuiRequest_Target, ArrayList<Object> resourceList_Add, HashMap<String, Object> serviceRequestInputs_Add) {
+ Map<String, Object> uuiObject = ServicePluginFactory.getInstance().getJsonObject(uuiRequest_Target, Map.class)
+ Map<String, Object> serviceObject = (Map<String, Object>) uuiObject.get("service")
+ Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject.get("parameters")
+ serviceParametersObject.put("resources", resourceList_Add)
+ serviceParametersObject.put("requestInputs", serviceRequestInputs_Add)
+ String uuiRequest_add = ServicePluginFactory.getInstance().getJsonString(serviceObject)
+ uuiRequest_add
+ }
+
+ private HashMap<String, Object> getServiceRequestInputsIncluded(ArrayList<Object> resourceList_Add, Map<String, Object> serviceRequestInputs_Target, Map<String, Object> serviceParametersObject_Target) {
+ ArrayList<String> newResourceNames = getNewResourceNames(resourceList_Add)
+ Map<String, Object> serviceRequestInputs_Add = new HashMap<String, Object>()
+ for (String inputKey : serviceRequestInputs_Target.keySet()) {
+ String resourceName = (inputKey.split("_"))[0]
+ if (newResourceNames.contains(resourceName)) {
+ serviceRequestInputs_Add.put(inputKey, serviceParametersObject_Target.get(inputKey))
+ }
+ }
+ serviceRequestInputs_Add
+ }
+
+ private ArrayList<String> getNewResourceNames(ArrayList<Object> addResourceList) {
+ Set<String> newResourceNames = new ArrayList<String>()
+ for (Object resourceObject : addResourceList) {
+ Map<String, Object> resourceAdded = (Map<String, Object>) resourceObject
+ String resName = new String(resourceAdded.get("resourceName"))
+ normalizeName(resName)
+ newResourceNames.add(resName)
+ }
+ newResourceNames
+ }
+
+ private void normalizeName(String resName) {
+ resName.replaceAll("_", "")
+ resName.replaceAll(" ", "")
+ resName.toLowerCase()
+ }
+
+ private ArrayList<Object> findResourceListIncluded(List<Object> resources_Target, List<Object> resources_Original) {
+ List<Object> addResourceList = new ArrayList<Object>()
+ for (Object resource_Target : resources_Target) {
+ Map<String, Object> resourceObject_Target = (Map<String, Object>) resource_Target
+ boolean isNewResourceInstance = isNewResourceInstance(resourceObject_Target, resources_Original)
+ if (isNewResourceInstance) {
+ addResourceList.add(resource_Target)
+ }
+ }
+ addResourceList
+ }
+
+ private boolean isNewResourceInstance(Map<String, Object> resourceObject_Target, List<Object> resources_Original) {
+ String resourceIndex_Target = null
+ if (resourceObject_Target.keySet().contains("resourceIndex")) {
+ resourceIndex_Target = resourceObject_Target.get("resourceIndex")
+ }
+ String resourceName_Target = resourceObject_Target.get("resourceName")
+ boolean isNewResourceInstance = true
+ for (Object resource_Original : resources_Original) {
+ Map<String, Object> resourceObject_Original = (Map<String, Object>) resource_Original
+ String resourceIndex_Original = null
+ if (resourceObject_Original.keySet().contains("resourceIndex")) {
+ resourceIndex_Original = resourceObject_Original.get("resourceIndex")
+ }
+ String resourceName_Original = resourceObject_Original.get("resourceName")
+ if (resourceName_Target.equals(resourceName_Original)) {
+ if (resourceIndex_Target != null && resourceIndex_Original != null) {
+ if (resourceIndex_Target.equals(resourceIndex_Original)) {
+ isNewResourceInstance = false
+ }
+ } else {
+ isNewResourceInstance = false
+ }
+ }
+ }
+ isNewResourceInstance
+ }
+
+ private Map<String, Object> getServiceParametersObject(String uuiRequest_Target) {
+ Map<String, Object> uuiObject = ServicePluginFactory.getInstance().getJsonObject(uuiRequest_Target, Map.class)
+ Map<String, Object> serviceObject = (Map<String, Object>) uuiObject.get("service")
+ Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject.get("parameters")
+ serviceParametersObject
+ }
+
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy
index 1168b20220..8e554e286d 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy
@@ -189,6 +189,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
JSONObject ob = new JSONObject(wrapper.getJson())
JSONArray ar = ob.getJSONObject("relationship-list").getJSONArray("relationship")
+ execution.setVariable("serviceInstanceData-original", si.get())
execution.setVariable("serviceRelationShip", ar.toString())
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/PnfNotificationEvent.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/PnfNotificationEvent.java
new file mode 100644
index 0000000000..267ddbf6a7
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/PnfNotificationEvent.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.pnf;
+
+import org.springframework.context.ApplicationEvent;
+
+public class PnfNotificationEvent extends ApplicationEvent {
+
+ private String pnfCorrelationId;
+
+ /**
+ * Create a new ApplicationEvent.
+ *
+ * @param source the object on which the event initially occurred (never {@code null})
+ */
+ public PnfNotificationEvent(Object source, String pnfCorrelationId) {
+ super(source);
+ this.pnfCorrelationId = pnfCorrelationId;
+ }
+
+ public String getPnfCorrelationId() {
+ return pnfCorrelationId;
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java
index 5cbd530a93..e2dc375cd1 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java
@@ -23,14 +23,20 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.so.bpmn.infrastructure.pnf.PnfNotificationEvent;
import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
-public class InformDmaapClient implements JavaDelegate {
+public class InformDmaapClient implements JavaDelegate, ApplicationListener<PnfNotificationEvent> {
+ private Logger logger = LoggerFactory.getLogger(getClass());
private DmaapClient dmaapClient;
+ private DelegateExecution execution;
@Override
public void execute(DelegateExecution execution) {
@@ -38,10 +44,19 @@ public class InformDmaapClient implements JavaDelegate {
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
dmaapClient.registerForUpdate(pnfCorrelationId, () -> runtimeService.createMessageCorrelation("WorkflowMessage")
.processInstanceBusinessKey(execution.getProcessBusinessKey()).correlateWithResult());
+ this.execution = execution;
}
@Autowired
public void setDmaapClient(DmaapClient dmaapClient) {
this.dmaapClient = dmaapClient;
}
+
+ @Override
+ public void onApplicationEvent(PnfNotificationEvent event) {
+ logger.info("Received application event for pnfCorrelationId: {}", event.getPnfCorrelationId());
+ RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
+ runtimeService.createMessageCorrelation("WorkflowMessage")
+ .processInstanceBusinessKey(execution.getProcessBusinessKey()).correlateWithResult();
+ }
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java
index 3de0f38b70..2869111485 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java
@@ -35,9 +35,11 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
+import org.onap.so.bpmn.infrastructure.pnf.PnfNotificationEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@@ -53,8 +55,11 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
private volatile ScheduledThreadPoolExecutor executor;
private volatile boolean dmaapThreadListenerIsRunning;
+ private ApplicationEventPublisher applicationEventPublisher;
+
@Autowired
- public PnfEventReadyDmaapClient(Environment env) {
+ public PnfEventReadyDmaapClient(Environment env, ApplicationEventPublisher applicationEventPublisher) {
+ this.applicationEventPublisher = applicationEventPublisher;
httpClient = HttpClientBuilder.create().build();
pnfCorrelationIdToThreadMap = new ConcurrentHashMap<>();
topicListenerDelayInSeconds = env.getProperty("pnf.dmaap.topicListenerDelayInSeconds", Integer.class);
@@ -130,13 +135,9 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
}
private void informAboutPnfReadyIfPnfCorrelationIdFound(String pnfCorrelationId) {
- Runnable runnable = unregister(pnfCorrelationId);
- if (runnable != null) {
- logger.debug("dmaap listener gets pnf ready event for pnfCorrelationId: {}", pnfCorrelationId);
- // runnable.run();
- runnable = null;
- }
+ unregister(pnfCorrelationId);
+ PnfNotificationEvent pnfNotificationEvent = new PnfNotificationEvent(this, pnfCorrelationId);
+ applicationEventPublisher.publishEvent(pnfNotificationEvent);
}
}
-
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy
new file mode 100644
index 0000000000..afbace76d6
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy
@@ -0,0 +1,301 @@
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
+import org.junit.Before
+import org.junit.Test
+import org.mockito.ArgumentCaptor
+import org.mockito.Captor
+import org.mockito.Mockito
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.core.domain.Resource
+import org.onap.so.bpmn.core.domain.ServiceDecomposition
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs
+import static org.mockito.Mockito.times
+import static org.mockito.Mockito.when
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * 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.
+ */
+class DoCompareServiceInstanceDataTest extends MsoGroovyTest {
+
+
+ public static final String uuiSoString = "{\n" +
+ " \"service\":{\n" +
+ " \"name\":\"SiteService\",\n" +
+ " \"description\":\"SiteService\",\n" +
+ " \"serviceInvariantUuid\":\"5c13f3fb-2744-4635-9f1f-c59c92dc8f70\",\n" +
+ " \"serviceUuid\":\"3a76b1f5-fb0d-4b6b-82d5-0e8a4ebc3838\",\n" +
+ " \"globalSubscriberId\":\"test_custormer\",\n" +
+ " \"serviceType\":\"example-service-type\",\n" +
+ " \"parameters\":{\n" +
+ " \"locationConstraints\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"resources\":[\n" +
+ " {\n" +
+ " \"resourceIndex\":\"1\",\n" +
+ " \"resourceName\":\"sdwanvpnresource\",\n" +
+ " \"resourceInvariantUuid\":\"0c0e1cbe-6e01-4f9e-8c45-a9700ebc14df\",\n" +
+ " \"resourceUuid\":\"4ad2d390-5c51-45f5-9710-b467a4ec7a73\",\n" +
+ " \"resourceCustomizationUuid\":\"66590e07-0777-415c-af44-36347cf3ddd3\",\n" +
+ " \"parameters\":{\n" +
+ " \"locationConstraints\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"resources\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"requestInputs\":{\n" +
+ "\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " {\n" +
+ " \"resourceIndex\":\"1\",\n" +
+ " \"resourceName\":\"sdwansiteresource\",\n" +
+ " \"resourceInvariantUuid\":\"97a3e552-08c4-4697-aeeb-d8d3e09ce58e\",\n" +
+ " \"resourceUuid\":\"63d8e1af-32dc-4c71-891d-e3f7b6a976d2\",\n" +
+ " \"resourceCustomizationUuid\":\"205456e7-3dc0-40c4-8cb0-28e6c1877042\",\n" +
+ " \"parameters\":{\n" +
+ " \"locationConstraints\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"resources\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"requestInputs\":{\n" +
+ "\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " {\n" +
+ " \"resourceIndex\":\"2\",\n" +
+ " \"resourceName\":\"sdwansiteresource\",\n" +
+ " \"resourceInvariantUuid\":\"97a3e552-08c4-4697-aeeb-d8d3e09ce58e\",\n" +
+ " \"resourceUuid\":\"63d8e1af-32dc-4c71-891d-e3f7b6a976d2\",\n" +
+ " \"resourceCustomizationUuid\":\"205456e7-3dc0-40c4-8cb0-28e6c1877042\",\n" +
+ " \"parameters\":{\n" +
+ " \"locationConstraints\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"resources\":[\n" +
+ "\n" +
+ " ],\n" +
+ " \"requestInputs\":{\n" +
+ "\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"requestInputs\":{\n" +
+ " \"sdwanvpnresource_list\":[\n" +
+ " {\n" +
+ " \"sdwanvpn_topology\":\"hub_spoke\",\n" +
+ " \"sdwanvpn_name\":\"defaultvpn\",\n" +
+ " \"sdwansitelan_list\":[\n" +
+ " {\n" +
+ " \"role\":\"Hub\",\n" +
+ " \"portType\":\"GE\",\n" +
+ " \"portSwitch\":\"layer3-port\",\n" +
+ " \"vlanId\":\"\",\n" +
+ " \"ipAddress\":\"192.168.10.1\",\n" +
+ " \"deviceName\":\"vCPE\",\n" +
+ " \"portNumer\":\"0/0/1\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"role\":\"Hub\",\n" +
+ " \"portType\":\"GE\",\n" +
+ " \"portSwitch\":\"layer2-port\",\n" +
+ " \"vlanId\":\"55\",\n" +
+ " \"ipAddress\":\"192.168.11.1\",\n" +
+ " \"deviceName\":\"CPE_Beijing\",\n" +
+ " \"portNumer\":\"0/0/1\"\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ " ],\n" +
+ " \"sdwansiteresource_list\":[\n" +
+ " {\n" +
+ " \"sdwansite_emails\":\"chenchuanyu@huawei.com\",\n" +
+ " \"sdwansite_address\":\"Huawei Public Cloud\",\n" +
+ " \"sdwansite_description\":\"DC Site\",\n" +
+ " \"sdwansite_role\":\"dsvpn_hub\",\n" +
+ " \"sdwansite_postcode\":\"20000\",\n" +
+ " \"sdwansite_type\":\"single_gateway\",\n" +
+ " \"sdwansite_latitude\":\"\",\n" +
+ " \"sdwansite_controlPoint\":\"\",\n" +
+ " \"sdwansite_longitude\":\"\",\n" +
+ " \"sdwansitewan_list\":[\n" +
+ " {\n" +
+ " \"providerIpAddress\":\"\",\n" +
+ " \"portType\":\"GE\",\n" +
+ " \"inputBandwidth\":\"1000\",\n" +
+ " \"ipAddress\":\"\",\n" +
+ " \"name\":\"10000\",\n" +
+ " \"transportNetworkName\":\"internet\",\n" +
+ " \"outputBandwidth\":\"10000\",\n" +
+ " \"deviceName\":\"vCPE\",\n" +
+ " \"portNumber\":\"0/0/0\",\n" +
+ " \"ipMode\":\"DHCP\",\n" +
+ " \"publicIP\":\"119.3.7.113\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"sdwandevice_list\":[\n" +
+ " {\n" +
+ " \"esn\":\"XXXXXXX\",\n" +
+ " \"vendor\":\"Huawei\",\n" +
+ " \"name\":\"vCPE\",\n" +
+ " \"type\":\"AR1000V\",\n" +
+ " \"version\":\"1.0\",\n" +
+ " \"class\":\"VNF\",\n" +
+ " \"systemIp\":\"20.20.20.1\"\n" +
+ " }\n" +
+ " ]\n" +
+ " },\n" +
+ " {\n" +
+ " \"sdwansite_emails\":\"chenchuanyu@huawei.com\",\n" +
+ " \"sdwansite_address\":\"Huawei Public Cloud\",\n" +
+ " \"sdwansite_description\":\"DC Site\",\n" +
+ " \"sdwansite_role\":\"dsvpn_hub\",\n" +
+ " \"sdwansite_postcode\":\"20000\",\n" +
+ " \"sdwansite_type\":\"single_gateway\",\n" +
+ " \"sdwansite_latitude\":\"\",\n" +
+ " \"sdwansite_controlPoint\":\"\",\n" +
+ " \"sdwansite_longitude\":\"\",\n" +
+ " \"sdwansitewan_list\":[\n" +
+ " {\n" +
+ " \"providerIpAddress\":\"\",\n" +
+ " \"portType\":\"GE\",\n" +
+ " \"inputBandwidth\":\"1000\",\n" +
+ " \"ipAddress\":\"172.18.1.2/24\",\n" +
+ " \"name\":\"10000\",\n" +
+ " \"transportNetworkName\":\"internet\",\n" +
+ " \"outputBandwidth\":\"10000\",\n" +
+ " \"deviceName\":\"CPE_Beijing\",\n" +
+ " \"portNumber\":\"0/0/0\",\n" +
+ " \"ipMode\":\"Static\",\n" +
+ " \"publicIP\":\"\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"sdwandevice_list\":[\n" +
+ " {\n" +
+ " \"esn\":\"XXXXXXX\",\n" +
+ " \"vendor\":\"Huawei\",\n" +
+ " \"name\":\"CPE_Beijing\",\n" +
+ " \"type\":\"AR161\",\n" +
+ " \"version\":\"1.0\",\n" +
+ " \"class\":\"PNF\",\n" +
+ " \"systemIp\":\"20.20.20.2\"\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+
+ @Before
+ void setUp() {
+ super.init("DoCompareServiceInstanceData")
+ }
+
+ @Captor
+ static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
+
+ @Test
+ void testPreProcessRequest() {
+ mockData()
+ DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
+ csi.preProcessRequest(mockExecution)
+ }
+
+ @Test(expected = BpmnError.class)
+ void testPreProcessRequestException() {
+ DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
+ csi.preProcessRequest(mockExecution)
+ }
+
+ @Test
+ void testPrepareDecomposeService_Original() {
+ mockData()
+ DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
+ csi.prepareDecomposeService_Original(mockExecution)
+ Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
+ String serviceModelInfo = getServiceModelInfo()
+ assertThat(captor.getValue(), sameBeanAs(serviceModelInfo))
+ }
+
+ @Test
+ void testProcessDecomposition_Original() {
+ mockData()
+ DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
+ csi.processDecomposition_Original(mockExecution)
+ Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
+ ServiceDecomposition serviceDecomposition = getServiceDecomposition()
+ assertThat(captor.getValue(), sameBeanAs(serviceDecomposition))
+ }
+
+ @Test
+ void testDoCompareUuiRquestInput() {
+ mockData()
+ DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
+ csi.doCompareUuiRquestInput(mockExecution)
+ Mockito.verify(mockExecution, times(4)).setVariable(captor.capture(), captor.capture())
+ }
+
+ private String getServiceModelInfo() {
+ String modelInvariantUuid = mockExecution.getVariable("model-invariant-id-original")
+ String modelUuid = mockExecution.getVariable("model-version-id-original")
+ String serviceModelInfo = """{
+ "modelInvariantUuid":"${modelInvariantUuid}",
+ "modelUuid":"${modelUuid}",
+ "modelVersion":""
+ }"""
+ serviceModelInfo
+ }
+
+ private void mockData() {
+ when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
+ when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
+ when(mockExecution.getVariable("model-version-id-original")).thenReturn("12345")
+ when(mockExecution.getVariable("model-invariant-id-original")).thenReturn("12345")
+ when(mockExecution.getVariable("uuiRequest")).thenReturn(uuiSoString)
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("1234")
+ when(mockExecution.getVariable("serviceInstanceData-original")).thenReturn(getExpectedServiceInstance())
+ when(mockExecution.getVariable("serviceDecomposition")).thenReturn(getServiceDecomposition())
+ when(mockExecution.getVariable("serviceDecomposition_Original")).thenReturn(getServiceDecomposition())
+ }
+
+ private ServiceDecomposition getServiceDecomposition() {
+ ServiceDecomposition decomposition = new ServiceDecomposition()
+ List<Resource> allSR_original = new ArrayList<>()
+ decomposition.setAllottedResources(allSR_original)
+ return decomposition
+ }
+
+ private ServiceInstance getExpectedServiceInstance() {
+ ServiceInstance expectedServiceInstanceData = new ServiceInstance()
+ expectedServiceInstanceData.setServiceInstanceId("1234")
+ expectedServiceInstanceData.setServiceInstanceName("volte-service")
+ expectedServiceInstanceData.setServiceType("E2E Service")
+ expectedServiceInstanceData.setServiceRole("E2E Service")
+ expectedServiceInstanceData.setInputParameters(uuiSoString)
+ return expectedServiceInstanceData
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java
index 446c73dda1..96c3db0ccc 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java
@@ -27,12 +27,14 @@ import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
+import org.onap.so.bpmn.infrastructure.pnf.PnfNotificationEvent;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
public class InformDmaapClientTest {
+
@Before
public void setUp() throws Exception {
informDmaapClient = new InformDmaapClient();
@@ -71,6 +73,19 @@ public class InformDmaapClientTest {
inOrder.verify(messageCorrelationBuilder).correlateWithResult();
}
+ @Test
+ public void onApplicationEvent_validPnfNotificationEvent_expectedOutput() {
+
+ PnfNotificationEvent pnfNotificationEvent = new PnfNotificationEvent(this, "testPnfCorrelationId");
+
+ informDmaapClient.execute(delegateExecution);
+ informDmaapClient.onApplicationEvent(pnfNotificationEvent);
+
+ InOrder inOrder = inOrder(messageCorrelationBuilder);
+ inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey");
+ inOrder.verify(messageCorrelationBuilder).correlateWithResult();
+ }
+
private DelegateExecution mockDelegateExecution() {
DelegateExecution delegateExecution = mock(DelegateExecution.class);
when(delegateExecution.getVariable(eq(ExecutionVariableNames.PNF_CORRELATION_ID)))
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java
index ca3373e8cb..9f31e2a5df 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java
@@ -25,8 +25,10 @@ package org.onap.so.bpmn.infrastructure.pnf.dmaap;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
@@ -47,9 +49,12 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.infrastructure.pnf.PnfNotificationEvent;
import org.onap.so.bpmn.infrastructure.pnf.dmaap.PnfEventReadyDmaapClient.DmaapTopicListenerThread;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.env.Environment;
@RunWith(MockitoJUnitRunner.class)
@@ -80,6 +85,9 @@ public class PnfEventReadyDmaapClientTest {
private Runnable threadMockToNotifyCamundaFlow;
private ScheduledThreadPoolExecutor executorMock;
+ @Mock
+ private ApplicationEventPublisher applicationEventPublisher;
+
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
when(env.getProperty(eq("pnf.dmaap.port"), eq(Integer.class))).thenReturn(PORT);
@@ -91,7 +99,7 @@ public class PnfEventReadyDmaapClientTest {
when(env.getProperty(eq("pnf.dmaap.consumerGroup"))).thenReturn(CONSUMER_GROUP);
when(env.getProperty(eq("pnf.dmaap.topicListenerDelayInSeconds"), eq(Integer.class)))
.thenReturn(TOPIC_LISTENER_DELAY_IN_SECONDS);
- testedObject = new PnfEventReadyDmaapClient(env);
+ testedObject = new PnfEventReadyDmaapClient(env, applicationEventPublisher);
testedObjectInnerClassThread = testedObject.new DmaapTopicListenerThread();
httpClientMock = mock(HttpClient.class);
threadMockToNotifyCamundaFlow = mock(Runnable.class);
@@ -123,7 +131,10 @@ public class PnfEventReadyDmaapClientTest {
assertEquals(captor1.getValue().getURI().getPath(),
"/" + URI_PATH_PREFIX + "/" + EVENT_TOPIC_TEST + "/" + CONSUMER_GROUP + "/" + CONSUMER_ID + "");
- // verify(threadMockToNotifyCamundaFlow).run();
+ /**
+ * Two PNF returned from HTTP request.
+ */
+ verify(applicationEventPublisher, times(2)).publishEvent(any(PnfNotificationEvent.class));
verify(executorMock).shutdown();
}