aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap
diff options
context:
space:
mode:
authormarios.iakovidis <marios.iakovidis@huawei.com>2019-04-25 13:15:41 +0300
committermarios.iakovidis <marios.iakovidis@huawei.com>2019-04-26 12:33:25 +0300
commit73b63fce2c7ba9aaeca0e54a1a9f027dca5e13bd (patch)
tree792513391385cc655dc23a6d9a0337e5fc398ee3 /bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap
parent074c0ebe9c1a0db0a5e0cc936898c35569ff4029 (diff)
Removed hardcoded values for PNF creation (cvlan, svlan, remoteId)
Change-Id: Ie4a63dd06279713c9f13062a09b44eb0e7f2e6bc Issue-ID: SO-1815 Signed-off-by: MariosIakovidis <marios.iakovidis@huawei.com>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java27
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/DmaapClient.java6
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java72
3 files changed, 96 insertions, 9 deletions
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 94ceddae97..2ababac7e3 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
@@ -24,11 +24,17 @@ import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.runtime.Execution;
+import org.onap.aai.domain.yang.v13.Metadatum;
+import org.onap.so.bpmn.common.recipe.ResourceInput;
+import org.onap.so.bpmn.common.resource.ResourceRequestBuilder;
+import org.onap.so.bpmn.core.json.JsonUtils;
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.stereotype.Component;
+import java.util.HashMap;
+import java.util.Optional;
@Component
public class InformDmaapClient implements JavaDelegate {
@@ -41,8 +47,25 @@ public class InformDmaapClient implements JavaDelegate {
String pnfCorrelationId = (String) execution.getVariable(ExecutionVariableNames.PNF_CORRELATION_ID);
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
String processBusinessKey = execution.getProcessBusinessKey();
- dmaapClient.registerForUpdate(pnfCorrelationId, () -> runtimeService.createMessageCorrelation("WorkflowMessage")
- .processInstanceBusinessKey(processBusinessKey).correlateWithResult());
+ HashMap<String, String> updateInfo = createUpdateInfo(execution);
+ updateInfo.put("pnfCorrelationId", pnfCorrelationId);
+ dmaapClient
+ .registerForUpdate(pnfCorrelationId,
+ () -> runtimeService.createMessageCorrelation("WorkflowMessage")
+ .processInstanceBusinessKey(processBusinessKey).correlateWithResult(),
+ Optional.of(updateInfo));
+ }
+
+ private HashMap<String, String> createUpdateInfo(DelegateExecution execution) {
+ HashMap<String, String> map = new HashMap();
+
+ ResourceInput resourceInputObj = ResourceRequestBuilder
+
+ .getJsonObject((String) execution.getVariable("resourceInput"), ResourceInput.class);
+ map.put("globalSubscriberID", resourceInputObj.getGlobalSubscriberId());
+ map.put("serviceType", resourceInputObj.getServiceType());
+ map.put("serviceInstanceId", resourceInputObj.getServiceInstanceId());
+ return map;
}
@Autowired
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/DmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/DmaapClient.java
index fbf86cc411..d513684659 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/DmaapClient.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/DmaapClient.java
@@ -20,9 +20,13 @@
package org.onap.so.bpmn.infrastructure.pnf.dmaap;
+import java.util.HashMap;
+import java.util.Optional;
+
public interface DmaapClient {
- void registerForUpdate(String pnfCorrelationId, Runnable informConsumer);
+ void registerForUpdate(String pnfCorrelationId, Runnable informConsumer,
+ Optional<HashMap<String, String>> updateInfo);
Runnable unregister(String pnfCorrelationId);
}
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 96562fe90f..cce476f4d8 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
@@ -23,9 +23,7 @@
package org.onap.so.bpmn.infrastructure.pnf.dmaap;
import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -40,6 +38,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.AAIObjectType;
@Component
public class PnfEventReadyDmaapClient implements DmaapClient {
@@ -53,6 +55,8 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
private volatile ScheduledThreadPoolExecutor executor;
private volatile boolean dmaapThreadListenerIsRunning;
+ public volatile List<HashMap<String, String>> updateInfoMap;
+
@Autowired
public PnfEventReadyDmaapClient(Environment env) {
httpClient = HttpClientBuilder.create().build();
@@ -64,11 +68,19 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
.port(env.getProperty("pnf.dmaap.port", Integer.class)).path(env.getProperty("pnf.dmaap.topicName"))
.path(env.getProperty("pnf.dmaap.consumerGroup")).path(env.getProperty("pnf.dmaap.consumerId"))
.build());
+ updateInfoMap = new ArrayList<>();
}
@Override
- public synchronized void registerForUpdate(String pnfCorrelationId, Runnable informConsumer) {
+ public synchronized void registerForUpdate(String pnfCorrelationId, Runnable informConsumer,
+ Optional<HashMap<String, String>> updateInfo) {
logger.debug("registering for pnf ready dmaap event for pnf correlation id: {}", pnfCorrelationId);
+ HashMap<String, String> map = updateInfo.get();
+ if (map != null && map.size() > 0) {
+ synchronized (updateInfoMap) {
+ updateInfoMap.add(map);
+ }
+ }
pnfCorrelationIdToThreadMap.put(pnfCorrelationId, informConsumer);
if (!dmaapThreadListenerIsRunning) {
startDmaapThreadListener();
@@ -78,7 +90,17 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
@Override
public synchronized Runnable unregister(String pnfCorrelationId) {
logger.debug("unregistering from pnf ready dmaap event for pnf correlation id: {}", pnfCorrelationId);
- Runnable runnable = pnfCorrelationIdToThreadMap.remove(pnfCorrelationId);
+ Runnable runnable = runnable = pnfCorrelationIdToThreadMap.remove(pnfCorrelationId);
+ synchronized (updateInfoMap) {
+ for (int i = updateInfoMap.size() - 1; i >= 0; i--) {
+ if (!updateInfoMap.get(i).containsKey("pnfCorrelationId"))
+ continue;
+ String id = updateInfoMap.get(i).get("pnfCorrelationId");
+ if (id != pnfCorrelationId)
+ continue;
+ updateInfoMap.remove(i);
+ }
+ }
if (pnfCorrelationIdToThreadMap.isEmpty()) {
stopDmaapThreadListener();
}
@@ -111,7 +133,14 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
try {
logger.debug("dmaap listener starts listening pnf ready dmaap topic");
HttpResponse response = httpClient.execute(getRequest);
- getPnfCorrelationIdListFromResponse(response).forEach(this::informAboutPnfReadyIfPnfCorrelationIdFound);
+ List<String> idList = getPnfCorrelationIdListFromResponse(response);
+
+ if (idList != null && idList.size() > 0) {
+ // send only body of response
+ registerClientResponse(idList.get(0), EntityUtils.toString(response.getEntity(), "UTF-8"));
+ }
+
+ idList.forEach(this::informAboutPnfReadyIfPnfCorrelationIdFound);
} catch (IOException e) {
logger.error("Exception caught during sending rest request to dmaap for listening event topic", e);
} finally {
@@ -136,5 +165,36 @@ public class PnfEventReadyDmaapClient implements DmaapClient {
runnable.run();
}
}
+
+ private void registerClientResponse(String pnfCorrelationId, String response) {
+
+ String customerId = null;
+ String serviceType = null;
+ String serId = null;
+ synchronized (updateInfoMap) {
+ for (HashMap<String, String> map : updateInfoMap) {
+ if (!map.containsKey("pnfCorrelationId"))
+ continue;
+ if (pnfCorrelationId != map.get("pnfCorrelationId"))
+ continue;
+ if (!map.containsKey("globalSubscriberID"))
+ continue;
+ if (!map.containsKey("serviceType"))
+ continue;
+ if (!map.containsKey("serviceInstanceId"))
+ continue;
+ customerId = map.get("pnfCorrelationId");
+ serviceType = map.get("serviceType");
+ serId = map.get("serviceInstanceId");
+ }
+ }
+ if (customerId == null || serviceType == null || serId == null)
+ return;
+ AAIResourcesClient client = new AAIResourcesClient();
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE_METADATA, customerId,
+ serviceType, serId);
+ client.update(uri, response);
+ }
+
}
}