diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main')
4 files changed, 148 insertions, 22 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy index 3e059e53bf..6a5a9021b2 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy @@ -216,7 +216,7 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { * This method updates the resource input by collecting required info from AAI * @param execution */ - public void updateResourceInput(DelegateExecution execution) { + public ResourceInput updateResourceInput(DelegateExecution execution) { ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(execution.getVariable(Prefix + "resourceInput"), ResourceInput.class) String modelName = resourceInputObj.getResourceModelInfo().getModelName() @@ -232,9 +232,29 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { String incomingRequest = resourceInputObj.getRequestsInputs() String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters") String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs") - String cvlan = "10" - String svlan = "100" - String accessId = "AC9.0234.0337" + String cvlan + String svlan + String remoteId + + List<Metadatum> metadatum = getMetaDatum(resourceInputObj.getGlobalSubscriberId(), + resourceInputObj.getServiceType(), + resourceInputObj.getServiceInstanceId()) + for(Metadatum datum: metadatum) { + if (datum.getMetaname().equalsIgnoreCase("cvlan")) { + cvlan = datum.getMetaval() + } + + if (datum.getMetaname().equalsIgnoreCase("svlan")) { + svlan = datum.getMetaval() + } + + if (datum.getMetaname().equalsIgnoreCase("remoteId")) { + remoteId = datum.getMetaval() + } + } + + logger.debug("cvlan: "+cvlan+" | svlan: "+svlan+" | remoteId: "+remoteId) + String manufacturer = jsonUtil.getJsonValue(serInput, "service.parameters.requestInputs.ont_ont_manufacturer") String ontsn = jsonUtil.getJsonValue(serInput, @@ -242,14 +262,14 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { String uResourceInput = jsonUtil.addJsonValue(resourceInput, "requestInputs.CVLAN", cvlan) uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.SVLAN", svlan) - uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.accessID", accessId) + uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.accessID", remoteId) uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.manufacturer", manufacturer) uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.ONTSN", ontsn) - msoLogger.debug("old resource input:" + resourceInputObj.toString()) + logger.debug("old resource input:" + resourceInputObj.toString()) resourceInputObj.setResourceParameters(uResourceInput) execution.setVariable(Prefix + "resourceInput", resourceInputObj.toString()) - msoLogger.debug("new resource Input :" + resourceInputObj.toString()) + logger.debug("new resource Input :" + resourceInputObj.toString()) break case ~/[\w\s\W]*EdgeInternetProfile[\w\s\W]*/ : @@ -260,23 +280,41 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs") JSONObject inputParameters = new JSONObject(requestInputs) - String cvlan = "100" - String svlan = "1000" + String cvlan + String svlan + String remoteId String manufacturer = jsonUtil.getJsonValue(serInput, "service.parameters.requestInputs.ont_ont_manufacturer") - String accessId = "AC9.0234.0337" + String ontsn = jsonUtil.getJsonValue(serInput, "service.parameters.requestInputs.ont_ont_serial_num") + List<Metadatum> metadatum = getMetaDatum(resourceInputObj.getGlobalSubscriberId(), + resourceInputObj.getServiceType(), + resourceInputObj.getServiceInstanceId()) + for(Metadatum datum: metadatum) { + if (datum.getMetaname().equalsIgnoreCase("cvlan")) { + cvlan = datum.getMetaval() + } + + if (datum.getMetaname().equalsIgnoreCase("svlan")) { + svlan = datum.getMetaval() + } + + if (datum.getMetaname().equalsIgnoreCase("remoteId")) { + remoteId = datum.getMetaval() + } + } + String uResourceInput = jsonUtil.addJsonValue(resourceInput, "requestInputs.c_vlan", cvlan) uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.s_vlan", svlan) uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.manufacturer", manufacturer) - uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.ip_access_id", accessId) + uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.ip_access_id", remoteId) uResourceInput = jsonUtil.addJsonValue(uResourceInput, "requestInputs.ont_sn", ontsn) - msoLogger.debug("old resource input:" + resourceInputObj.toString()) + logger.debug("old resource input:" + resourceInputObj.toString()) resourceInputObj.setResourceParameters(uResourceInput) execution.setVariable(Prefix + "resourceInput", resourceInputObj.toString()) - msoLogger.debug("new resource Input :" + resourceInputObj.toString()) + logger.debug("new resource Input :" + resourceInputObj.toString()) break @@ -320,6 +358,7 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { default: break } + return resourceInputObj } /** 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); + } + } } |