aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
authorSangalang, Felix <felix.sangalang@att.com>2019-06-14 14:45:16 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-06-14 14:45:22 -0400
commit3fea528d612cf90c57510f66dc0d0b42b607e6d5 (patch)
tree289eb335b64761172e85e8774eb58aca1004edb7 /bpmn/so-bpmn-tasks
parente29b04bca6367c14fdbd403bbd275e6c8c10fa60 (diff)
Validate names before writing to A&AI
Validate name for InstanceGroup, Configuration and Network. Change-Id: I494749e17a40c6c0cdd51dd28d9c9bca371410ac Issue-ID: SO-2022 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java19
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java8
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIInstanceGroupResources.java8
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java8
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java33
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java22
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java21
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java19
8 files changed, 137 insertions, 1 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 28d5363ad2..76f9322cfc 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
@@ -309,9 +309,13 @@ public class AAICreateTasks {
*/
public void createNetwork(BuildingBlockExecution execution) {
try {
+ Boolean alaCarte = execution.getVariable(A_LA_CARTE);
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())) {
+ throw new DuplicateNameException("l3Network", l3network.getNetworkName());
+ }
// set default to false. ToBe updated by SDNC
l3network.setIsBoundToVpn(false);
// define is bound to vpn flag as true if NEUTRON_NETWORK_TYPE is PROVIDER
@@ -362,11 +366,16 @@ public class AAICreateTasks {
*/
public void createNetworkCollectionInstanceGroup(BuildingBlockExecution execution) {
try {
+ Boolean alaCarte = execution.getVariable(A_LA_CARTE);
ServiceInstance serviceInstance =
extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
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
+ && aaiInstanceGroupResources.checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName())) {
+ throw new DuplicateNameException("instance-group", instanceGroup.getInstanceGroupName());
+ }
// put shell in AAI
aaiNetworkResources.createNetworkInstanceGroup(instanceGroup);
} catch (Exception ex) {
@@ -483,7 +492,12 @@ public class AAICreateTasks {
public void createConfiguration(BuildingBlockExecution execution) {
try {
+ Boolean alaCarte = execution.getVariable(A_LA_CARTE);
Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
+ if (alaCarte != null && alaCarte
+ && aaiConfigurationResources.checkConfigurationNameInUse(configuration.getConfigurationName())) {
+ throw new DuplicateNameException("configuration", configuration.getConfigurationName());
+ }
aaiConfigurationResources.createConfiguration(configuration);
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
@@ -492,9 +506,14 @@ public class AAICreateTasks {
public void createInstanceGroupVnf(BuildingBlockExecution execution) {
try {
+ Boolean alaCarte = execution.getVariable(A_LA_CARTE);
ServiceInstance serviceInstance =
extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
+ if (alaCarte != null && alaCarte
+ && aaiInstanceGroupResources.checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName())) {
+ throw new DuplicateNameException("instance-group", instanceGroup.getInstanceGroupName());
+ }
aaiInstanceGroupResources.createInstanceGroupandConnectServiceInstance(instanceGroup, serviceInstance);
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java
index 9eee0e607d..867d80a4ea 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java
@@ -24,6 +24,7 @@ import java.util.Optional;
import javax.ws.rs.core.UriBuilder;
import org.onap.so.bpmn.common.InjectionHelper;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.AAIEdgeLabel;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
@@ -237,4 +238,11 @@ public class AAIConfigurationResources {
aaiConfiguration.setOrchestrationStatus(orchestrationStatus.name());
injectionHelper.getAaiClient().update(aaiResourceUri, aaiConfiguration);
}
+
+ public boolean checkConfigurationNameInUse(String configurationName) {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION)
+ .queryParam("configuration-name", configurationName);
+ return injectionHelper.getAaiClient().exists(uri);
+ }
+
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIInstanceGroupResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIInstanceGroupResources.java
index c48593037a..296d052315 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIInstanceGroupResources.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIInstanceGroupResources.java
@@ -25,6 +25,7 @@ import org.onap.so.bpmn.common.InjectionHelper;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.AAIEdgeLabel;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
@@ -84,4 +85,11 @@ public class AAIInstanceGroupResources {
injectionHelper.getAaiClient().createIfNotExists(instanceGroupUri, Optional.of(aaiInstanceGroup))
.connect(instanceGroupUri, serviceInstanceURI);
}
+
+ public boolean checkInstanceGroupNameInUse(String instanceGroupName) {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.INSTANCE_GROUP)
+ .queryParam("instance-group-name", instanceGroupName);
+ return injectionHelper.getAaiClient().exists(uri);
+ }
+
}
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 b936551549..bc702c9fb4 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
@@ -32,6 +32,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.AAIEdgeLabel;
import org.onap.so.client.aai.entities.AAIResultWrapper;
@@ -206,4 +207,11 @@ public class AAINetworkResources {
AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId);
injectionHelper.getAaiClient().delete(networkPolicyURI);
}
+
+ public boolean checkNetworkNameInUse(String networkName) {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
+ return injectionHelper.getAaiClient().exists(uri);
+ }
+
}
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 b054cc17bb..7bb2bc689f 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
@@ -398,13 +398,21 @@ public class AAICreateTasksTest extends BaseTaskTest {
@Test
public void createNetworkTest() throws Exception {
network.getModelInfoNetwork().setNeutronNetworkType("PROVIDER");
-
+ execution.setVariable("aLaCarte", Boolean.FALSE);
doNothing().when(aaiNetworkResources).createNetworkConnectToServiceInstance(network, serviceInstance);
aaiCreateTasks.createNetwork(execution);
verify(aaiNetworkResources, times(1)).createNetworkConnectToServiceInstance(network, serviceInstance);
}
@Test
+ public void createNetworkNameInUseExceptionTest() throws Exception {
+ expectedException.expect(BpmnError.class);
+ execution.setVariable("aLaCarte", Boolean.TRUE);
+ doReturn(true).when(aaiNetworkResources).checkNetworkNameInUse(network.getNetworkName());
+ aaiCreateTasks.createNetwork(execution);
+ }
+
+ @Test
public void createNetworkExceptionTest() throws Exception {
expectedException.expect(BpmnError.class);
@@ -444,6 +452,7 @@ public class AAICreateTasksTest extends BaseTaskTest {
public void createNetworkCollectionInstanceGroupTest() throws Exception {
doNothing().when(aaiNetworkResources)
.createNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
+ execution.setVariable("aLaCarte", Boolean.FALSE);
aaiCreateTasks.createNetworkCollectionInstanceGroup(execution);
verify(aaiNetworkResources, times(1))
.createNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
@@ -509,11 +518,21 @@ public class AAICreateTasksTest extends BaseTaskTest {
public void createConfigurationTest() throws Exception {
gBBInput = execution.getGeneralBuildingBlock();
doNothing().when(aaiConfigurationResources).createConfiguration(configuration);
+ execution.setVariable("aLaCarte", Boolean.FALSE);
aaiCreateTasks.createConfiguration(execution);
verify(aaiConfigurationResources, times(1)).createConfiguration(configuration);
}
@Test
+ public void createConfigurationNameInUseExceptionTest() throws Exception {
+ expectedException.expect(BpmnError.class);
+ doReturn(true).when(aaiConfigurationResources)
+ .checkConfigurationNameInUse(configuration.getConfigurationName());
+ execution.setVariable("aLaCarte", Boolean.TRUE);
+ aaiCreateTasks.createConfiguration(execution);
+ }
+
+ @Test
public void connectVnfToCloudRegionTest() throws Exception {
gBBInput = execution.getGeneralBuildingBlock();
doNothing().when(aaiVnfResources).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion());
@@ -543,14 +562,26 @@ public class AAICreateTasksTest extends BaseTaskTest {
@Test
public void createInstanceGroupVnfTest() throws Exception {
+ doReturn(false).when(aaiInstanceGroupResources)
+ .checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName());
doNothing().when(aaiInstanceGroupResources).createInstanceGroupandConnectServiceInstance(instanceGroup,
serviceInstance);
+ execution.setVariable("aLaCarte", Boolean.FALSE);
aaiCreateTasks.createInstanceGroupVnf(execution);
verify(aaiInstanceGroupResources, times(1)).createInstanceGroupandConnectServiceInstance(instanceGroup,
serviceInstance);
}
@Test
+ public void createInstanceGroupVnfNameInUseExceptionTest() throws Exception {
+ expectedException.expect(BpmnError.class);
+ doReturn(true).when(aaiInstanceGroupResources)
+ .checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName());
+ execution.setVariable("aLaCarte", Boolean.TRUE);
+ aaiCreateTasks.createInstanceGroupVnf(execution);
+ }
+
+ @Test
public void createInstanceGroupVnfExceptionTest() throws Exception {
expectedException.expect(BpmnError.class);
doThrow(RuntimeException.class).when(aaiInstanceGroupResources)
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 91d9070c0f..68f3d20c82 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
@@ -20,6 +20,8 @@
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.eq;
import static org.mockito.ArgumentMatchers.isA;
@@ -44,6 +46,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIEdgeLabel;
@@ -240,4 +243,23 @@ public class AAIConfigurationResourcesTest extends TestDataSetup {
verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class),
any(org.onap.aai.domain.yang.Configuration.class));
}
+
+ @Test
+ public void checkConfigurationNameInUseTrueTest() throws Exception {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION)
+ .queryParam("configuration-name", "configurationName");
+ doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiConfigurationResources.checkConfigurationNameInUse("configurationName");
+ assertTrue(nameInUse);
+ }
+
+ @Test
+ public void checkConfigurationNameInUseFalseTest() throws Exception {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION)
+ .queryParam("configuration-name", "configurationName");
+ doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiConfigurationResources.checkConfigurationNameInUse("configurationName");
+ assertFalse(nameInUse);
+ }
+
}
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 8c0d27f799..cb5683d9d8 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
@@ -22,6 +22,8 @@ package org.onap.so.client.orchestration;
import static org.mockito.ArgumentMatchers.eq;
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.Mockito.doNothing;
@@ -40,6 +42,7 @@ import org.onap.so.bpmn.common.InjectionHelper;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIEdgeLabel;
@@ -131,4 +134,22 @@ public class AAIInstanceGroupResourcesTest extends TestDataSetup {
verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
}
+ @Test
+ public void checkInstanceGroupNameInUseTrueTest() throws Exception {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.INSTANCE_GROUP)
+ .queryParam("instance-group-name", "instanceGroupName");
+ doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiInstanceGroupResources.checkInstanceGroupNameInUse("instanceGroupName");
+ assertTrue(nameInUse);
+ }
+
+ @Test
+ public void checkInstanceGroupNameInUseFalseTest() throws Exception {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.INSTANCE_GROUP)
+ .queryParam("instance-group-name", "instanceGroupName");
+ doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiInstanceGroupResources.checkInstanceGroupNameInUse("instanceGroupName");
+ assertFalse(nameInUse);
+ }
+
}
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 d41148d784..b6161d7669 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
@@ -23,6 +23,7 @@ package org.onap.so.client.orchestration;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -425,4 +426,22 @@ public class AAINetworkResourcesTest extends TestDataSetup {
verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
}
+ @Test
+ public void checkInstanceGroupNameInUseTrueTest() throws Exception {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", "networkName");
+ doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiNetworkResources.checkNetworkNameInUse("networkName");
+ assertTrue(nameInUse);
+ }
+
+ @Test
+ public void checkInstanceGroupNameInUseFalseTest() throws Exception {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", "networkName");
+ doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiNetworkResources.checkNetworkNameInUse("networkName");
+ assertFalse(nameInUse);
+ }
+
}