diff options
12 files changed, 276 insertions, 129 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index dd993bca51..078317885c 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -20,9 +20,8 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; -import java.util.HashMap; +import java.util.Map; import java.util.Objects; -import java.util.Optional; import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @@ -35,8 +34,7 @@ public class DmaapClientTestImpl implements DmaapClient { private Runnable informConsumer; @Override - public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, - Optional<HashMap<String, String>> updateInfo) { + public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, Map<String, String> updateInfo) { this.pnfCorrelationId = pnfCorrelationId; this.informConsumer = informConsumer; } 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 2ababac7e3..a55f32aaaa 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 @@ -3,6 +3,7 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Nokia. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +21,12 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; +import java.util.Map; 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; @@ -39,7 +38,7 @@ import java.util.Optional; @Component public class InformDmaapClient implements JavaDelegate { - private Logger logger = LoggerFactory.getLogger(getClass()); + private static final Logger LOGGER = LoggerFactory.getLogger(InformDmaapClient.class); private DmaapClient dmaapClient; @Override @@ -47,25 +46,34 @@ public class InformDmaapClient implements JavaDelegate { String pnfCorrelationId = (String) execution.getVariable(ExecutionVariableNames.PNF_CORRELATION_ID); RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService(); String processBusinessKey = execution.getProcessBusinessKey(); - HashMap<String, String> updateInfo = createUpdateInfo(execution); - updateInfo.put("pnfCorrelationId", pnfCorrelationId); - dmaapClient - .registerForUpdate(pnfCorrelationId, - () -> runtimeService.createMessageCorrelation("WorkflowMessage") - .processInstanceBusinessKey(processBusinessKey).correlateWithResult(), - Optional.of(updateInfo)); + dmaapClient.registerForUpdate(pnfCorrelationId, + () -> runtimeService.createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey(processBusinessKey).correlateWithResult(), + createUpdateInfoMap(execution)); } - private HashMap<String, String> createUpdateInfo(DelegateExecution execution) { - HashMap<String, String> map = new HashMap(); - - ResourceInput resourceInputObj = ResourceRequestBuilder + private Map<String, String> createUpdateInfoMap(DelegateExecution execution) { + Map<String, String> updateInfoMap = new HashMap<>(); + updateInfoMap.put("pnfCorrelationId", + (String) execution.getVariable(ExecutionVariableNames.PNF_CORRELATION_ID)); + getResourceInput(execution).ifPresent(resourceInput -> { + updateInfoMap.put("globalSubscriberID", resourceInput.getGlobalSubscriberId()); + updateInfoMap.put("serviceType", resourceInput.getServiceType()); + updateInfoMap.put("serviceInstanceId", resourceInput.getServiceInstanceId()); + }); + return updateInfoMap; + } - .getJsonObject((String) execution.getVariable("resourceInput"), ResourceInput.class); - map.put("globalSubscriberID", resourceInputObj.getGlobalSubscriberId()); - map.put("serviceType", resourceInputObj.getServiceType()); - map.put("serviceInstanceId", resourceInputObj.getServiceInstanceId()); - return map; + private Optional<ResourceInput> getResourceInput(DelegateExecution execution) { + ResourceInput resourceInput = null; + if (execution.getVariable("resourceInput") != null) { + resourceInput = ResourceRequestBuilder.getJsonObject((String) execution.getVariable("resourceInput"), + ResourceInput.class); + } else { + LOGGER.warn("resourceInput value is null for correlation id: {}", + execution.getVariable(ExecutionVariableNames.PNF_CORRELATION_ID)); + } + return Optional.ofNullable(resourceInput); } @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 d513684659..bafb749e15 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 @@ -3,6 +3,7 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Nokia. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +21,11 @@ package org.onap.so.bpmn.infrastructure.pnf.dmaap; -import java.util.HashMap; -import java.util.Optional; +import java.util.Map; public interface DmaapClient { - void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, - Optional<HashMap<String, String>> updateInfo); + void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, Map<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 48061db887..02303a6b23 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 @@ -54,8 +54,7 @@ public class PnfEventReadyDmaapClient implements DmaapClient { private int topicListenerDelayInSeconds; private volatile ScheduledThreadPoolExecutor executor; private volatile boolean dmaapThreadListenerIsRunning; - - public volatile List<HashMap<String, String>> updateInfoMap; + private volatile List<Map<String, String>> listOfUpdateInfoMap; @Autowired public PnfEventReadyDmaapClient(Environment env) { @@ -68,18 +67,15 @@ 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<>(); + listOfUpdateInfoMap = new ArrayList<>(); } @Override public synchronized void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, - Optional<HashMap<String, String>> updateInfo) { + Map<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); - } + synchronized (listOfUpdateInfoMap) { + listOfUpdateInfoMap.add(updateInfo); } pnfCorrelationIdToThreadMap.put(pnfCorrelationId, informConsumer); if (!dmaapThreadListenerIsRunning) { @@ -91,14 +87,14 @@ public class PnfEventReadyDmaapClient implements DmaapClient { public synchronized Runnable unregister(String pnfCorrelationId) { logger.debug("unregistering from pnf ready dmaap event for pnf correlation id: {}", pnfCorrelationId); Runnable runnable = pnfCorrelationIdToThreadMap.remove(pnfCorrelationId); - synchronized (updateInfoMap) { - for (int i = updateInfoMap.size() - 1; i >= 0; i--) { - if (!updateInfoMap.get(i).containsKey("pnfCorrelationId")) + synchronized (listOfUpdateInfoMap) { + for (int i = listOfUpdateInfoMap.size() - 1; i >= 0; i--) { + if (!listOfUpdateInfoMap.get(i).containsKey("pnfCorrelationId")) continue; - String id = updateInfoMap.get(i).get("pnfCorrelationId"); + String id = listOfUpdateInfoMap.get(i).get("pnfCorrelationId"); if (id != pnfCorrelationId) continue; - updateInfoMap.remove(i); + listOfUpdateInfoMap.remove(i); } } if (pnfCorrelationIdToThreadMap.isEmpty()) { @@ -174,8 +170,8 @@ public class PnfEventReadyDmaapClient implements DmaapClient { String customerId = null; String serviceType = null; String serId = null; - synchronized (updateInfoMap) { - for (HashMap<String, String> map : updateInfoMap) { + synchronized (listOfUpdateInfoMap) { + for (Map<String, String> map : listOfUpdateInfoMap) { if (!map.containsKey("pnfCorrelationId")) continue; if (pnfCorrelationId != map.get("pnfCorrelationId")) diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index 2634f03d4b..598582bfd8 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -3,6 +3,7 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Nokia. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,9 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; +import java.util.Map; import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; -import java.util.HashMap; import java.util.Objects; -import java.util.Optional; public class DmaapClientTestImpl implements DmaapClient { @@ -31,8 +31,7 @@ public class DmaapClientTestImpl implements DmaapClient { private Runnable informConsumer; @Override - public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, - Optional<HashMap<String, String>> updateInfo) { + public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, Map<String, String> updateInfo) { this.pnfCorrelationId = pnfCorrelationId; this.informConsumer = informConsumer; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java index 127d21c0ed..9c72d229b2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java @@ -60,6 +60,8 @@ public class AppcRunTasks { public static final String ROLLBACK_VNF_STOP = "rollbackVnfStop"; public static final String ROLLBACK_VNF_LOCK = "rollbackVnfLock"; public static final String ROLLBACK_QUIESCE_TRAFFIC = "rollbackQuiesceTraffic"; + public static final String CONTROLLER_TYPE_DEFAULT = "APPC"; + public static final String GENERIC_APPC_ERROR_CODE = "1002"; @Autowired private ExceptionBuilder exceptionUtil; @Autowired @@ -139,7 +141,12 @@ public class AppcRunTasks { ControllerSelectionReference controllerSelectionReference = catalogDbClient .getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString()); - String controllerType = controllerSelectionReference.getControllerName(); + String controllerType = null; + if (controllerSelectionReference != null) { + controllerType = controllerSelectionReference.getControllerName(); + } else { + controllerType = CONTROLLER_TYPE_DEFAULT; + } String vfModuleId = null; VfModule vfModule = null; @@ -153,7 +160,7 @@ public class AppcRunTasks { HashMap<String, String> payloadInfo = buildPayloadInfo(vnfName, aicIdentity, vnfHostIpAddress, vmIdList, vserverIdList, identityUrl, vfModuleId); - Optional<String> payload = null; + Optional<String> payload = Optional.empty(); RequestParameters requestParameters = gBBInput.getRequestContext().getRequestParameters(); if (requestParameters != null) { String pay = requestParameters.getPayload(); @@ -169,7 +176,9 @@ public class AppcRunTasks { mapRollbackVariables(execution, action, appcCode); } catch (Exception e) { logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), - "Caught exception in runAppcCommand", "BPMN", ErrorCode.UnknownError.getValue(), "APPC Error", e); + "Caught exception in runAppcCommand", "BPMN", ErrorCode.UnknownError.getValue(), + "Error on request to APPC", e); + appcCode = GENERIC_APPC_ERROR_CODE; appcMessage = e.getMessage(); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java index bc71fc6f67..9413e8ef2e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java @@ -3,13 +3,14 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2019 TechMahindra. + * Copyright (C) 2019 Nokia. * ================================================================================ * 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. @@ -20,8 +21,10 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -33,15 +36,15 @@ import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; import org.onap.so.client.cds.beans.ConfigAssignPropertiesForVnf; import org.onap.so.client.cds.beans.ConfigAssignRequestVnf; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.Vnfs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** - * * Get vnf related data and config assign - * */ @Component public class ConfigAssignVnf { @@ -51,48 +54,42 @@ public class ConfigAssignVnf { private static final String ACTION_NAME = "config-assign"; private static final String MODE = "sync"; + private final ExtractPojosForBB extractPojosForBB; + private final ExceptionBuilder exceptionBuilder; + @Autowired - private ExceptionBuilder exceptionUtil; - @Autowired - private ExtractPojosForBB extractPojosForBB; + public ConfigAssignVnf(ExtractPojosForBB extractPojosForBB, ExceptionBuilder exceptionBuilder) { + this.extractPojosForBB = extractPojosForBB; + this.exceptionBuilder = exceptionBuilder; + } /** * Getting the vnf data, blueprint name, blueprint version etc and setting them in execution object and calling the * subprocess. - * - * @param execution */ public void preProcessAbstractCDSProcessing(BuildingBlockExecution execution) { logger.info("Start preProcessAbstractCDSProcessing "); try { - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); - - List<Map<String, Object>> userParams = - execution.getGeneralBuildingBlock().getRequestContext().getRequestParameters().getUserParams(); - ConfigAssignPropertiesForVnf configAssignPropertiesForVnf = new ConfigAssignPropertiesForVnf(); configAssignPropertiesForVnf.setServiceInstanceId(serviceInstance.getServiceInstanceId()); configAssignPropertiesForVnf .setServiceModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid()); configAssignPropertiesForVnf - .setVnfCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid()); - configAssignPropertiesForVnf.setVnfId(vnf.getVnfId()); - configAssignPropertiesForVnf.setVnfName(vnf.getVnfName()); - - for (Map<String, Object> params : userParams) { - for (Map.Entry<String, Object> entry : params.entrySet()) { - configAssignPropertiesForVnf.setUserParam(entry.getKey(), entry.getValue()); - } - } - + .setVnfCustomizationUuid(genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + configAssignPropertiesForVnf.setVnfId(genericVnf.getVnfId()); + configAssignPropertiesForVnf.setVnfName(genericVnf.getVnfName()); + setUserParamsInConfigAssignPropertiesForVnf(configAssignPropertiesForVnf, + execution.getGeneralBuildingBlock().getRequestContext().getRequestParameters().getUserParams(), + genericVnf); ConfigAssignRequestVnf configAssignRequestVnf = new ConfigAssignRequestVnf(); - configAssignRequestVnf.setResolutionKey(vnf.getVnfName()); + configAssignRequestVnf.setResolutionKey(genericVnf.getVnfName()); configAssignRequestVnf.setConfigAssignPropertiesForVnf(configAssignPropertiesForVnf); - String blueprintName = vnf.getModelInfoGenericVnf().getBlueprintName(); - String blueprintVersion = vnf.getModelInfoGenericVnf().getBlueprintVersion(); + String blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName(); + String blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion(); logger.debug(" BlueprintName : " + blueprintName + " BlueprintVersion : " + blueprintVersion); AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean(); @@ -109,9 +106,48 @@ public class ConfigAssignVnf { abstractCDSPropertiesBean.setActionName(ACTION_NAME); abstractCDSPropertiesBean.setMode(MODE); execution.setVariable("executionObject", abstractCDSPropertiesBean); - } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + logger.error("An exception occurred when creating ConfigAssignPropertiesForVnf for CDS request", ex); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + private void setUserParamsInConfigAssignPropertiesForVnf(ConfigAssignPropertiesForVnf configAssignProperties, + List<Map<String, Object>> userParamsFromRequest, GenericVnf vnf) throws Exception { + Service service = getServiceFromRequestUserParams(userParamsFromRequest); + List<Map<String, String>> instanceParamsList = + getInstanceParamForVnf(service, vnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + instanceParamsList + .forEach(instanceParamsMap -> instanceParamsMap.forEach(configAssignProperties::setUserParam)); + } + + private Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception { + Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey("service")).findFirst() + .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock")); + return convertServiceFromJsonToServiceObject((String) serviceMap.get("service")); + } + + private Service convertServiceFromJsonToServiceObject(String serviceFromJson) throws Exception { + try { + return new ObjectMapper().readValue(serviceFromJson, Service.class); + } catch (Exception e) { + logger.error(String.format( + "An exception occurred while converting json object to Service object. The json is: %s", + serviceFromJson), e); + throw e; + } + } + + private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid) + throws Exception { + Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream() + .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(genericVnfModelCustomizationUuid)) + .findFirst(); + if (foundedVnf.isPresent()) { + return foundedVnf.get().getInstanceParams(); + } else { + throw new Exception(String.format("Can not find vnf for genericVnfModelCustomizationUuid: %s", + genericVnfModelCustomizationUuid)); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfAdapterClientImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfAdapterClientImpl.java index e24e86285c..9af2128f63 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfAdapterClientImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfAdapterClientImpl.java @@ -7,9 +7,9 @@ * 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. @@ -33,11 +33,16 @@ import org.onap.so.adapters.vnfrest.RollbackVfModuleResponse; import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest; import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse; import org.onap.so.client.adapter.rest.AdapterRestClient; +import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component public class VnfAdapterClientImpl implements VnfAdapterClient { + private static final Logger logger = LoggerFactory.getLogger(VnfAdapterClientImpl.class); + private static final String VF_MODULES = "/vf-modules/"; private VnfAdapterRestProperties props; @@ -57,6 +62,7 @@ public class VnfAdapterClientImpl implements VnfAdapterClient { return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + "/vf-modules").build()).post(req, CreateVfModuleResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in createVfModule", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -69,6 +75,7 @@ public class VnfAdapterClientImpl implements VnfAdapterClient { this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId + "/rollback").build()).delete(req, RollbackVfModuleResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in rollbackVfModule", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -80,6 +87,7 @@ public class VnfAdapterClientImpl implements VnfAdapterClient { return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build()) .delete(req, DeleteVfModuleResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in deleteVfModule", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -91,6 +99,7 @@ public class VnfAdapterClientImpl implements VnfAdapterClient { return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build()) .put(req, UpdateVfModuleResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in updateVfModule", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -122,6 +131,7 @@ public class VnfAdapterClientImpl implements VnfAdapterClient { return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON).get(QueryVfModuleResponse.class).get(); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in queryVfModule", e); throw new VnfAdapterClientException(e.getMessage()); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java index 2af4d5f1fa..c5e8bf7416 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientImpl.java @@ -7,9 +7,9 @@ * 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. @@ -34,11 +34,15 @@ import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest; import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse; import org.onap.so.client.RestClient; import org.onap.so.client.adapter.rest.AdapterRestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { + private static final Logger logger = LoggerFactory.getLogger(VnfVolumeAdapterClientImpl.class); + private final VnfVolumeAdapterRestProperties props; public VnfVolumeAdapterClientImpl() { @@ -50,6 +54,7 @@ public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { try { return this.getAdapterRestClient("").post(req, CreateVolumeGroupResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in createVNFVolumes", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -60,6 +65,7 @@ public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { try { return this.getAdapterRestClient("/" + aaiVolumeGroupId).delete(req, DeleteVolumeGroupResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in deleteVNFVolumes", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -71,6 +77,7 @@ public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { return this.getAdapterRestClient("/" + aaiVolumeGroupId + "/rollback").delete(req, RollbackVolumeGroupResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in rollbackVNFVolumes", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -81,6 +88,7 @@ public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { try { return this.getAdapterRestClient("/" + aaiVolumeGroupId).put(req, UpdateVolumeGroupResponse.class); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in updateVNFVolumes", e); throw new VnfAdapterClientException(e.getMessage()); } } @@ -94,6 +102,7 @@ public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient { requestId, serviceInstanceId); return this.getAdapterRestClient(path).get(QueryVolumeGroupResponse.class).get(); } catch (InternalServerErrorException e) { + logger.error("InternalServerErrorException in queryVNFVolumes", e); throw new VnfAdapterClientException(e.getMessage()); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java index 6daed56675..6278d48e03 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java @@ -23,10 +23,10 @@ package org.onap.so.client.adapter.vnf.mapper; import java.io.Serializable; public class AttributeNameValue implements Serializable { - private final static long serialVersionUID = -5215028275587848311L; + private static final long serialVersionUID = -5215028275587848311L; private String attributeName; - private Object attributeValue; + private transient Object attributeValue; public AttributeNameValue(String attributeName, Object attributeValue) { this.attributeName = attributeName; @@ -51,7 +51,7 @@ public class AttributeNameValue implements Serializable { @Override public String toString() { - return new StringBuilder().append("{\"attribute_name\": \"").append(attributeName.toString()) + return new StringBuilder().append("{\"attribute_name\": \"").append(attributeName) .append("\", \"attribute_value\": \"").append(attributeValue.toString()).append("\"}").toString(); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java index 5c69987a54..8c13c9be97 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java @@ -33,7 +33,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; import javax.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; @@ -76,10 +75,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException; import org.onap.so.entity.MsoRequest; import org.onap.so.jsonpath.JsonPathUtil; import org.onap.so.openstack.utils.MsoMulticloudUtils; -import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -481,7 +480,7 @@ public class VnfAdapterVfModuleObjectMapper { } } sbInterfaceRoutePrefixes.append("]"); - if (interfaceRoutePrefixesList.size() > 0) { + if (!interfaceRoutePrefixesList.isEmpty()) { paramsMap.put(key + UNDERSCORE + networkKey + "_route_prefixes", sbInterfaceRoutePrefixes.toString()); } @@ -508,7 +507,7 @@ public class VnfAdapterVfModuleObjectMapper { sriovFilterBuf.append(heatVlanFilterValue); } } - if (heatVlanFiltersList.size() > 0) { + if (!heatVlanFiltersList.isEmpty()) { paramsMap.put(networkKey + "_ATT_VF_VLAN_FILTER", sriovFilterBuf.toString()); } } @@ -540,7 +539,7 @@ public class VnfAdapterVfModuleObjectMapper { String ipVersion = ipAddress.getIpVersion(); for (int b = 0; b < ipsList.size(); b++) { String ipAddressValue = ipsList.get(b); - if (ipVersion.equals("ipv4")) { + if ("ipv4".equals(ipVersion)) { if (b != ipsList.size() - 1) { sbIpv4Ips.append(ipAddressValue + ","); } else { @@ -548,7 +547,7 @@ public class VnfAdapterVfModuleObjectMapper { } paramsMap.put(key + UNDERSCORE + networkKey + IP + UNDERSCORE + b, ipAddressValue); - } else if (ipVersion.equals("ipv6")) { + } else if ("ipv6".equals(ipVersion)) { if (b != ipsList.size() - 1) { sbIpv6Ips.append(ipAddressValue + ","); } else { @@ -897,6 +896,7 @@ public class VnfAdapterVfModuleObjectMapper { try { json = mapper.writeValueAsString(obj); } catch (JsonProcessingException e) { + logger.error("JsonProcessingException in convertToString", e); json = "{}"; } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java index 7d96a18305..468bc7d8f6 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java @@ -3,13 +3,14 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2019 TechMahindra. + * Copyright (C) 2019 Nokia. * ================================================================================ * 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. @@ -20,57 +21,139 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.UUID; -import org.camunda.bpm.engine.delegate.BpmnError; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.InjectMocks; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.ExceptionBuilder; -public class ConfigAssignVnfTest extends BaseTaskTest { - @InjectMocks - private ConfigAssignVnf configAssignVnf = new ConfigAssignVnf(); +public class ConfigAssignVnfTest { - private GenericVnf genericVnf; - private ServiceInstance serviceInstance; - private RequestContext requestContext; - private String msoRequestId; + private static final String GENERIC_VNF_ID = "vnfId_configVnfTest"; + private static final String GENERIC_VNF_NAME = "vnfName_configVnfTest"; + private static final String VNF_MODEL_CUSTOMIZATION_UUID = "0c1ac643-377e-475b-be50-6be65f91a7ad"; + private static final String SERVICE_INSTANCE_ID = "serviceInst_configTest"; + private static final String SERVICE_MODEL_UUID = "5af91c26-8418-4d3f-944c-965842deda94"; + private static final String TARGET_VNF_MODEL_CUSTOMIZATION_UUID = "0c1ac643-377e-475b-be50-6be65f91a7ad"; + private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput"; + private static final int THE_NUMBER_OF_EXPECTED_CONFIG_PROPERTIES = 8; + + private static final String USER_PARAMS_FROM_REQUEST = "{\"resources\":{\"vnfs\":[" + + "{\"modelInfo\":{\"modelCustomizationId\":\"" + VNF_MODEL_CUSTOMIZATION_UUID + "\"}," + + "\"instanceParams\":[{\"paramName1\":\"paramValue1\",\"paramName2\":\"paramValue2\"},{\"paramName3\":\"paramValue3\"}]}," + + "{\"modelInfo\":{\"modelCustomizationId\":\"2d1ac656-377e-467b-be50-6ce65f66a7ca\"}," + + "\"instanceParams\":[{\"parName4\":\"parValue4\",\"parName5\":\"parValue5\"}]}]}}\n"; + + + private ConfigAssignVnf testedObject; + + private BuildingBlockExecution buildingBlockExecution; + private ExtractPojosForBB extractPojosForBB; @Before - public void before() throws BBObjectNotFoundException { - genericVnf = setGenericVnf(); - serviceInstance = setServiceInstance(); - msoRequestId = UUID.randomUUID().toString(); - requestContext = setRequestContext(); - requestContext.setMsoRequestId(msoRequestId); - gBBInput.setRequestContext(requestContext); - - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil) - .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) - .thenReturn(genericVnf); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) - .thenReturn(serviceInstance); + public void setup() { + buildingBlockExecution = createBuildingBlockExecution(); + extractPojosForBB = mock(ExtractPojosForBB.class); + testedObject = new ConfigAssignVnf(extractPojosForBB, new ExceptionBuilder()); } @Test - public void preProcessAbstractCDSProcessingTest() throws Exception { + public void prepareAbstractCDSPropertiesBean_success() throws Exception { + // given + when(extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID)) + .thenReturn(createGenericVnf()); + when(extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID)) + .thenReturn(createServiceInstance()); + // when + testedObject.preProcessAbstractCDSProcessing(buildingBlockExecution); + // then + verifyConfigAssignPropertiesJsonContent(); + } - configAssignVnf.preProcessAbstractCDSProcessing(execution); + private void verifyConfigAssignPropertiesJsonContent() throws Exception { + AbstractCDSPropertiesBean abstractCDSPropertiesBean = buildingBlockExecution.getVariable("executionObject"); + String payload = abstractCDSPropertiesBean.getRequestObject(); + ObjectMapper mapper = new ObjectMapper(); + JsonNode payloadJson = mapper.readTree(payload); + JsonNode configAssignPropertiesNode = payloadJson.findValue("config-assign-properties"); + assertThat(configAssignPropertiesNode.size()).isEqualTo(THE_NUMBER_OF_EXPECTED_CONFIG_PROPERTIES); + assertThat(configAssignPropertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(configAssignPropertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); + assertThat(configAssignPropertiesNode.get("vnf-name").asText()).isEqualTo(GENERIC_VNF_NAME); + assertThat(configAssignPropertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); + assertThat(configAssignPropertiesNode.get("vnf-customization-uuid").asText()) + .isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID); + assertThat(configAssignPropertiesNode.has("paramName1")).isTrue(); + assertThat(configAssignPropertiesNode.get("paramName1").asText()).isEqualTo("paramValue1"); + assertThat(configAssignPropertiesNode.has("paramName2")).isTrue(); + assertThat(configAssignPropertiesNode.get("paramName2").asText()).isEqualTo("paramValue2"); + assertThat(configAssignPropertiesNode.has("paramName3")).isTrue(); + assertThat(configAssignPropertiesNode.get("paramName3").asText()).isEqualTo("paramValue3"); + } - assertTrue(true); + private BuildingBlockExecution createBuildingBlockExecution() { + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock()); + return new DelegateExecutionImpl(execution); } + private ServiceInstance createServiceInstance() { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelUuid(SERVICE_MODEL_UUID); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + return serviceInstance; + } + + private GenericVnf createGenericVnf() { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(GENERIC_VNF_ID); + genericVnf.setVnfName(GENERIC_VNF_NAME); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelCustomizationUuid(TARGET_VNF_MODEL_CUSTOMIZATION_UUID); + modelInfoGenericVnf.setBlueprintName("blueprintTest"); + modelInfoGenericVnf.setBlueprintVersion("blueprintVerTest"); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); + return genericVnf; + } + + private GeneralBuildingBlock createGeneralBuildingBlock() { + GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock(); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(createRequestUserParams()); + requestContext.setRequestParameters(requestParameters); + generalBuildingBlock.setRequestContext(requestContext); + return generalBuildingBlock; + } + + private List<Map<String, Object>> createRequestUserParams() { + List<Map<String, Object>> userParams = new ArrayList<>(); + Map<String, Object> userParamMap = new HashMap<>(); + userParamMap.put("service", USER_PARAMS_FROM_REQUEST); + userParams.add(userParamMap); + return userParams; + } } |