diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
56 files changed, 1497 insertions, 139 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java index e83c27c400..92b4e211d5 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java @@ -404,9 +404,9 @@ public class SniroHomingV2 { for(Candidate c:required){ org.onap.so.client.sniro.beans.Candidate can = new org.onap.so.client.sniro.beans.Candidate(); org.onap.so.client.sniro.beans.CandidateType type = new org.onap.so.client.sniro.beans.CandidateType(); - type.setName(c.getCandidateType().getName()); - can.setCandidateType(type); - can.setCandidates(c.getCandidates()); + type.setName(c.getIdentifierType().getName()); + can.setIdentifierType(type); + can.setIdentifiers(c.getIdentifiers()); can.setCloudOwner(c.getCloudOwner()); cans.add(can); } @@ -417,9 +417,9 @@ public class SniroHomingV2 { for(Candidate c:excluded){ org.onap.so.client.sniro.beans.Candidate can = new org.onap.so.client.sniro.beans.Candidate(); org.onap.so.client.sniro.beans.CandidateType type = new org.onap.so.client.sniro.beans.CandidateType(); - type.setName(c.getCandidateType().getName()); - can.setCandidateType(type); - can.setCandidates(c.getCandidates()); + type.setName(c.getIdentifierType().getName()); + can.setIdentifierType(type); + can.setIdentifiers(c.getIdentifiers()); can.setCloudOwner(c.getCloudOwner()); cans.add(can); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index 4a3cb01b74..f47781082d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -22,11 +22,13 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; import java.util.Arrays; import java.util.List; +import java.util.Optional; +import java.util.TreeSet; +import java.util.UUID; import java.util.stream.Collectors; import org.camunda.bpm.engine.delegate.BpmnError; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; @@ -35,6 +37,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; @@ -44,6 +47,9 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.aai.AAIObjectPlurals; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAIConfigurationResources; @@ -53,9 +59,10 @@ import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.client.orchestration.AAIVolumeGroupResources; import org.onap.so.client.orchestration.AAIVpnBindingResources; -import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @@ -64,8 +71,13 @@ import org.springframework.stereotype.Component; public class AAICreateTasks { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAICreateTasks.class); + private static final Logger logger = LoggerFactory.getLogger(AAICreateTasks.class.getName()); + private static final String networkTypeProvider = "PROVIDER"; private static String NETWORK_COLLECTION_NAME = "networkCollectionName"; + private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList"; + private static String HEAT_STACK_ID = "heatStackId"; + private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn"; @Autowired private AAIServiceInstanceResources aaiSIResources; @Autowired @@ -233,6 +245,11 @@ public class AAICreateTasks { try { GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); + int moduleIndex = 0; + if (vfModule.getModelInfoVfModule() != null && !Boolean.TRUE.equals(vfModule.getModelInfoVfModule().getIsBaseBoolean())) { + moduleIndex = this.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, vfModule); + } + vfModule.setModuleIndex(moduleIndex); aaiVfModuleResources.createVfModule(vfModule, vnf); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); @@ -432,4 +449,95 @@ public class AAICreateTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + + public void createNetworkPolicies(BuildingBlockExecution execution) { + try{ + String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST); + if (fqdns != null && !fqdns.isEmpty()) { + String fqdnList[] = fqdns.split(","); + int fqdnCount = fqdnList.length; + if (fqdnCount > 0) { + for (int i=0; i < fqdnCount; i++) { + String fqdn = fqdnList[i]; + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY); + uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn); + Optional<org.onap.aai.domain.yang.NetworkPolicy> oNetPolicy = aaiNetworkResources.getNetworkPolicy(uri); + if(!oNetPolicy.isPresent()) { + msoLogger.debug("This network policy FQDN is not in AAI yet: " + fqdn); + String networkPolicyId = UUID.randomUUID().toString(); + msoLogger.debug("Adding network-policy with network-policy-id " + networkPolicyId); + NetworkPolicy networkPolicy = new NetworkPolicy(); + networkPolicy.setNetworkPolicyId(networkPolicyId); + networkPolicy.setNetworkPolicyFqdn(fqdn); + networkPolicy.setHeatStackId(execution.getVariable(HEAT_STACK_ID)); + + aaiNetworkResources.createNetworkPolicy(networkPolicy); + } + } + } + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + /** + * Groups existing vf modules by the model uuid of our new vf module and returns the lowest unused index + * + * if we have a module type A, and there are 3 instances of those, + * and then module type B has 2 instances, if we are adding a new module type A, + * the vf-module-index should be 3 assuming contiguous indices (not 5, or 2) + * + */ + protected int getLowestUnusedVfModuleIndexFromAAIVnfResponse(GenericVnf genericVnf, VfModule newVfModule) { + + String newVfModuleModelInvariantUUID = null; + if (newVfModule.getModelInfoVfModule() != null) { + newVfModuleModelInvariantUUID = newVfModule.getModelInfoVfModule().getModelInvariantUUID(); + } + + + if (genericVnf != null && genericVnf.getVfModules() != null && !genericVnf.getVfModules().isEmpty()) { + List<VfModule> modules = genericVnf.getVfModules().stream().filter(item -> !item.getVfModuleId().equals(newVfModule.getVfModuleId())).collect(Collectors.toList()); + TreeSet<Integer> moduleIndices = new TreeSet<>(); + int nullIndexFound = 0; + for (VfModule vfModule : modules) { + if (vfModule.getModelInfoVfModule() != null) { + if (vfModule.getModelInfoVfModule().getModelInvariantUUID().equals(newVfModuleModelInvariantUUID)) { + if (vfModule.getModuleIndex() != null) { + moduleIndices.add(vfModule.getModuleIndex()); + } else { + nullIndexFound++; + logger.warn("Found null index for vf-module-id {} and model-invariant-uuid {}", vfModule.getVfModuleId(), vfModule.getModelInfoVfModule().getModelInvariantUUID()); + } + } + } + } + + return calculateUnusedIndex(moduleIndices, nullIndexFound); + } else { + return 0; + } + } + + protected int calculateUnusedIndex(TreeSet<Integer> moduleIndices, int nullIndexFound) { + //pad array with nulls + Integer[] temp = new Integer[moduleIndices.size() + nullIndexFound]; + Integer[] array = moduleIndices.toArray(temp); + int result = 0; + //when a null is found skip that potential value + //effectively creates something like, [0,1,3,null,null] -> [0,1,null(2),3,null(4)] + for (int i=0; i < array.length; i++, result++) { + if (Integer.valueOf(result) != array[i]) { + if (nullIndexFound > 0) { + nullIndexFound--; + i--; + } else { + break; + } + } + } + + return result; + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java index a00806a19c..8f0334e462 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java @@ -21,16 +21,23 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; +import java.util.Optional; +import java.util.UUID; + import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.aai.AAIObjectPlurals; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAINetworkResources; @@ -38,11 +45,16 @@ import org.onap.so.client.orchestration.AAIServiceInstanceResources; import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.client.orchestration.AAIVolumeGroupResources; +import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class AAIDeleteTasks { + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIDeleteTasks.class); + + private static String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList"; + private static String NETWORK_POLICY_FQDN_PARAM = "network-policy-fqdn"; @Autowired private ExceptionBuilder exceptionUtil; @@ -145,4 +157,30 @@ public class AAIDeleteTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + + public void deleteNetworkPolicies(BuildingBlockExecution execution) { + try{ + String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST); + if (fqdns != null && !fqdns.isEmpty()) { + String fqdnList[] = fqdns.split(","); + int fqdnCount = fqdnList.length; + if (fqdnCount > 0) { + for (int i=0; i < fqdnCount; i++) { + String fqdn = fqdnList[i]; + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY); + uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn); + Optional<org.onap.aai.domain.yang.NetworkPolicy> oNetPolicy = aaiNetworkResources.getNetworkPolicy(uri); + if(oNetPolicy.isPresent()) { + String networkPolicyId = oNetPolicy.get().getNetworkPolicyId(); + msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId); + + aaiNetworkResources.deleteNetworkPolicy(networkPolicyId); + } + } + } + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index ed6379a6a4..5176bee0d6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -449,4 +449,53 @@ public class AAIUpdateTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + + public void updateIpv4OamAddressVnf(BuildingBlockExecution execution) { + try { + String ipv4OamAddress = execution.getVariable("oamManagementV4Address"); + if (ipv4OamAddress != null) { + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + GenericVnf copiedGenericVnf = genericVnf.shallowCopyId(); + + genericVnf.setIpv4OamAddress(ipv4OamAddress); + copiedGenericVnf.setIpv4OamAddress(ipv4OamAddress); + + aaiVnfResources.updateObjectVnf(copiedGenericVnf); + } + } catch(Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void updateManagementV6AddressVnf(BuildingBlockExecution execution) { + try { + String managementV6Address = execution.getVariable("oamManagementV6Address"); + if (managementV6Address != null) { + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + GenericVnf copiedGenericVnf = genericVnf.shallowCopyId(); + + genericVnf.setManagementV6Address(managementV6Address); + copiedGenericVnf.setManagementV6Address(managementV6Address); + + aaiVnfResources.updateObjectVnf(copiedGenericVnf); + } + } catch(Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void updateContrailServiceInstanceFqdnVfModule(BuildingBlockExecution execution) { + try { + String contrailServiceInstanceFqdn = execution.getVariable("contrailServiceInstanceFqdn"); + if (contrailServiceInstanceFqdn != null) { + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + vfModule.setContrailServiceInstanceFqdn(contrailServiceInstanceFqdn); + aaiVfModuleResources.updateContrailServiceInstanceFqdnVfModule(vfModule, vnf); + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + }
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java index 94eead2d05..acef0cb354 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java @@ -84,6 +84,7 @@ public class ExecuteActivity implements JavaDelegate { variables.put("buildingBlock", executeBuildingBlock); variables.put("mso-request-id", requestId); variables.put("retryCount", 1); + variables.put("aLaCarte", true); ProcessInstanceWithVariables buildingBlockResult = runtimeService.createProcessInstanceByKey("ExecuteBuildingBlock").setVariables(variables).executeWithVariablesInReturn(); VariableMap variableMap = buildingBlockResult.getVariables(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java index d821223507..fec7e8456f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.adapter.network.tasks; import java.io.StringReader; @@ -15,6 +35,9 @@ import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkError; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkError; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.NetworkAdapterResources; import org.slf4j.Logger; @@ -68,8 +91,8 @@ public class NetworkAdapterRestV1 { throw new Exception("No Network Request was created. networkAdapterRequest was null."); } } catch (Exception ex) { - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex.getStackTrace().toString()); - } + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex); + } } public void processCallback (DelegateExecution execution) { @@ -95,6 +118,14 @@ public class NetworkAdapterRestV1 { DeleteNetworkResponse deleteNetworkResponse = (DeleteNetworkResponse) unmarshalXml(callback, DeleteNetworkResponse.class); execution.setVariable("deleteNetworkResponse", deleteNetworkResponse); } + } else if (networkAdapterRequest instanceof UpdateNetworkRequest) { + if (callback.contains("updateNetworkError")) { + UpdateNetworkError updateNetworkError = (UpdateNetworkError) unmarshalXml(callback, UpdateNetworkError.class); + throw new Exception(updateNetworkError.getMessage()); + } else { + UpdateNetworkResponse updateNetworkResponse = (UpdateNetworkResponse) unmarshalXml(callback, UpdateNetworkResponse.class); + execution.setVariable("updateNetworkResponse", updateNetworkResponse); + } } } } catch (Exception e) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImpl.java index f1a9e955b6..0851dc9d95 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImpl.java @@ -26,6 +26,7 @@ import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse; import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; @@ -47,10 +48,18 @@ import javax.xml.bind.Unmarshaller; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.sax.SAXSource; import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; @Component public class VnfAdapterImpl { - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfAdapterCreateTasks.class); + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfAdapterImpl.class); + private static final String CONTRAIL_SERVICE_INSTANCE_FQDN = "contrailServiceInstanceFqdn"; + private static final String OAM_MANAGEMENT_V4_ADDRESS = "oamManagementV4Address"; + private static final String OAM_MANAGEMENT_V6_ADDRESS = "oamManagementV6Address"; + private static final String CONTRAIL_NETWORK_POLICY_FQDN_LIST = "contrailNetworkPolicyFqdnList"; @Autowired private ExtractPojosForBB extractPojosForBB; @@ -65,6 +74,10 @@ public class VnfAdapterImpl { execution.setVariable("mso-request-id", gBBInput.getRequestContext().getMsoRequestId()); execution.setVariable("mso-service-instance-id", serviceInstance.getServiceInstanceId()); execution.setVariable("heatStackId", null); + execution.setVariable(CONTRAIL_SERVICE_INSTANCE_FQDN, null); + execution.setVariable(OAM_MANAGEMENT_V4_ADDRESS, null); + execution.setVariable(OAM_MANAGEMENT_V6_ADDRESS, null); + execution.setVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST, null); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } @@ -79,15 +92,36 @@ public class VnfAdapterImpl { VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); String heatStackId = ((CreateVfModuleResponse) vnfRestResponse).getVfModuleStackId(); if(!StringUtils.isEmpty(heatStackId)) { - vfModule.setHeatStackId(heatStackId); + vfModule.setHeatStackId(heatStackId); execution.setVariable("heatStackId", heatStackId); } + Map<String,String> vfModuleOutputs = ((CreateVfModuleResponse) vnfRestResponse).getVfModuleOutputs(); + if (vfModuleOutputs != null) { + processVfModuleOutputs(execution, vfModuleOutputs); + } } else if(vnfRestResponse instanceof DeleteVfModuleResponse) { VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); Boolean vfModuleDelete = ((DeleteVfModuleResponse) vnfRestResponse).getVfModuleDeleted(); if(null!= vfModuleDelete && vfModuleDelete) { vfModule.setHeatStackId(null); execution.setVariable("heatStackId", null); + Map<String,String> vfModuleOutputs = ((DeleteVfModuleResponse) vnfRestResponse).getVfModuleOutputs(); + if (vfModuleOutputs != null) { + processVfModuleOutputs(execution, vfModuleOutputs); + if (execution.getVariable(OAM_MANAGEMENT_V4_ADDRESS) != null) { + genericVnf.setIpv4OamAddress(""); + execution.setVariable(OAM_MANAGEMENT_V4_ADDRESS, ""); + } + if (execution.getVariable(OAM_MANAGEMENT_V6_ADDRESS) != null) { + genericVnf.setManagementV6Address(""); + execution.setVariable(OAM_MANAGEMENT_V6_ADDRESS, ""); + } + if (execution.getVariable(CONTRAIL_SERVICE_INSTANCE_FQDN) != null) { + vfModule.setContrailServiceInstanceFqdn(""); + execution.setVariable(CONTRAIL_SERVICE_INSTANCE_FQDN, ""); + } + } } } else if(vnfRestResponse instanceof CreateVolumeGroupResponse) { VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID)); @@ -108,7 +142,7 @@ public class VnfAdapterImpl { } } } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } @@ -133,4 +167,49 @@ public class VnfAdapterImpl { throw new MarshallerException("Error parsing VNF Adapter response. " + e.getMessage(), MsoLogger.ErrorCode.SchemaError.getValue(), e); } } + + private void processVfModuleOutputs(BuildingBlockExecution execution, Map<String,String> vfModuleOutputs) { + if (vfModuleOutputs == null) { + return; + } + try { + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + List<String> contrailNetworkPolicyFqdnList = new ArrayList<String>(); + Iterator<String> keys = vfModuleOutputs.keySet().iterator(); + while (keys.hasNext()) { + String key = keys.next(); + if (key.equals("contrail-service-instance-fqdn")) { + String contrailServiceInstanceFqdn = vfModuleOutputs.get(key); + msoLogger.debug("Obtained contrailServiceInstanceFqdn: " + contrailServiceInstanceFqdn); + vfModule.setContrailServiceInstanceFqdn(contrailServiceInstanceFqdn); + execution.setVariable(CONTRAIL_SERVICE_INSTANCE_FQDN, contrailServiceInstanceFqdn); + } + else if (key.endsWith("contrail_network_policy_fqdn")) { + String contrailNetworkPolicyFqdn = vfModuleOutputs.get(key); + msoLogger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn); + contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn); + } + else if (key.equals("oam_management_v4_address")) { + String oamManagementV4Address = vfModuleOutputs.get(key); + msoLogger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address); + genericVnf.setIpv4OamAddress(oamManagementV4Address); + execution.setVariable(OAM_MANAGEMENT_V4_ADDRESS, oamManagementV4Address); + } + else if (key.equals("oam_management_v6_address")) { + String oamManagementV6Address = vfModuleOutputs.get(key); + msoLogger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address); + genericVnf.setManagementV6Address(oamManagementV6Address); + execution.setVariable(OAM_MANAGEMENT_V6_ADDRESS, oamManagementV6Address); + } + + if (!contrailNetworkPolicyFqdnList.isEmpty()) { + execution.setVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST, String.join(",", contrailNetworkPolicyFqdnList)); + } + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java new file mode 100644 index 0000000000..aaa9e51d15 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/audit/AuditTasks.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.audit; + + +import org.onap.so.audit.beans.AuditInventory; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +public class AuditTasks { + + private static final Logger logger = LoggerFactory.getLogger(AuditTasks.class); + + @Autowired + private ExceptionBuilder exceptionUtil; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private Environment env; + + public void isAuditNeeded(BuildingBlockExecution execution) { + try { + logger.debug("auditInventoryNeeded Value: {}", env.getProperty("mso.infra.auditInventory")); + execution.setVariable("auditInventoryNeeded",env.getProperty("mso.infra.auditInventory")); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void setupAuditVariable(BuildingBlockExecution execution) { + try { + execution.setVariable("auditInventory",createAuditInventory(execution)); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + private AuditInventory createAuditInventory(BuildingBlockExecution execution) throws BBObjectNotFoundException { + AuditInventory auditInventory = new AuditInventory(); + + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); + CloudRegion cloudRegion = gBBInput.getCloudRegion(); + + auditInventory.setCloudOwner(cloudRegion.getCloudOwner()); + auditInventory.setCloudRegion(cloudRegion.getLcpCloudRegionId()); + auditInventory.setTenantId(cloudRegion.getTenantId()); + auditInventory.setHeatStackName(vfModule.getVfModuleName()); + return auditInventory; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java new file mode 100644 index 0000000000..f2fb37e182 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModule.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.flowspecific.tasks; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +public class ActivateVfModule { + + private static final Logger logger = LoggerFactory.getLogger(ActivateVfModule.class); + + protected static final String VF_MODULE_TIMER_DURATION_PATH = "mso.workflow.vfModuleActivate.timer.duration"; + protected static final String DEFAULT_TIMER_DURATION = "PT180S"; + + @Autowired + private ExceptionBuilder exceptionUtil; + + @Autowired + private Environment environment; + + + public void setTimerDuration(BuildingBlockExecution execution) { + try { + String waitDuration = this.environment.getProperty(VF_MODULE_TIMER_DURATION_PATH, DEFAULT_TIMER_DURATION); + logger.debug("Sleeping before proceeding with SDNC activate. Timer duration: {}", waitDuration); + execution.setVariable("vfModuleActivateTimerDuration", waitDuration); + } catch (Exception e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java index 2dae820e95..4f2e2c98d2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java @@ -21,7 +21,10 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import java.util.HashMap; import java.util.Optional; - +import java.net.HttpURLConnection; +import java.net.SocketTimeoutException; +import org.apache.http.conn.ConnectTimeoutException; +import org.camunda.bpm.engine.delegate.BpmnError; import org.onap.appc.client.lcm.model.Action; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -105,10 +108,22 @@ public class GenericVnfHealthCheck { appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); appcCode = appCClient.getErrorCode(); appcMessage = appCClient.getErrorMessage(); - + } catch (BpmnError ex) { + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Caught exception in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex); + appcMessage = ex.getMessage(); + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage); } catch (Exception e) { - msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e); - appcMessage = e.getMessage(); + if (e instanceof java.util.concurrent.TimeoutException ) + { + appcMessage = "Request to APPC timed out. "; + msoLogger.error(MessageEnum.RA_CONNECTION_EXCEPTION, "Caught timedOut exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e); + throw e; + } + else { + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e); + appcMessage = e.getMessage(); + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage); + } } msoLogger.error("Error Message: " + appcMessage); msoLogger.error("ERROR CODE: " + appcCode); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java index b0063c1da1..2065dfb71e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java @@ -105,6 +105,10 @@ public class OrchestrationStatusValidator { org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID, execution.getLookupMap().get(ResourceKey.CONFIGURATION_ID)); orchestrationStatus = configuration.getOrchestrationStatus(); break; + case NO_VALIDATE: + //short circuit and exit method + execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.VALIDATION_SKIPPED); + return; default: // can't currently get here, so not tested. Added in case enum is expanded without a change to this code throw new OrchestrationStatusValidationException(String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction())); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index d18fd006f4..0082545fa1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -68,6 +68,8 @@ import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.Networks; +import org.onap.so.serviceinstancebeans.RelatedInstance; +import org.onap.so.serviceinstancebeans.RelatedInstanceList; import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -198,7 +200,7 @@ public class WorkflowAction { if (orchFlows == null || orchFlows.isEmpty()) { orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, cloudOwner, serviceType); } - orchFlows = filterOrchFlows(orchFlows, resourceType, execution); + orchFlows = filterOrchFlows(sIRequest, orchFlows, resourceType, execution); String key = ""; ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo(); if(modelInfo.getModelType().equals(ModelType.service)) { @@ -303,8 +305,9 @@ public class WorkflowAction { } } - // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, enable it. - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, enable it. + if (sIRequest.getRequestDetails().getRequestParameters() != null && + sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); for (Map<String, Object> params : userParams) { if (params.containsKey(HOMINGSOLUTION)) { @@ -320,12 +323,13 @@ public class WorkflowAction { if (flowsToExecute.isEmpty()) { throw new IllegalStateException("Macro did not come up with a valid execution path."); } - + List<String> flowNames = new ArrayList<>(); logger.info("List of BuildingBlocks to execute:"); for (ExecuteBuildingBlock ebb : flowsToExecute) { logger.info(ebb.getBuildingBlock().getBpmnFlowName()); + flowNames.add(ebb.getBuildingBlock().getBpmnFlowName()); } - + execution.setVariable("flowNames", flowNames); execution.setVariable(G_CURRENT_SEQUENCE, 0); execution.setVariable("retryCount", 0); execution.setVariable("isRollback", false); @@ -1101,10 +1105,22 @@ public class WorkflowAction { return listToExecute; } - protected List<OrchestrationFlow> filterOrchFlows(List<OrchestrationFlow> orchFlows, WorkflowType resourceType, DelegateExecution execution) { + protected List<OrchestrationFlow> filterOrchFlows(ServiceInstancesRequest sIRequest, List<OrchestrationFlow> orchFlows, WorkflowType resourceType, DelegateExecution execution) { List<OrchestrationFlow> result = new ArrayList<>(orchFlows); + String vnfCustomizationUUID = ""; + String vfModuleCustomizationUUID = sIRequest.getRequestDetails().getModelInfo().getModelCustomizationUuid(); + RelatedInstanceList[] relatedInstanceList = sIRequest.getRequestDetails().getRelatedInstanceList(); + if (relatedInstanceList != null) { + for (RelatedInstanceList relatedInstList : relatedInstanceList) { + RelatedInstance relatedInstance = relatedInstList.getRelatedInstance(); + if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) { + vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationUuid(); + } + } + } + if (resourceType.equals(WorkflowType.VFMODULE)) { - List<String> fabricCustomizations = traverseCatalogDbForConfiguration((String)execution.getVariable("vnfId"), (String)execution.getVariable("vfModuleId")); + List<String> fabricCustomizations = traverseCatalogDbForConfiguration(vnfCustomizationUUID, vfModuleCustomizationUUID); if (fabricCustomizations.isEmpty()) { result = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList()); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java index c895566ca5..c8eeaa7a2b 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java @@ -302,4 +302,8 @@ public class AAIObjectMapper { public org.onap.aai.domain.yang.Subnet mapSubnet (Subnet subnet){ return modelMapper.map(subnet,org.onap.aai.domain.yang.Subnet.class); } + + public org.onap.aai.domain.yang.NetworkPolicy mapNetworkPolicy (NetworkPolicy networkPolicy){ + return modelMapper.map(networkPolicy,org.onap.aai.domain.yang.NetworkPolicy.class); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java index 794314bf8c..f917aed39e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java @@ -22,6 +22,7 @@ package org.onap.so.client.adapter.network.mapper; import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -92,14 +93,19 @@ public class NetworkAdapterObjectMapper { networkTechnology = l3Network.getNetworkTechnology(); logger.warn("NetworkTechnology was null in CatalogDB. Using field from AAI: " + networkTechnology); } - createNetworkRequest.setNetworkTechnology(setNetworkTechnology(networkTechnology)); + if (networkTechnology != null) { + createNetworkRequest.setNetworkTechnology(networkTechnology.toUpperCase()); + if (createNetworkRequest.getNetworkTechnology().contains("CONTRAIL")) { + createNetworkRequest.setContrailRequest(true); + } + } //build and set Contrail Network ContrailNetwork contrailNetwork = buildContrailNetwork(l3Network, customer); createNetworkRequest.setContrailNetwork(contrailNetwork); - //set Network Parameters from VID request - createNetworkRequest.setNetworkParams(userInput); + //set Network Parameters from VID request, add "shared" and "external" to this map + createNetworkRequest.setNetworkParams(addSharedAndExternal(userInput, l3Network)); createNetworkRequest = setFlowFlags(createNetworkRequest, orchestrationContext); @@ -112,16 +118,6 @@ public class NetworkAdapterObjectMapper { return createNetworkRequest; } - protected NetworkTechnology setNetworkTechnology(String networkTechnology) { - if(networkTechnology.equalsIgnoreCase("Contrail")) { - return NetworkTechnology.CONTRAIL; - } else if(networkTechnology.equalsIgnoreCase("Neutron")){ - return NetworkTechnology.NEUTRON; - } else { - return NetworkTechnology.VMWARE; - } - } - public DeleteNetworkRequest deleteNetworkRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, ServiceInstance serviceInstance, L3Network l3Network) throws UnsupportedEncodingException { DeleteNetworkRequest deleteNetworkRequest = new DeleteNetworkRequest(); @@ -182,7 +178,7 @@ public class NetworkAdapterObjectMapper { updateNetworkRequest.setSubnets(buildOpenstackSubnetList(l3Network)); updateNetworkRequest.setProviderVlanNetwork(buildProviderVlanNetwork(l3Network)); updateNetworkRequest.setContrailNetwork(buildContrailNetwork(l3Network, customer)); - updateNetworkRequest.setNetworkParams(userInput); + updateNetworkRequest.setNetworkParams(addSharedAndExternal(userInput, l3Network)); updateNetworkRequest.setMsoRequest(createMsoRequest(requestContext, serviceInstance)); setFlowFlags(updateNetworkRequest, orchestrationContext); @@ -287,6 +283,14 @@ public class NetworkAdapterObjectMapper { //add host route to the list openstackHostRouteList.add(openstackHostRoute); } + if (subnet.getDhcpStart() != null && !subnet.getDhcpStart().equals("")) { + org.onap.so.openstack.beans.Pool openstackAllocationPool = new org.onap.so.openstack.beans.Pool(); + openstackAllocationPool.setStart(subnet.getDhcpStart()); + openstackAllocationPool.setEnd(subnet.getDhcpEnd()); + List<org.onap.so.openstack.beans.Pool> allocationPools = new ArrayList<>(); + allocationPools.add(openstackAllocationPool); + openstackSubnet.setAllocationPools(allocationPools); + } openstackSubnet.setHostRoutes(openstackHostRouteList); //add subnet to the list subnetList.add(openstackSubnet); @@ -371,4 +375,16 @@ public class NetworkAdapterObjectMapper { updateNetworkRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled())); //NetworkTechnology(NetworkTechnology.NEUTRON); NOOP - default } -}
\ No newline at end of file + + private Map<String, String> addSharedAndExternal(Map<String, String> userInput, L3Network l3Network) { + if (userInput == null) + userInput = new HashMap<String, String>(); + if (!userInput.containsKey("shared")) { + userInput.put("shared", Optional.ofNullable(l3Network.isIsSharedNetwork()).orElse(false).toString()); + } + if (!userInput.containsKey("external")) { + userInput.put("external", Optional.ofNullable(l3Network.isIsExternalNetwork()).orElse(false).toString()); + } + return userInput; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapper.java index 93e588f2e1..701817ab58 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapper.java @@ -29,6 +29,7 @@ import java.util.UUID; import javax.annotation.PostConstruct; +import org.apache.commons.lang3.StringUtils; import org.onap.sdnc.northbound.client.model.GenericResourceApiParam; import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology; @@ -92,7 +93,12 @@ public class VnfAdapterObjectMapper { deleteVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); deleteVolumeGroupRequest.setTenantId(cloudRegion.getTenantId()); deleteVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId()); - deleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId()); + if (!StringUtils.isEmpty(volumeGroup.getHeatStackId())){ + deleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId()); + } else + { + deleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getVolumeGroupName()); + } deleteVolumeGroupRequest.setSkipAAI(true); deleteVolumeGroupRequest.setMsoRequest(createMsoRequest(requestContext, serviceInstance)); 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 3ace03ee0a..352d4ec7d1 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 @@ -23,6 +23,7 @@ package org.onap.so.client.adapter.vnf.mapper; import static java.util.Arrays.asList; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -35,6 +36,7 @@ import java.util.Optional; import javax.annotation.PostConstruct; +import org.apache.commons.lang3.StringUtils; import org.onap.sdnc.northbound.client.model.GenericResourceApiParam; import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam; import org.onap.sdnc.northbound.client.model.GenericResourceApiSubInterfaceNetworkData; @@ -443,7 +445,6 @@ public class VnfAdapterVfModuleObjectMapper { } } } - } private void buildVfModuleNetworkInformation(Map<String,String> paramsMap, GenericResourceApiVmNetworkData network, String key, String networkKey) { @@ -780,16 +781,26 @@ public class VnfAdapterVfModuleObjectMapper { deleteVfModuleRequest.setTenantId(cloudRegion.getTenantId()); deleteVfModuleRequest.setVnfId(genericVnf.getVnfId()); deleteVfModuleRequest.setVfModuleId(vfModule.getVfModuleId()); - deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId - deleteVfModuleRequest.setSkipAAI(true); - String messageId = vnfAdapterObjectMapperUtils.getRandomUuid(); - deleteVfModuleRequest.setMessageId(messageId); - deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId)); + if (!StringUtils.isEmpty(vfModule.getHeatStackId())){ + deleteVfModuleRequest.setVfModuleStackId(vfModule.getHeatStackId());//DoDVfMod_heatStackId + } else + { + deleteVfModuleRequest.setVfModuleStackId(vfModule.getVfModuleName()); + } + + deleteVfModuleRequest.setSkipAAI(true); + setIdAndUrl(deleteVfModuleRequest); MsoRequest msoRequest = buildMsoRequest(requestContext, serviceInstance); deleteVfModuleRequest.setMsoRequest(msoRequest); return deleteVfModuleRequest; } + protected void setIdAndUrl(DeleteVfModuleRequest deleteVfModuleRequest) throws UnsupportedEncodingException{ + String messageId = vnfAdapterObjectMapperUtils.getRandomUuid(); + deleteVfModuleRequest.setMessageId(messageId); + deleteVfModuleRequest.setNotificationUrl(vnfAdapterObjectMapperUtils.createCallbackUrl("VNFAResponse", messageId)); + } + private String convertToString(Object obj) { String json; try { @@ -814,4 +825,4 @@ public class VnfAdapterVfModuleObjectMapper { } return baseVfModule; } -} +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java index d2bf95a28e..4ca3f2a78d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java @@ -45,6 +45,7 @@ import org.springframework.stereotype.Component; @Component public class AAINetworkResources { + @Autowired private InjectionHelper injectionHelper; @@ -171,6 +172,16 @@ public class AAINetworkResources { AAIResourceUri instanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); injectionHelper.getAaiClient().delete(instanceGroupURI); } - - + + public void createNetworkPolicy(org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy networkPolicy) { + NetworkPolicy aaiNetworkPolicy = aaiObjectMapper.mapNetworkPolicy(networkPolicy); + String networkPolicyId = networkPolicy.getNetworkPolicyId(); + AAIResourceUri netUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId); + injectionHelper.getAaiClient().create(netUri, aaiNetworkPolicy); + } + + public void deleteNetworkPolicy(String networkPolicyId) { + AAIResourceUri networkPolicyURI = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId); + injectionHelper.getAaiClient().delete(networkPolicyURI); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java index a641d43ba3..ef61319eee 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVfModuleResources.java @@ -76,6 +76,15 @@ public class AAIVfModuleResources { injectionHelper.getAaiClient().update(vfModuleURI, aaiVfModule); } + public void updateContrailServiceInstanceFqdnVfModule(VfModule vfModule, GenericVnf vnf) { + AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId()); + VfModule copiedVfModule = vfModule.shallowCopyId(); + + copiedVfModule.setContrailServiceInstanceFqdn(vfModule.getContrailServiceInstanceFqdn()); + org.onap.aai.domain.yang.VfModule aaiVfModule = aaiObjectMapper.mapVfModule(copiedVfModule); + injectionHelper.getAaiClient().update(vfModuleURI, aaiVfModule); + } + public void changeAssignVfModule(VfModule vfModule, GenericVnf vnf) { AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId()); org.onap.aai.domain.yang.VfModule AAIVfModule = aaiObjectMapper.mapVfModule(vfModule); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java index b42636b078..1f8c56e727 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Candidate.java @@ -29,28 +29,28 @@ public class Candidate implements Serializable{ private static final long serialVersionUID = -5474502255533410907L; - @JsonProperty("candidateType") - private CandidateType candidateType; - @JsonProperty("candidates") - private List<String> candidates; + @JsonProperty("identifierType") + private CandidateType identifierType; + @JsonProperty("identifiers") + private List<String> identifiers; @JsonProperty("cloudOwner") private String cloudOwner; - public CandidateType getCandidateType(){ - return candidateType; + public CandidateType getIdentifierType(){ + return identifierType; } - public void setCandidateType(CandidateType candidateType){ - this.candidateType = candidateType; + public void setIdentifierType(CandidateType identifierType){ + this.identifierType = identifierType; } - public List<String> getCandidates(){ - return candidates; + public List<String> getIdentifiers(){ + return identifiers; } - public void setCandidates(List<String> candidates){ - this.candidates = candidates; + public void setIdentifiers(List<String> identifiers){ + this.identifiers = identifiers; } public String getCloudOwner(){ diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java index 873ff7ca95..cf28c114e8 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java @@ -20,7 +20,7 @@ package org.onap.so.bpmn.common.aai.tasks; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java index df1f0adcea..d8c7ebaff7 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -45,6 +45,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; @@ -516,7 +517,7 @@ public class TestDataSetup{ VfModule vfModule = new VfModule(); vfModule.setVfModuleId("testVfModuleId" + vfModuleCounter); vfModule.setVfModuleName("testVfModuleName" + vfModuleCounter); - + vfModule.setModuleIndex(0); ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); modelInfoVfModule.setModelInvariantUUID("testModelInvariantUUID" + vfModuleCounter); modelInfoVfModule.setModelVersion("testModelVersion" + vfModuleCounter); @@ -529,6 +530,10 @@ public class TestDataSetup{ } public VfModule setVfModule() { + return setVfModule(true); + } + + public VfModule setVfModule(boolean addToGenericVnf) { VfModule vfModule = buildVfModule(); GenericVnf genericVnf = null; @@ -539,7 +544,9 @@ public class TestDataSetup{ genericVnf = setGenericVnf(); } - genericVnf.getVfModules().add(vfModule); + if (addToGenericVnf) { + genericVnf.getVfModules().add(vfModule); + } lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModule.getVfModuleId()); return vfModule; @@ -702,4 +709,12 @@ public class TestDataSetup{ subnet.setNeutronSubnetId("testNeutronSubnetId"); return subnet; } + + public NetworkPolicy buildNetworkPolicy() { + NetworkPolicy networkPolicy = new NetworkPolicy(); + networkPolicy.setNetworkPolicyId("testNetworkPolicyId"); + networkPolicy.setNetworkPolicyFqdn("testNetworkPolicyFqdn"); + networkPolicy.setHeatStackId("testHeatStackId"); + return networkPolicy; + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java index da7e727488..c48019af83 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -19,6 +19,7 @@ */ package org.onap.so.bpmn.infrastructure.aai.tasks; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; @@ -29,12 +30,18 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.Arrays; +import java.util.Optional; +import java.util.TreeSet; + import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; +import org.mockito.Captor; import org.mockito.InjectMocks; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; @@ -43,12 +50,16 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; public class AAICreateTasksTest extends BaseTaskTest{ @@ -65,6 +76,9 @@ public class AAICreateTasksTest extends BaseTaskTest{ private Customer customer; private Configuration configuration; + @Captor + ArgumentCaptor<NetworkPolicy> networkPolicyCaptor; + @Rule public final ExpectedException exception = ExpectedException.none(); @@ -268,9 +282,17 @@ public class AAICreateTasksTest extends BaseTaskTest{ @Test public void createVfModuleTest() throws Exception { - doNothing().when(aaiVfModuleResources).createVfModule(vfModule, genericVnf); + + VfModule newVfModule = setVfModule(false); + newVfModule.setModuleIndex(null); + newVfModule.getModelInfoVfModule().setModelInvariantUUID("testModelInvariantUUID1"); + doNothing().when(aaiVfModuleResources).createVfModule(newVfModule, genericVnf); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(newVfModule); + + assertEquals(null, newVfModule.getModuleIndex()); aaiCreateTasks.createVfModule(execution); - verify(aaiVfModuleResources, times(1)).createVfModule(vfModule, genericVnf); + assertEquals(1, newVfModule.getModuleIndex().intValue()); + verify(aaiVfModuleResources, times(1)).createVfModule(newVfModule, genericVnf); } @Test @@ -445,4 +467,138 @@ public class AAICreateTasksTest extends BaseTaskTest{ aaiCreateTasks.connectVnfToTenant(execution); verify(aaiVnfResources, times(1)).connectVnfToTenant(genericVnf, gBBInput.getCloudRegion()); } + @Test + public void createNetworkPolicyNeedToCreateAllTest() throws Exception { + execution.setVariable("heatStackId", "testHeatStackId"); + execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123,ED456"); + Optional<NetworkPolicy> networkPolicy = Optional.empty(); + doReturn(networkPolicy).when(aaiNetworkResources).getNetworkPolicy(any(AAIResourceUri.class)); + doNothing().when(aaiNetworkResources).createNetworkPolicy(any(NetworkPolicy.class)); + aaiCreateTasks.createNetworkPolicies(execution); + verify(aaiNetworkResources, times(2)).createNetworkPolicy(networkPolicyCaptor.capture()); + assertEquals("ABC123", networkPolicyCaptor.getAllValues().get(0).getNetworkPolicyFqdn()); + assertEquals("ED456", networkPolicyCaptor.getAllValues().get(1).getNetworkPolicyFqdn()); + assertEquals("testHeatStackId", networkPolicyCaptor.getAllValues().get(0).getHeatStackId()); + assertEquals("testHeatStackId", networkPolicyCaptor.getAllValues().get(1).getHeatStackId()); + } + + @Test + public void createNetworkPolicyNeedToCreateNoneTest() throws Exception { + execution.setVariable("heatStackId", "testHeatStackId"); + execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123"); + NetworkPolicy networkPolicy = new NetworkPolicy(); + doReturn(Optional.of(networkPolicy)).when(aaiNetworkResources).getNetworkPolicy(any(AAIResourceUri.class)); + doNothing().when(aaiNetworkResources).createNetworkPolicy(any(NetworkPolicy.class)); + aaiCreateTasks.createNetworkPolicies(execution); + verify(aaiNetworkResources, times(0)).createNetworkPolicy(any(NetworkPolicy.class)); + } + + @Test + public void createNetworkPolicyNoNetworkPoliciesTest() throws Exception { + execution.setVariable("heatStackId", "testHeatStackId"); + aaiCreateTasks.createNetworkPolicies(execution); + verify(aaiNetworkResources, times(0)).createNetworkPolicy(any(NetworkPolicy.class)); + } + + @Test + public void createVfModuleGetLowestIndexTest() throws Exception { + GenericVnf vnf = new GenericVnf(); + ModelInfoGenericVnf vnfInfo = new ModelInfoGenericVnf(); + vnf.setModelInfoGenericVnf(vnfInfo); + vnfInfo.setModelInvariantUuid("my-uuid"); + + ModelInfoVfModule infoA = new ModelInfoVfModule(); + infoA.setIsBaseBoolean(false); + infoA.setModelInvariantUUID("A"); + + ModelInfoVfModule infoB = new ModelInfoVfModule(); + infoB.setIsBaseBoolean(false); + infoB.setModelInvariantUUID("B"); + + ModelInfoVfModule infoC = new ModelInfoVfModule(); + infoC.setIsBaseBoolean(false); + infoC.setModelInvariantUUID("C"); + + VfModule newVfModuleA = new VfModule(); + newVfModuleA.setVfModuleId("a"); + VfModule newVfModuleB = new VfModule(); + newVfModuleB.setVfModuleId("b"); + VfModule newVfModuleC = new VfModule(); + newVfModuleC.setVfModuleId("c"); + + VfModule vfModule = new VfModule(); + vnf.getVfModules().add(vfModule); + vfModule.setVfModuleId("1"); + + VfModule vfModule2 = new VfModule(); + vnf.getVfModules().add(vfModule2); + vfModule2.setVfModuleId("2"); + + VfModule vfModule3 = new VfModule(); + vnf.getVfModules().add(vfModule3); + vfModule3.setVfModuleId("3"); + + VfModule vfModule4 = new VfModule(); + vnf.getVfModules().add(vfModule4); + vfModule4.setVfModuleId("4"); + + VfModule vfModule5 = new VfModule(); + vnf.getVfModules().add(vfModule5); + vfModule5.setVfModuleId("5"); + + //modules are included in the vnf already + vnf.getVfModules().add(newVfModuleA); + vnf.getVfModules().add(newVfModuleB); + vnf.getVfModules().add(newVfModuleC); + + //A + newVfModuleA.setModelInfoVfModule(infoA); + vfModule.setModelInfoVfModule(infoA); + vfModule2.setModelInfoVfModule(infoA); + vfModule3.setModelInfoVfModule(infoA); + + //B + + newVfModuleB.setModelInfoVfModule(infoB); + vfModule4.setModelInfoVfModule(infoB); + vfModule5.setModelInfoVfModule(infoB); + + //C + newVfModuleC.setModelInfoVfModule(infoC); + + + //A + vfModule.setModuleIndex(2); + vfModule2.setModuleIndex(0); + vfModule3.setModuleIndex(3); + + //B + vfModule4.setModuleIndex(null); + vfModule5.setModuleIndex(1); + + assertEquals(1, aaiCreateTasks.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, newVfModuleA)); + + assertEquals(2, aaiCreateTasks.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, newVfModuleB)); + + assertEquals(0, aaiCreateTasks.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, newVfModuleC)); + + } + + @Test + public void calculateUnusedIndexTest() { + + TreeSet<Integer> a = new TreeSet<>(Arrays.asList(0,1,3)); + TreeSet<Integer> b = new TreeSet<>(Arrays.asList(0,1,8)); + TreeSet<Integer> c = new TreeSet<>(Arrays.asList(0,2,4)); + assertEquals(2, aaiCreateTasks.calculateUnusedIndex(a, 0)); + assertEquals(5, aaiCreateTasks.calculateUnusedIndex(a, 2)); + + assertEquals(4, aaiCreateTasks.calculateUnusedIndex(b, 2)); + assertEquals(3, aaiCreateTasks.calculateUnusedIndex(b, 1)); + + assertEquals(5, aaiCreateTasks.calculateUnusedIndex(c, 2)); + assertEquals(9, aaiCreateTasks.calculateUnusedIndex(c, 6)); + assertEquals(1, aaiCreateTasks.calculateUnusedIndex(c, 0)); + + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java index 67f5d197de..5cb775180e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java @@ -20,22 +20,26 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.List; +import java.util.Optional; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; +import org.mockito.Captor; import org.mockito.InjectMocks; +import org.onap.aai.domain.yang.NetworkPolicy; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; @@ -46,6 +50,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.exception.BBObjectNotFoundException; @@ -62,6 +67,9 @@ public class AAIDeleteTasksTest extends BaseTaskTest { private CloudRegion cloudRegion; private Configuration configuration; + @Captor + ArgumentCaptor<String> stringCaptor; + @Before public void before() throws BBObjectNotFoundException { serviceInstance = setServiceInstance(); @@ -179,4 +187,34 @@ public class AAIDeleteTasksTest extends BaseTaskTest { aaiDeleteTasks.deleteConfiguration(execution); verify(aaiConfigurationResources, times(1)).deleteConfiguration(configuration); } + + @Test + public void deleteNetworkPolicyNeedToDeleteAllTest() throws Exception { + execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123,DEF456"); + NetworkPolicy networkPolicy0 = new NetworkPolicy(); + networkPolicy0.setNetworkPolicyId("testNetworkPolicyId0"); + NetworkPolicy networkPolicy1 = new NetworkPolicy(); + networkPolicy1.setNetworkPolicyId("testNetworkPolicyId1"); + doReturn(Optional.of(networkPolicy0),Optional.of(networkPolicy1)).when(aaiNetworkResources).getNetworkPolicy(any(AAIResourceUri.class)); + doNothing().when(aaiNetworkResources).deleteNetworkPolicy(any(String.class)); + aaiDeleteTasks.deleteNetworkPolicies(execution); + verify(aaiNetworkResources, times(2)).deleteNetworkPolicy(stringCaptor.capture()); + assertEquals("testNetworkPolicyId0", stringCaptor.getAllValues().get(0)); + assertEquals("testNetworkPolicyId1", stringCaptor.getAllValues().get(1)); + } + + @Test + public void deleteNetworkPolicyNeedToDeleteNoneTest() throws Exception { + execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123"); + Optional<NetworkPolicy> networkPolicy = Optional.empty(); + doReturn(networkPolicy).when(aaiNetworkResources).getNetworkPolicy(any(AAIResourceUri.class)); + aaiDeleteTasks.deleteNetworkPolicies(execution); + verify(aaiNetworkResources, times(0)).deleteNetworkPolicy(any(String.class)); + } + + @Test + public void deleteNetworkPolicyNoNetworkPoliciesTest() throws Exception { + aaiDeleteTasks.deleteNetworkPolicies(execution); + verify(aaiNetworkResources, times(0)).deleteNetworkPolicy(any(String.class)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index f97b137fb3..73d7257632 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -586,4 +586,49 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE); } + @Test + public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception { + execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn"); + doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf); + + aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution); + + verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf); + assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn()); + } + @Test + public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception { + aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution); + verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf); + } + @Test + public void updateIpv4OamAddressVnfTest() throws Exception { + execution.setVariable("oamManagementV4Address", "newIpv4OamAddress"); + doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf); + + aaiUpdateTasks.updateIpv4OamAddressVnf(execution); + + verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf); + assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress()); + } + @Test + public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception { + aaiUpdateTasks.updateIpv4OamAddressVnf(execution); + verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf); + } + @Test + public void updateManagementV6AddressVnfTest() throws Exception { + execution.setVariable("oamManagementV6Address", "newManagementV6Address"); + doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf); + + aaiUpdateTasks.updateManagementV6AddressVnf(execution); + + verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf); + assertEquals("newManagementV6Address", genericVnf.getManagementV6Address()); + } + @Test + public void updateManagementV6AddressVnfNoUpdateTest() throws Exception { + aaiUpdateTasks.updateManagementV6AddressVnf(execution); + verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java index 2ba8cb4b57..516c9480ad 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java @@ -1,11 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.adapter.network.tasks; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertThat; + import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import javax.xml.bind.JAXBException; import org.junit.Test; import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; public class NetworkAdapterRestV1Test { @@ -16,4 +42,17 @@ public class NetworkAdapterRestV1Test { String returnedXml = response.toXmlString(); System.out.println(returnedXml); } + + @Test + public void testUnmarshalXmlUpdate() throws IOException, JAXBException { + UpdateNetworkResponse expectedResponse = new UpdateNetworkResponse(); + expectedResponse.setMessageId("ec100bcc-2659-4aa4-b4d8-3255715c2a51"); + expectedResponse.setNetworkId("80de31e3-cc78-4111-a9d3-5b92bf0a39eb"); + Map<String,String>subnetMap = new HashMap<String,String>(); + subnetMap.put("95cd8437-25f1-4238-8720-cbfe7fa81476", "d8d16606-5d01-4822-b160-9a0d257303e0"); + expectedResponse.setSubnetMap(subnetMap); + String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><updateNetworkResponse><messageId>ec100bcc-2659-4aa4-b4d8-3255715c2a51</messageId><networkId>80de31e3-cc78-4111-a9d3-5b92bf0a39eb</networkId><subnetMap><entry><key>95cd8437-25f1-4238-8720-cbfe7fa81476</key><value>d8d16606-5d01-4822-b160-9a0d257303e0</value></entry></subnetMap></updateNetworkResponse>"; + UpdateNetworkResponse response = (UpdateNetworkResponse) new NetworkAdapterRestV1().unmarshalXml(xml, UpdateNetworkResponse.class); + assertThat(expectedResponse, sameBeanAs(response)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java index 4158f9cfae..33d0dbe130 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.adapter.vnf.tasks; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -35,6 +36,7 @@ import org.mockito.InjectMocks; import org.onap.so.FileUtil; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; @@ -50,6 +52,7 @@ public class VnfAdapterImplTest extends BaseTaskTest { private RequestContext requestContext; private ServiceInstance serviceInstance; + private GenericVnf genericVnf; private VfModule vfModule; private VolumeGroup volumeGroup; @@ -58,12 +61,17 @@ public class VnfAdapterImplTest extends BaseTaskTest { private static final String VNF_ADAPTER_VOLUME_CREATE_RESPONSE = FileUtil.readResourceFile("__files/VfModularity/CreateVfModuleVolumeCallbackResponse.xml"); private static final String VNF_ADAPTER_VOLUME_DELETE_RESPONSE = FileUtil.readResourceFile("__files/VfModularity/DeleteVfModuleVolumeCallbackResponse.xml"); private static final String TEST_VFMODULE_HEATSTACK_ID = "slowburn"; - private static final String TEST_VOLUME_HEATSTACK_ID = "testHeatStackId1"; + private static final String TEST_VOLUME_HEATSTACK_ID = "testHeatStackId1"; + private static final String TEST_CONTRAIL_SERVICE_INSTANCE_FQDN = "default-domain:MSOTest:MsoNW-RA"; + private static final String TEST_OAM_MANAGEMENT_V4_ADDRESS = "127.0.0.1"; + private static final String TEST_OAM_MANAGEMENT_V6_ADDRESS = "2000:abc:bce:1111"; + private static final String TEST_CONTRAIL_NETWORK_POLICY_FQDNS = "MSOTest:DefaultPolicyFQDN2,MSOTest:DefaultPolicyFQDN1"; @Before public void before() throws BBObjectNotFoundException { requestContext = setRequestContext(); serviceInstance = setServiceInstance(); + genericVnf = setGenericVnf(); vfModule = setVfModule(); volumeGroup = setVolumeGroup(); vfModule.setHeatStackId(null); @@ -72,6 +80,7 @@ public class VnfAdapterImplTest extends BaseTaskTest { doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance); when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf); when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule); } @@ -86,8 +95,15 @@ public class VnfAdapterImplTest extends BaseTaskTest { @Test public void postProcessVnfAdapter_CreateResponseTest() { execution.setVariable("vnfAdapterRestV1Response", VNF_ADAPTER_REST_CREATE_RESPONSE); - vnfAdapterImpl.postProcessVnfAdapter(execution); + vnfAdapterImpl.postProcessVnfAdapter(execution); assertEquals(TEST_VFMODULE_HEATSTACK_ID, vfModule.getHeatStackId()); + assertEquals(TEST_CONTRAIL_SERVICE_INSTANCE_FQDN, vfModule.getContrailServiceInstanceFqdn()); + assertEquals(TEST_CONTRAIL_SERVICE_INSTANCE_FQDN, execution.getVariable("contrailServiceInstanceFqdn")); + assertEquals(TEST_OAM_MANAGEMENT_V4_ADDRESS, genericVnf.getIpv4OamAddress()); + assertEquals(TEST_OAM_MANAGEMENT_V4_ADDRESS, execution.getVariable("oamManagementV4Address")); + assertEquals(TEST_OAM_MANAGEMENT_V6_ADDRESS, genericVnf.getManagementV6Address()); + assertEquals(TEST_OAM_MANAGEMENT_V6_ADDRESS, execution.getVariable("oamManagementV6Address")); + assertEquals(TEST_CONTRAIL_NETWORK_POLICY_FQDNS, execution.getVariable("contrailNetworkPolicyFqdnList")); } @@ -111,6 +127,20 @@ public class VnfAdapterImplTest extends BaseTaskTest { vnfAdapterImpl.postProcessVnfAdapter(execution); assertNull(vfModule.getHeatStackId()); } + + @Test + public void postProcessVnfAdapter_CreateResponseTest_EmptyVfModuleOutputs() { + execution.setVariable("vnfAdapterRestV1Response", "<createVfModuleResponse><vfModuleOutputs></vfModuleOutputs></createVfModuleResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + assertNull(vfModule.getContrailServiceInstanceFqdn()); + assertNull(execution.getVariable("contrailServiceInstanceFqdn")); + assertNotEquals(TEST_OAM_MANAGEMENT_V4_ADDRESS, genericVnf.getIpv4OamAddress()); + assertNull(execution.getVariable("oamManagementV4Address")); + assertNull(genericVnf.getManagementV6Address()); + assertNull(execution.getVariable("oamManagementV6Address")); + assertNull(execution.getVariable("contrailNetworkPolicyFqdnList")); + } @Test public void postProcessVnfAdapter_DeleteResponseTest() { @@ -118,6 +148,25 @@ public class VnfAdapterImplTest extends BaseTaskTest { execution.setVariable("vnfAdapterRestV1Response", VNF_ADAPTER_REST_DELETE_RESPONSE); vnfAdapterImpl.postProcessVnfAdapter(execution); assertNull(vfModule.getHeatStackId()); + assertEquals(vfModule.getContrailServiceInstanceFqdn(), ""); + assertEquals(execution.getVariable("contrailServiceInstanceFqdn"), ""); + assertEquals(genericVnf.getIpv4OamAddress(), ""); + assertEquals(execution.getVariable("oamManagementV4Address"), ""); + assertEquals(genericVnf.getManagementV6Address(), ""); + assertEquals(execution.getVariable("oamManagementV6Address"), ""); + assertEquals(TEST_CONTRAIL_NETWORK_POLICY_FQDNS, execution.getVariable("contrailNetworkPolicyFqdnList")); + } + + @Test + public void postProcessVnfAdapter_DeleteResponseTest_EmptyVfModuleOutputs() { + execution.setVariable("vnfAdapterRestV1Response", "<createVfModuleResponse><vfModuleOutputs></vfModuleOutputs></createVfModuleResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + assertNull(vfModule.getContrailServiceInstanceFqdn()); + assertNull(execution.getVariable("contrailServiceInstanceFqdn")); + assertNull(execution.getVariable("oamManagementV4Address")); + assertNull(execution.getVariable("oamManagementV6Address")); + assertNull(execution.getVariable("contrailNetworkPolicyFqdnList")); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.java new file mode 100644 index 0000000000..7a9e2bb6cf --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/audit/AuditTasksTest.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.audit; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.onap.so.audit.beans.AuditInventory; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.exception.BBObjectNotFoundException; + +public class AuditTasksTest extends BaseTaskTest{ + + @InjectMocks + private AuditTasks auditTasks = new AuditTasks(); + private ServiceInstance serviceInstance; + private GenericVnf genericVnf; + private VfModule vfModule; + + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Before + public void before() throws BBObjectNotFoundException { + serviceInstance = setServiceInstance(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + setCloudRegion(); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance); + } + + @Test + public void setupAuditVariableTest() throws Exception { + AuditInventory expectedAuditInventory = new AuditInventory(); + expectedAuditInventory.setCloudOwner("testCloudOwner"); + expectedAuditInventory.setCloudRegion("testLcpCloudRegionId"); + expectedAuditInventory.setHeatStackName("testVfModuleName1"); + expectedAuditInventory.setTenantId("testTenantId"); + auditTasks.setupAuditVariable(execution); + assertThat((AuditInventory)execution.getVariable("auditInventory"), sameBeanAs(expectedAuditInventory)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java new file mode 100644 index 0000000000..d1d167e561 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ActivateVfModuleTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.flowspecific.tasks; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.BaseTaskTest; + +public class ActivateVfModuleTest extends BaseTaskTest { + + @InjectMocks + private ActivateVfModule activateVfModule = new ActivateVfModule(); + + @Test + public void setWaitBeforeDurationTest() throws Exception { + when(env.getProperty(ActivateVfModule.VF_MODULE_TIMER_DURATION_PATH, ActivateVfModule.DEFAULT_TIMER_DURATION)).thenReturn("PT300S"); + activateVfModule.setTimerDuration(execution); + verify(env, times(1)).getProperty(ActivateVfModule.VF_MODULE_TIMER_DURATION_PATH, ActivateVfModule.DEFAULT_TIMER_DURATION); + assertEquals("PT300S", (String) execution.getVariable("vfModuleActivateTimerDuration")); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java index e17859969d..7fdf2535bf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java @@ -35,6 +35,7 @@ import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; @@ -142,4 +143,34 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest { genericVnfHealthCheck.callAppcClient(execution); verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); } + + @Test + @Ignore //The runAppCCommand method in not capable of throwing this exception + public void callAppcClientTimeOutExceptionTest() { + expectedException.expect(java.util.concurrent.TimeoutException.class); + Action action = Action.HealthCheck; + String vnfId = genericVnf.getVnfId(); + String payload = "{\"testName\":\"testValue\",}"; + String controllerType = "testType"; + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("vnfName", "testVnfName"); + payloadInfo.put("vfModuleId", "testVfModuleId"); + payloadInfo.put("oamIpAddress", "testOamIpAddress"); + payloadInfo.put("vnfHostIpAddress", "testOamIpAddress"); + execution.setVariable("action", Action.HealthCheck.toString()); + execution.setVariable("msoRequestId", msoRequestId); + execution.setVariable("controllerType", controllerType); + execution.setVariable("vnfId", "testVnfId1"); + execution.setVariable("vnfName", "testVnfName"); + execution.setVariable("vfModuleId", "testVfModuleId"); + execution.setVariable("oamIpAddress", "testOamIpAddress"); + execution.setVariable("vnfHostIpAddress", "testOamIpAddress"); + execution.setVariable("payload", payload); + + doThrow(java.util.concurrent.TimeoutException.class).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + + + genericVnfHealthCheck.callAppcClient(execution); + verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index f0bb6a369c..59fad5cdd6 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -84,7 +84,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ requestContext.setMsoRequestId("testRequestId"); RequestParameters params = new RequestParameters(); params.setaLaCarte(false); - params.setSubscriptionServiceType("iptollfree"); + params.setSubscriptionServiceType("testSubscriptionServiceType"); requestContext.setRequestParameters(params); } @@ -94,10 +94,10 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ bondingLink.getServiceProxies().add(setServiceProxy("1", "transport")); ServiceProxy sp2 = setServiceProxy("2", "infrastructure"); Candidate requiredCandidate = new Candidate(); - requiredCandidate.setCandidateType(CandidateType.VNF_ID); + requiredCandidate.setIdentifierType(CandidateType.VNF_ID); List<String> c = new ArrayList<String>(); c.add("testVnfId"); - requiredCandidate.setCandidates(c); + requiredCandidate.setIdentifiers(c); sp2.addRequiredCandidates(requiredCandidate); bondingLink.getServiceProxies().add(sp2); serviceInstance.getVpnBondingLinks().add(bondingLink); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java index 1da8a183a6..688f95c3c0 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java @@ -22,7 +22,7 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java index a8d7eb3d2e..3cf003d1ad 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasksTest.java @@ -21,7 +21,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java new file mode 100644 index 0000000000..03b39f57e5 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorUnitTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.workflow.tasks; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.db.catalog.beans.BuildingBlockDetail; +import org.onap.so.db.catalog.beans.OrchestrationAction; +import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective; +import org.onap.so.db.catalog.beans.ResourceType; +import org.onap.so.db.catalog.client.CatalogDbClient; + +@RunWith(MockitoJUnitRunner.class) +public class OrchestrationStatusValidatorUnitTest { + + @Mock + private CatalogDbClient catalogDbClient; + + @InjectMocks + private OrchestrationStatusValidator validator; + @Test + public void skipValidationTest() { + BuildingBlockDetail bbDetail = new BuildingBlockDetail(); + bbDetail.setBuildingBlockName("customBB"); + bbDetail.setResourceType(ResourceType.NO_VALIDATE); + bbDetail.setTargetAction(OrchestrationAction.CUSTOM); + when(catalogDbClient.getBuildingBlockDetail("customBB")).thenReturn(bbDetail); + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + execution.setVariable("flowToBeCalled", "customBB"); + execution.setVariable("aLaCarte", false); + validator.validateOrchestrationStatus(execution); + + + assertThat(execution.getVariable("orchestrationStatusValidationResult"), equalTo(OrchestrationStatusValidationDirective.VALIDATION_SKIPPED)); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 7b348c8cb3..24b87277c4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -37,9 +37,11 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.Set; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -70,6 +72,8 @@ import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResource; import org.onap.so.db.catalog.beans.CollectionResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.ConfigurationResource; +import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.HeatEnvironment; import org.onap.so.db.catalog.beans.HeatTemplate; import org.onap.so.db.catalog.beans.InstanceGroup; @@ -77,6 +81,7 @@ import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; import org.onap.so.serviceinstancebeans.RequestDetails; @@ -854,6 +859,63 @@ public class WorkflowActionTest extends BaseTaskTest { ,"DeleteNetworkCollectionBB"); } + @Test + public void selectExecutionListALaCarteVfModuleNoFabricCreateTest() throws Exception{ + String gAction = "createInstance"; + String resource = "VfModule"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction,resource,true,"my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEqualsBulkFlowName(ebbs,"AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB"); + } + + @Test + public void selectExecutionListALaCarteVfModuleFabricCreateTest() throws Exception{ + String gAction = "createInstance"; + String resource = "VfModule"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + List<CvnfcCustomization> cvnfcCustomizations = new ArrayList<CvnfcCustomization>(); + CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); + VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = new VnfVfmoduleCvnfcConfigurationCustomization(); + ConfigurationResource configurationResource = new ConfigurationResource(); + configurationResource.setToscaNodeType("FabricConfiguration"); + vnfVfmoduleCvnfcConfigurationCustomization.setConfigurationResource(configurationResource); + Set<VnfVfmoduleCvnfcConfigurationCustomization> custSet = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>(); + custSet.add(vnfVfmoduleCvnfcConfigurationCustomization); + cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(custSet); + cvnfcCustomizations.add(cvnfcCustomization); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction,resource,true,"my-custom-cloud-owner")).thenReturn(northBoundRequest); + when(catalogDbClient.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID("fc25201d-36d6-43a3-8d39-fdae88e526ae", "9a6d01fd-19a7-490a-9800-460830a12e0b")).thenReturn(cvnfcCustomizations); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEqualsBulkFlowName(ebbs,"AssignVfModuleBB","CreateVfModuleBB","ActivateVfModuleBB","AssignFabricConfigurationBB","ActivateFabricConfigurationBB"); + } + /** * WorkflowActionBB Tests */ diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java index 297d75a104..2dd4033aa2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionUnitTest.java @@ -57,6 +57,10 @@ import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RelatedInstance; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @RunWith(MockitoJUnitRunner.class) public class WorkflowActionUnitTest { @@ -87,9 +91,16 @@ public class WorkflowActionUnitTest { "flow y", "ActivateFabricConfigurationBB", "flow z"); - doReturn(Arrays.asList("yes", "yes")).when(workflowAction).traverseCatalogDbForConfiguration(ArgumentMatchers.isNull(), ArgumentMatchers.isNull()); + doReturn(Arrays.asList("yes", "yes")).when(workflowAction).traverseCatalogDbForConfiguration(ArgumentMatchers.any(String.class), ArgumentMatchers.isNull()); - List<OrchestrationFlow> result = workflowAction.filterOrchFlows(flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); + ServiceInstancesRequest sIRequest = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + ModelInfo modelInfo = new ModelInfo(); + requestDetails.setModelInfo(modelInfo); + RelatedInstance relatedInstance = new RelatedInstance(); + sIRequest.setRequestDetails(requestDetails); + + List<OrchestrationFlow> result = workflowAction.filterOrchFlows(sIRequest, flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); assertThat(result, is(flows)); } @@ -103,7 +114,14 @@ public class WorkflowActionUnitTest { "ActivateFabricConfigurationBB", "flow z"); - List<OrchestrationFlow> result = workflowAction.filterOrchFlows(flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); + ServiceInstancesRequest sIRequest = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationUuid(""); + requestDetails.setModelInfo(modelInfo); + sIRequest.setRequestDetails(requestDetails); + + List<OrchestrationFlow> result = workflowAction.filterOrchFlows(sIRequest, flows, WorkflowType.VFMODULE, mock(DelegateExecution.class)); List<OrchestrationFlow> expected = createFlowList( "flow x", "flow y", @@ -147,7 +165,7 @@ public class WorkflowActionUnitTest { doReturn(Arrays.asList(flow)).when(workflowAction).queryNorthBoundRequestCatalogDb(any(), any(), any(), anyBoolean(), any(), any()); workflowAction.selectExecutionList(execution); - verify(workflowAction, times(1)).filterOrchFlows(eq(flows), any(), any()); + verify(workflowAction, times(1)).filterOrchFlows(any(), eq(flows), any(), any()); flow = new OrchestrationFlow(); flow.setFlowName("flow y"); @@ -155,7 +173,7 @@ public class WorkflowActionUnitTest { when(execution.getVariable(eq("aLaCarte"))).thenReturn(false); workflowAction.selectExecutionList(execution); - verify(workflowAction, never()).filterOrchFlows(eq(flows), any(), any()); + verify(workflowAction, never()).filterOrchFlows(any(), eq(flows), any(), any()); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java index 611d793166..6eb22a6dcc 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java @@ -21,7 +21,7 @@ package org.onap.so.bpmn.sdno.tasks; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java index db01399b82..a8e9a7e57e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java @@ -41,6 +41,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget; @@ -672,4 +673,21 @@ public class AAIObjectMapperTest { assertThat(actualSubnet, sameBeanAs(expectedSubnet)); } + + @Test + public void mapNetworkPolicyTest() { + NetworkPolicy networkPolicy = new NetworkPolicy(); + networkPolicy.setNetworkPolicyId("testNetworkPolicyId"); + networkPolicy.setNetworkPolicyFqdn("testNetworkPolicyFqdn"); + networkPolicy.setHeatStackId("testHeatStackId"); + + org.onap.aai.domain.yang.NetworkPolicy expectedNetworkPolicy = new org.onap.aai.domain.yang.NetworkPolicy(); + expectedNetworkPolicy.setNetworkPolicyId("testNetworkPolicyId"); + expectedNetworkPolicy.setNetworkPolicyFqdn("testNetworkPolicyFqdn"); + expectedNetworkPolicy.setHeatStackId("testHeatStackId"); + + org.onap.aai.domain.yang.NetworkPolicy actualNetworkPolicy = aaiObjectMapper.mapNetworkPolicy(networkPolicy); + + assertThat(actualNetworkPolicy, sameBeanAs(expectedNetworkPolicy)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java index 1a86d713a2..4bdbd1a846 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java @@ -22,7 +22,7 @@ package org.onap.so.client.adapter.network.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.*; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import java.io.UnsupportedEncodingException; @@ -30,6 +30,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -99,24 +100,6 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ } @Test - public void testSetNetworkTechnology() { - String networkTechnology = "Contrail"; - NetworkTechnology expectedNetworkTechnology = NetworkTechnology.CONTRAIL; - NetworkTechnology actualNetworkTechnology = SPY_networkAdapterObjectMapper.setNetworkTechnology(networkTechnology); - assertEquals("NetworkTechnology matches", expectedNetworkTechnology, actualNetworkTechnology); - - networkTechnology = "Neutron"; - expectedNetworkTechnology = NetworkTechnology.NEUTRON; - actualNetworkTechnology = SPY_networkAdapterObjectMapper.setNetworkTechnology(networkTechnology); - assertEquals("NetworkTechnology matches", expectedNetworkTechnology, actualNetworkTechnology); - - networkTechnology = "Vmware"; - expectedNetworkTechnology = NetworkTechnology.VMWARE; - actualNetworkTechnology = SPY_networkAdapterObjectMapper.setNetworkTechnology(networkTechnology); - assertEquals("NetworkTechnology matches", expectedNetworkTechnology, actualNetworkTechnology); - - } - @Test public void buildCreateNetworkRequestFromBbobjectTest() throws Exception { String cloudRegionPo = "cloudRegionPo"; @@ -129,12 +112,17 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ expectedCreateNetworkRequest.setNetworkType(l3Network.getNetworkType()); expectedCreateNetworkRequest.setBackout(false); expectedCreateNetworkRequest.setFailIfExists(true); - expectedCreateNetworkRequest.setNetworkTechnology(NetworkTechnology.CONTRAIL); + expectedCreateNetworkRequest.setNetworkTechnology("CONTRAIL"); MsoRequest msoRequest = new MsoRequest(); msoRequest.setRequestId(requestContext.getMsoRequestId()); msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); expectedCreateNetworkRequest.setMsoRequest(msoRequest); expectedCreateNetworkRequest.setSkipAAI(true); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "true"); + networkParams.put("external", "false"); + networkParams.put("testUserInputKey", "testUserInputValue"); + expectedCreateNetworkRequest.setNetworkParams(networkParams); expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); @@ -148,13 +136,15 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ subnetList.add(openstackSubnet); l3Network.getSubnets().add(openstackSubnet); l3Network.setNetworkTechnology("Contrail"); + l3Network.setIsSharedNetwork(true); + l3Network.setIsExternalNetwork(false); doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); - assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest").ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("networkParams").ignoring("messageId")); + assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest").ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("messageId")); } @Test @@ -243,6 +233,12 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ l3Network.getSubnets().add(actualSubnet); l3Network.getNetworkPolicies().add(networkPolicy); l3Network.getContrailNetworkRouteTableReferences().add(routeTableReference); + l3Network.setIsSharedNetwork(false); + l3Network.setIsExternalNetwork(false); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "false"); + networkParams.put("external", "false"); + networkParams.put("testUserInputKey", "testUserInputValue"); UpdateNetworkRequest expectedUpdateNetworkRequest = new UpdateNetworkRequest(); expectedUpdateNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); @@ -256,7 +252,7 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ expectedUpdateNetworkRequest.setSubnets(subnets); expectedUpdateNetworkRequest.setProviderVlanNetwork(providerVlanNetwork); expectedUpdateNetworkRequest.setContrailNetwork(contrailNetwork); - expectedUpdateNetworkRequest.setNetworkParams(userInput); + expectedUpdateNetworkRequest.setNetworkParams(networkParams); expectedUpdateNetworkRequest.setMsoRequest(msoRequest); expectedUpdateNetworkRequest.setSkipAAI(true); expectedUpdateNetworkRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled())); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java index 99e76450af..339e9cbf17 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java @@ -230,7 +230,16 @@ public class VnfAdapterObjectMapperTest { } @Test - public void test_deleteVolumeGroupRequestMapper() throws Exception { + public void test_deleteVolumeGroupHeatIdRequestMapper() throws Exception{ + this.test_deleteVolumeGroupRequestMapper("heatStackId"); + } + + @Test + public void test_deleteVolumeGroupNoHeatIdRequestMapper() throws Exception{ + this.test_deleteVolumeGroupRequestMapper(null); + } + + private void test_deleteVolumeGroupRequestMapper(String heatStackId) throws Exception { DeleteVolumeGroupRequest expectedDeleteVolumeGroupRequest = new DeleteVolumeGroupRequest(); CloudRegion cloudRegion = new CloudRegion(); @@ -244,8 +253,13 @@ public class VnfAdapterObjectMapperTest { volumeGroup.setVolumeGroupId("volumeGroupId"); expectedDeleteVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId()); - volumeGroup.setHeatStackId("heatStackId"); - expectedDeleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId()); + if (heatStackId != null){ + volumeGroup.setHeatStackId("heatStackId"); + expectedDeleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId()); + } else { + volumeGroup.setVolumeGroupName("volumeGroupName"); + expectedDeleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getVolumeGroupName()); + } expectedDeleteVolumeGroupRequest.setSkipAAI(true); @@ -269,7 +283,7 @@ public class VnfAdapterObjectMapperTest { assertThat(actualDeleteVolumeGroupRequest, sameBeanAs(expectedDeleteVolumeGroupRequest)); } - + @Test @Ignore public void test_createVolumeGroupParams() throws Exception { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java index 32a495e094..a156c382d1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java @@ -845,7 +845,7 @@ public class VnfAdapterVfModuleObjectMapperPayloadTest { jsonToCompare, DeleteVfModuleRequest.class); - assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl")); + assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl").ignoring("vfModuleStackId")); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java index c8f4a222f3..160feed426 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java @@ -20,19 +20,38 @@ package org.onap.so.client.adapter.vnf.mapper; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.junit.Before; import org.junit.Test; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.entity.MsoRequest; -public class VnfAdapterVfModuleObjectMapperTest{ +public class VnfAdapterVfModuleObjectMapperTest { + @Spy private VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + } @Test public void createVnfcSubInterfaceKeyTest() { @@ -64,4 +83,42 @@ public class VnfAdapterVfModuleObjectMapperTest{ } + @Test + public void test_deleteVfModuleNoHeatIdRequestMapper() throws Exception { + DeleteVfModuleRequest expectedDeleteVfModuleRequest = new DeleteVfModuleRequest(); + + CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setLcpCloudRegionId("lcpCloudRegionId"); + expectedDeleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + + cloudRegion.setTenantId("tenantId"); + expectedDeleteVfModuleRequest.setTenantId(cloudRegion.getTenantId()); + + GenericVnf genericVnf = new GenericVnf(); + VfModule vfModule = new VfModule(); + vfModule.setHeatStackId("heatStackId"); + expectedDeleteVfModuleRequest.setVfModuleStackId("heatStackId"); + expectedDeleteVfModuleRequest.setSkipAAI(true); + + MsoRequest msoRequest = new MsoRequest(); + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("msoRequestId"); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedDeleteVfModuleRequest.setMsoRequest(msoRequest); + + String messageId = "messageId"; + String endpoint = "endpoint"; + doNothing().when(mapper).setIdAndUrl(any()); + expectedDeleteVfModuleRequest.setMessageId(messageId); + expectedDeleteVfModuleRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId); + + DeleteVfModuleRequest actualDeleteVfModuleRequest = mapper.deleteVfModuleRequestMapper(requestContext, cloudRegion, + serviceInstance, genericVnf, vfModule); + + assertThat(actualDeleteVfModuleRequest, sameBeanAs(expectedDeleteVfModuleRequest).ignoring("messageId").ignoring("notificationUrl")); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java index 11e542be7b..8bf3de5c4e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java @@ -21,7 +21,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java index 8b16964ab5..a38c8be686 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java @@ -21,7 +21,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java index e19458f21d..10bbf39823 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java @@ -20,7 +20,7 @@ package org.onap.so.client.orchestration; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java index f20c646657..2e2cc5d974 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java @@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -45,7 +45,6 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.aai.domain.yang.NetworkPolicy; import org.onap.aai.domain.yang.RouteTableReference; import org.onap.aai.domain.yang.VpnBinding; import org.onap.so.bpmn.common.InjectionHelper; @@ -54,6 +53,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.client.aai.AAIObjectType; @@ -77,6 +77,7 @@ public class AAINetworkResourcesTest extends TestDataSetup{ private ServiceInstance serviceInstance; private CloudRegion cloudRegion; private Subnet subnet; + private NetworkPolicy networkPolicy; @Mock protected AAIResourcesClient MOCK_aaiResourcesClient; @@ -107,6 +108,8 @@ public class AAINetworkResourcesTest extends TestDataSetup{ subnet = buildSubnet(); + networkPolicy = buildNetworkPolicy(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); } @@ -175,16 +178,15 @@ public class AAINetworkResourcesTest extends TestDataSetup{ public void getNetworkPolicyTest() throws Exception { final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiNetworkPolicy.json"))); AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); - Optional<NetworkPolicy> oNetPolicy = Optional.empty(); + Optional<org.onap.aai.domain.yang.NetworkPolicy> oNetPolicy = Optional.empty(); AAIResourceUri netPolicyUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, "ModelInvariantUUID"); doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); oNetPolicy = aaiNetworkResources.getNetworkPolicy(netPolicyUri); - verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class)); - + verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class)); if (oNetPolicy.isPresent()) { - NetworkPolicy networkPolicy = oNetPolicy.get(); - assertThat(aaiResultWrapper.asBean(NetworkPolicy.class).get(), sameBeanAs(networkPolicy)); + org.onap.aai.domain.yang.NetworkPolicy networkPolicy = oNetPolicy.get(); + assertThat(aaiResultWrapper.asBean(org.onap.aai.domain.yang.NetworkPolicy.class).get(), sameBeanAs(networkPolicy)); } } @@ -357,4 +359,20 @@ public class AAINetworkResourcesTest extends TestDataSetup{ assertThat(aaiResultWrapper.asBean(org.onap.aai.domain.yang.Subnet.class).get(), sameBeanAs(subnet)); } } + + @Test + public void createNetworkPolicyTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.NetworkPolicy.class)); + doReturn(new org.onap.aai.domain.yang.NetworkPolicy()).when(MOCK_aaiObjectMapper).mapNetworkPolicy(networkPolicy); + aaiNetworkResources.createNetworkPolicy(networkPolicy); + verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.NetworkPolicy.class)); + } + + @Test + public void deleteNetworkPolicyTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + aaiNetworkResources.deleteNetworkPolicy(networkPolicy.getNetworkPolicyId()); + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java index 0a8e7ce349..a8200caf79 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java @@ -138,4 +138,17 @@ public class AAIVfModuleResourcesTest extends TestDataSetup{ assertEquals("testHeatStackId", vfModule.getHeatStackId()); } + + @Test + public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception { + vfModule.setContrailServiceInstanceFqdn("testContrailServiceInstanceFqdn"); + + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class)); + + aaiVfModuleResources.updateContrailServiceInstanceFqdnVfModule(vfModule, vnf); + + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class),ArgumentMatchers.isNull()); + + assertEquals("testContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn()); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java index c28bc05dcb..b87b5e4166 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java @@ -22,7 +22,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java index 77e56751d4..c50b084df2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java @@ -22,7 +22,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java index 44263fa3f5..46d87c7ca3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java @@ -21,7 +21,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.ArgumentMatchers.any; diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/createNetworkRequest.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/createNetworkRequest.json index a9cef565df..d7e282dda7 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/createNetworkRequest.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/createNetworkRequest.json @@ -13,9 +13,13 @@ "cidr": "107.244.64.2/20", "gatewayIp": "107.244.64.1", "ipVersion": "4", - "enableDHCP": false, + "enableDHCP": true, "addrFromStart": true, - "hostRoutes": [] + "hostRoutes": [], + "allocationPools": [{ + "start": "107.244.64.2", + "end": "107.244.64.16" + }] } ], "providerVlanNetwork": { diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/generalBB.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/generalBB.json index 6c6981b96a..e0b3bc4ff9 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/generalBB.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/generalBB.json @@ -64,9 +64,9 @@ "cidr-mask" : "20", "ip-version" : "4", "orchestration-status" : null, - "dhcp-enabled" : false, - "dhcp-start" : "", - "dhcp-end" : "", + "dhcp-enabled" : true, + "dhcp-start" : "107.244.64.2", + "dhcp-end" : "107.244.64.16", "subnet-role" : "", "ip-assignment-direction" : "true", "subnet-sequence" : null, diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json index b65203b24d..83ecd6add1 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json @@ -42,13 +42,13 @@ "modelInvariantId" : "testProxyModelInvariantUuid2" }, "requiredCandidates" : [ { - "candidateType" : { + "identifierType" : { "name" : "vnfId" }, - "candidates" : [ "testVnfId" ] + "identifiers" : [ "testVnfId" ] } ] } ], - "requestParameters" : {"subscriptionServiceType":"iptollfree","aLaCarte":false} + "requestParameters" : {"subscriptionServiceType":"testSubscriptionServiceType","aLaCarte":false} }, "licenseInfo" : { "licenseDemands" : [ ] diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json index ac460c328a..740a05d1be 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json @@ -51,7 +51,7 @@ "modelInvariantId" : "testAllottedModelInvariantUuid3" } } ], - "requestParameters" : {"subscriptionServiceType":"iptollfree","aLaCarte":false} + "requestParameters" : {"subscriptionServiceType":"testSubscriptionServiceType","aLaCarte":false} }, "licenseInfo" : { "licenseDemands" : [ ] diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json index 6db2153691..c3c5c0771a 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json @@ -42,10 +42,10 @@ "modelInvariantId" : "testProxyModelInvariantUuid2" }, "requiredCandidates" : [ { - "candidateType" : { + "identifierType" : { "name" : "vnfId" }, - "candidates" : [ "testVnfId" ] + "identifiers" : [ "testVnfId" ] } ] }, { "serviceResourceId" : "testProxyId1", @@ -66,10 +66,10 @@ "modelInvariantId" : "testProxyModelInvariantUuid2" }, "requiredCandidates" : [ { - "candidateType" : { + "identifierType" : { "name" : "vnfId" }, - "candidates" : [ "testVnfId" ] + "identifiers" : [ "testVnfId" ] } ] }, { "serviceResourceId" : "testProxyId1", @@ -90,13 +90,13 @@ "modelInvariantId" : "testProxyModelInvariantUuid2" }, "requiredCandidates" : [ { - "candidateType" : { + "identifierType" : { "name" : "vnfId" }, - "candidates" : [ "testVnfId" ] + "identifiers" : [ "testVnfId" ] } ] } ], - "requestParameters" : {"subscriptionServiceType":"iptollfree","aLaCarte":false} + "requestParameters" : {"subscriptionServiceType":"testSubscriptionServiceType","aLaCarte":false} }, "licenseInfo" : { "licenseDemands" : [ ] diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/VnfAndVfModuleMapper/vnfAdapterDeleteVfModuleRequest.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/VnfAndVfModuleMapper/vnfAdapterDeleteVfModuleRequest.json index 21e5bde3ec..1d2e7d090f 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/VnfAndVfModuleMapper/vnfAdapterDeleteVfModuleRequest.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/VnfAndVfModuleMapper/vnfAdapterDeleteVfModuleRequest.json @@ -2,7 +2,8 @@ "cloudSiteId" : "cloudRegionId", "tenantId" : "tenantId", "vnfId" : "vnfId", - "vfModuleId" : "vfModuleId", + "vfModuleId" : "vfModuleId", + "vfModuleStackId" : "vfModuleName", "skipAAI" : true, "msoRequest" : { "requestId" : "requestId", diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/VfModuleCreateWithFabric.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/VfModuleCreateWithFabric.json new file mode 100644 index 0000000000..332ad4500c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/VfModuleCreateWithFabric.json @@ -0,0 +1,65 @@ +{ + "requestDetails": { + "modelInfo": { + "modelCustomizationName": "model-cust-name", + "modelInvariantId": "db86e4a6-c027-452e-a559-3a23b3128367", + "modelType": "vfModule", + "modelName": "test-model-name", + "modelVersion": "1", + "modelCustomizationUuid": "9a6d01fd-19a7-490a-9800-460830a12e0b", + "modelVersionId": "14c8f313-fb0f-4cf6-8caf-c7cce8137b60", + "modelCustomizationId": "9a6d01fd-19a7-490a-9800-460830a12e0b", + "modelUuid": "14c8f313-fb0f-4cf6-8caf-c7cce8137b60", + "modelInvariantUuid": "db86e4a6-c027-452e-a559-3a23b3128367", + "modelInstanceName": "test-model-instance-name" + }, + "requestInfo": { + "source": "VID", + "instanceName": "instanceName", + "suppressRollback": false, + "requestorId": "user" + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "f647e3ef-6d2e-4cd3-bff4-8df4634208de", + "modelInfo": { + "modelInvariantId": "86adb376-5303-441a-b50e-96c0cd643b0f", + "modelType": "service", + "modelName": "model-name", + "modelVersion": "1.0", + "modelVersionId": "599e21ed-803d-4d1f-83df-20005339b83f", + "modelUuid": "599e21ed-803d-4d1f-83df-20005339b83f", + "modelInvariantUuid": "86adb376-5303-441a-b50e-96c0cd643b0f" + } + } + }, + { + "relatedInstance": { + "instanceId": "b80b16a5-f80d-4ffa-91c8-bd47c7438a3d", + "modelInfo": { + "modelCustomizationName": "modle-cust-name", + "modelInvariantId": "5cca9285-4ed4-4e11-a609-921ed3344811", + "modelType": "vnf", + "modelName": "modle-name", + "modelVersion": "1.0", + "modelCustomizationUuid": "fc25201d-36d6-43a3-8d39-fdae88e526ae", + "modelVersionId": "7cae703a-b20d-481a-863a-b862236c00f7", + "modelCustomizationId": "fc25201d-36d6-43a3-8d39-fdae88e526ae", + "modelUuid": "7cae703a-b20d-481a-863a-b862236c00f7", + "modelInvariantUuid": "5cca9285-4ed4-4e11-a609-921ed3344811", + "modelInstanceName": "model-inst-name" + } + } + } + ], + "cloudConfiguration": { + "tenantId": "872f331350c54e59991a8de2cbffb40c", + "cloudOwner": "my-custom-cloud-owner", + "lcpCloudRegionId": "cloud-region" + }, + "requestParameters": { + "usePreload": true + } + } +}
\ No newline at end of file |