diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
5 files changed, 55 insertions, 11 deletions
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 57dbec3ad7..e3540ecc58 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 @@ -107,8 +107,12 @@ public class AAICreateTasks { public void createServiceInstance(BuildingBlockExecution execution) { try { + Boolean alaCarte = execution.getVariable(A_LA_CARTE); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + if (Boolean.TRUE.equals(alaCarte) && aaiSIResources.checkInstanceServiceNameInUse(serviceInstance)) { + throw new DuplicateNameException("service-instance", serviceInstance.getServiceInstanceName()); + } Customer customer = execution.getGeneralBuildingBlock().getCustomer(); aaiSIResources.createServiceInstance(serviceInstance, customer); } catch (Exception ex) { @@ -327,7 +331,8 @@ public class AAICreateTasks { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); - if (alaCarte != null && alaCarte && aaiNetworkResources.checkNetworkNameInUse(l3network.getNetworkName())) { + if (Boolean.TRUE.equals(alaCarte) + && aaiNetworkResources.checkNetworkNameInUse(l3network.getNetworkName())) { throw new DuplicateNameException("l3Network", l3network.getNetworkName()); } // set default to false. ToBe updated by SDNC @@ -386,7 +391,7 @@ public class AAICreateTasks { InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup(); // set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME)); - if (alaCarte != null && alaCarte + if (Boolean.TRUE.equals(alaCarte) && aaiInstanceGroupResources.checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName())) { throw new DuplicateNameException("instance-group", instanceGroup.getInstanceGroupName()); } @@ -508,7 +513,7 @@ public class AAICreateTasks { try { Boolean alaCarte = execution.getVariable(A_LA_CARTE); Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID); - if (alaCarte != null && alaCarte + if (Boolean.TRUE.equals(alaCarte) && aaiConfigurationResources.checkConfigurationNameInUse(configuration.getConfigurationName())) { throw new DuplicateNameException("configuration", configuration.getConfigurationName()); } @@ -524,7 +529,7 @@ public class AAICreateTasks { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID); - if (alaCarte != null && alaCarte + if (Boolean.TRUE.equals(alaCarte) && aaiInstanceGroupResources.checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName())) { throw new DuplicateNameException("instance-group", instanceGroup.getInstanceGroupName()); } 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 b0ba0595d5..a1fcbff0db 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 @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -33,7 +35,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import javax.annotation.PostConstruct; -import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang3.StringUtils; import org.onap.sdnc.northbound.client.model.GenericResourceApiParam; import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam; @@ -118,7 +119,7 @@ public class VnfAdapterVfModuleObjectMapper { public CreateVfModuleRequest createVfModuleRequestMapper(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) - throws JsonParseException, JsonMappingException, IOException { + throws IOException { CreateVfModuleRequest createVfModuleRequest = new CreateVfModuleRequest(); createVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); @@ -167,7 +168,7 @@ public class VnfAdapterVfModuleObjectMapper { private Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) - throws JsonParseException, JsonMappingException, IOException { + throws IOException { GenericResourceApiVnfTopology vnfTop = @@ -206,7 +207,7 @@ public class VnfAdapterVfModuleObjectMapper { Map<String, Object> srcMap) { StringBuilder directives = new StringBuilder(); int no_directives_size = 0; - if (directives.equals(MsoMulticloudUtils.USER_DIRECTIVES) + if (directive.equals(MsoMulticloudUtils.USER_DIRECTIVES) && srcMap.containsKey(MsoMulticloudUtils.OOF_DIRECTIVES)) { no_directives_size = 1; } @@ -214,7 +215,7 @@ public class VnfAdapterVfModuleObjectMapper { directives.append("{ \"attributes\": [ "); int i = 0; for (String attributeName : srcMap.keySet()) { - if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directives) + if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directive) && attributeName.equals(MsoMulticloudUtils.OOF_DIRECTIVES))) { directives.append(new AttributeNameValue(attributeName, srcMap.get(attributeName).toString())); if (i < (srcMap.size() - 1 + no_directives_size)) @@ -247,7 +248,7 @@ public class VnfAdapterVfModuleObjectMapper { private void buildParamsMapFromVnfSdncResponse(Map<String, Object> paramsMap, GenericResourceApiVnftopologyVnfTopology vnfTopology, Map<String, String> networkRoleMap, - boolean skipVnfResourceAssignments) throws JsonParseException, JsonMappingException, IOException { + boolean skipVnfResourceAssignments) throws IOException { // Get VNF parameters from SDNC response GenericResourceApiParam vnfParametersData = vnfTopology.getVnfParametersData(); buildParamsMapFromSdncParams(paramsMap, vnfParametersData); @@ -324,7 +325,7 @@ public class VnfAdapterVfModuleObjectMapper { private void buildParamsMapFromVfModuleSdncResponse(Map<String, Object> paramsMap, GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology, boolean skipVfModuleAssignments) - throws JsonParseException, JsonMappingException, IOException { + throws IOException { // Get VF Module parameters from SDNC response GenericResourceApiParam vfModuleParametersData = vfModuleTopology.getVfModuleParameters(); buildParamsMapFromSdncParams(paramsMap, vfModuleParametersData); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java index f84afbe4a2..c41f3fa56c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java @@ -157,5 +157,10 @@ public class AAIServiceInstanceResources { injectionHelper.getAaiClient().update(serviceInstanceURI, aaiServiceInstance); } + public boolean checkInstanceServiceNameInUse(ServiceInstance serviceInstance) { + AAIResourceUri uriSI = AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE) + .queryParam("service-instance-name", serviceInstance.getServiceInstanceName()); + return injectionHelper.getAaiClient().exists(uriSI); + } } 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 5868eb8fc4..b889493d2e 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 @@ -123,12 +123,21 @@ public class AAICreateTasksTest extends BaseTaskTest { @Test public void createServiceInstanceTest() throws Exception { + doReturn(false).when(aaiServiceInstanceResources).checkInstanceServiceNameInUse(serviceInstance); doNothing().when(aaiServiceInstanceResources).createServiceInstance(serviceInstance, customer); aaiCreateTasks.createServiceInstance(execution); verify(aaiServiceInstanceResources, times(1)).createServiceInstance(serviceInstance, customer); } @Test + public void createServiceInstanceNameInUseExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doReturn(true).when(aaiServiceInstanceResources).checkInstanceServiceNameInUse(serviceInstance); + execution.setVariable("aLaCarte", Boolean.TRUE); + aaiCreateTasks.createServiceInstance(execution); + } + + @Test public void createServiceInstanceExceptionTest() throws Exception { expectedException.expect(BpmnError.class); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java index 14df832754..ea98ee0169 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java @@ -21,8 +21,11 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -43,8 +46,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -186,4 +191,23 @@ public class AAIServiceInstanceResourcesTest extends TestDataSetup { verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.ServiceInstance.class)); } + + @Test + public void checkInstanceServiceNameInUseTrueTest() throws Exception { + AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE) + .queryParam("service-instance-name", serviceInstance.getServiceInstanceName()); + doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(uri)); + boolean nameInUse = aaiServiceInstanceResources.checkInstanceServiceNameInUse(serviceInstance); + assertTrue(nameInUse); + } + + @Test + public void checkInstanceServiceNameInUseFalseTest() throws Exception { + AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE) + .queryParam("service-instance-name", serviceInstance.getServiceInstanceName()); + doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(uri)); + boolean nameInUse = aaiServiceInstanceResources.checkInstanceServiceNameInUse(serviceInstance); + assertFalse(nameInUse); + } + } |