summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-04-22 12:35:15 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-22 12:35:15 +0000
commit761567ec1de6e322c419f47f00a66a691f58a7af (patch)
treeb61e950ceca83290b17dab54868974bc493341e8 /bpmn/so-bpmn-tasks
parent21e51ae1290ac58d9f579333199098f98615f5b2 (diff)
parentfbb984e6a8823ca26eae20a65c6d261feac02b7b (diff)
Merge "openstack inventory capture"
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModule.java86
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/DeleteVFModule.java51
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java3
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModuleTest.java108
4 files changed, 248 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModule.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModule.java
new file mode 100644
index 0000000000..4b1e40917a
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModule.java
@@ -0,0 +1,86 @@
+package org.onap.so.bpmn.infrastructure.vfmodule;
+
+import java.util.Optional;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+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.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.Relationships;
+import org.onap.so.client.aai.entities.uri.AAIPluralResourceUri;
+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.cloud.resource.beans.CloudInformation;
+import org.onap.so.cloud.resource.beans.NodeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+
+@Component
+public class CreateVFModule {
+
+ private static final Logger logger = LoggerFactory.getLogger(CreateVFModule.class);
+
+ @Autowired
+ protected ExceptionBuilder exceptionUtil;
+
+ @Autowired
+ protected ExtractPojosForBB extractPojosForBB;
+
+ public void createInventoryVariable(BuildingBlockExecution execution) {
+ try {
+ GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+ CloudInformation cloudInformation = new CloudInformation();
+ cloudInformation.setOwner(gBBInput.getCloudRegion().getCloudOwner());
+ cloudInformation.setRegionId(gBBInput.getCloudRegion().getLcpCloudRegionId());
+ cloudInformation.setTenantId(gBBInput.getTenant().getTenantId());
+ cloudInformation.setTenantName(gBBInput.getTenant().getTenantName());
+ cloudInformation.setTenantContext(gBBInput.getTenant().getTenantContext());
+ cloudInformation.setTemplateInstanceId(execution.getVariable("heatStackId"));
+ cloudInformation.setNodeType(getNodeType(gBBInput.getCloudRegion()));
+ cloudInformation.setVnfName(vnf.getVnfName());
+ cloudInformation.setVnfId(vnf.getVnfId());
+ cloudInformation.setVfModuleId(vfModule.getVfModuleId());
+ execution.setVariable("cloudInformation", cloudInformation);
+ } catch (Exception e) {
+ logger.error("Error building CloudInformation Object for NC Inventory", e);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
+ }
+ }
+
+ protected NodeType getNodeType(CloudRegion cloudRegion) {
+ AAIResourceUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION,
+ cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId());
+ AAIResourcesClient client = getAAIClient();
+ Optional<Relationships> relationships = client.get(cloudRegionUri).getRelationships();
+ if (relationships.isPresent()) {
+ AAIPluralResourceUri networkTechsGreenfieldUri = AAIUriFactory
+ .createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(),
+ cloudRegion.getLcpCloudRegionId())
+ .relatedTo(AAIObjectPlurals.NETWORK_TECHNOLOGY)
+ .queryParam("network-technology-name", NodeType.GREENFIELD.getNetworkTechnologyName());
+
+ AAIResultWrapper networkTechsGreenfield = client.get(networkTechsGreenfieldUri);
+ if (networkTechsGreenfield != null && !networkTechsGreenfield.isEmpty()) {
+ return NodeType.GREENFIELD;
+ }
+ }
+ return NodeType.BROWNFIELD;
+ }
+
+ protected AAIResourcesClient getAAIClient() {
+ return new AAIResourcesClient();
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/DeleteVFModule.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/DeleteVFModule.java
new file mode 100644
index 0000000000..ef9b06fe8c
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/vfmodule/DeleteVFModule.java
@@ -0,0 +1,51 @@
+package org.onap.so.bpmn.infrastructure.vfmodule;
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+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.ExceptionBuilder;
+import org.onap.so.cloud.resource.beans.CloudInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DeleteVFModule {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeleteVFModule.class);
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ public void createInventoryVariable(BuildingBlockExecution execution) {
+ try {
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+ GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
+ CloudInformation cloudInformation = new CloudInformation();
+ cloudInformation.setOwner(gBBInput.getCloudRegion().getCloudOwner());
+ cloudInformation.setRegionId(gBBInput.getCloudRegion().getLcpCloudRegionId());
+ cloudInformation.setTenantId(gBBInput.getTenant().getTenantId());
+ cloudInformation.setTenantName(gBBInput.getTenant().getTenantName());
+ cloudInformation.setTenantContext(gBBInput.getTenant().getTenantContext());
+ cloudInformation.setTemplateInstanceId(vfModule.getHeatStackId());
+ cloudInformation.setVnfName(vnf.getVnfName());
+ cloudInformation.setVnfId(vnf.getVnfId());
+ cloudInformation.setVfModuleId(vfModule.getVfModuleId());
+
+ execution.setVariable("cloudInformation", cloudInformation);
+ } catch (Exception e) {
+ logger.error("Error building CloudInformation Object for NC Inventory", e);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
+ }
+ }
+
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
index 03ffd9c4c1..29177f8275 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
@@ -24,6 +24,7 @@ package org.onap.so.bpmn;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.InjectionHelper;
import org.onap.so.bpmn.common.data.TestDataSetup;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils;
@@ -32,6 +33,8 @@ import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.Relationships;
import org.onap.so.client.aai.mapper.AAIObjectMapper;
import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper;
import org.onap.so.client.appc.ApplicationControllerAction;
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModuleTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModuleTest.java
new file mode 100644
index 0000000000..63f7d6cbfc
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/vfmodule/CreateVFModuleTest.java
@@ -0,0 +1,108 @@
+package org.onap.so.bpmn.infrastructure.vfmodule;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+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.bbobjects.Tenant;
+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.AAIResourcesClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.Relationships;
+import org.onap.so.client.aai.entities.uri.AAIPluralResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+import org.onap.so.cloud.resource.beans.CloudInformation;
+import org.onap.so.cloud.resource.beans.NodeType;
+
+
+
+public class CreateVFModuleTest extends BaseTaskTest {
+
+ @Spy
+ @InjectMocks
+ public CreateVFModule createVFModule;
+
+ @Mock
+ protected AAIResourcesClient aaiResourcesClient;
+
+ @Mock
+ protected AAIResultWrapper aaiIResultWrapper;
+
+ @Mock
+ protected Relationships relationships;
+
+ @Mock
+ protected BuildingBlockExecution execution;
+
+
+ public GeneralBuildingBlock gbb;
+ public CloudRegion cloudRegion;
+ private GenericVnf genericVnf;
+ private VfModule vfModule;
+ private ServiceInstance service;
+
+ @Before
+ public void before() {
+ cloudRegion = new CloudRegion();
+ cloudRegion.setCloudOwner("CloudOwner");
+ cloudRegion.setLcpCloudRegionId("testRegion");
+ Tenant tenant = new Tenant();
+ tenant.setTenantId("tenant-001");
+ tenant.setTenantName("test-tenant");
+ tenant.setTenantContext("testContext");
+ service = setServiceInstance();
+ genericVnf = setGenericVnf();
+ vfModule = setVfModule();
+ gbb = new GeneralBuildingBlock();
+ gbb.setCloudRegion(cloudRegion);
+ gbb.setTenant(tenant);
+ }
+
+ @Test
+ public void createInventoryVariableTest() throws BBObjectNotFoundException {
+ doReturn(gbb).when(execution).getGeneralBuildingBlock();
+ doReturn(genericVnf).when(extractPojosForBB).extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+ doReturn(vfModule).when(extractPojosForBB).extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ doReturn("heat-stack-id").when(execution).getVariable("heatStackId");
+ doReturn(NodeType.GREENFIELD).when(createVFModule).getNodeType(any(CloudRegion.class));
+ createVFModule.createInventoryVariable(execution);
+ verify(execution).setVariable(eq("cloudInformation"), any(CloudInformation.class));
+ }
+
+ @Test
+ public void getNodeTypeBrownfieldTest() {
+ doReturn(aaiResourcesClient).when(createVFModule).getAAIClient();
+ doReturn(aaiIResultWrapper).when(aaiResourcesClient).get(any(AAIResourceUri.class));
+ doReturn(Optional.empty()).when(aaiIResultWrapper).getRelationships();
+
+ assertEquals(NodeType.BROWNFIELD, createVFModule.getNodeType(cloudRegion));
+ }
+
+ @Test
+ public void getNodeTypeGreenfieldTest() {
+ doReturn(aaiResourcesClient).when(createVFModule).getAAIClient();
+ doReturn(aaiIResultWrapper).when(aaiResourcesClient).get(any(AAIResourceUri.class));
+ doReturn(aaiIResultWrapper).when(aaiResourcesClient).get(any(AAIPluralResourceUri.class));
+ doReturn(Optional.of(relationships)).when(aaiIResultWrapper).getRelationships();
+
+ assertEquals(NodeType.GREENFIELD, createVFModule.getNodeType(cloudRegion));
+ }
+}