aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2020-01-21 13:30:45 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2020-01-29 07:57:39 +0100
commit76a37d03413fd1798e50274c57566c0ed3d752e4 (patch)
tree73aa936f3c01f9e890d9460749e7c8faa5b85f3b /bpmn/so-bpmn-tasks/src
parent48cb43adc20ac10fa6f22c0e03fe2b6775d45b87 (diff)
AssignPnfBB connects PNF and service instance in AAI
Change-Id: I92ab4b45acb120d647ea3de7a455e2e873c12a72 Issue-ID: SO-2605 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java6
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java52
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java6
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java86
6 files changed, 185 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 b9f73f3f0e..22089dae1f 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
@@ -6,6 +6,8 @@
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -29,6 +31,7 @@ import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.onap.so.client.orchestration.AAIPnfResources;
import org.onap.so.logger.LoggingAnchor;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.onap.so.bpmn.common.BuildingBlockExecution;
@@ -43,6 +46,7 @@ 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;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
@@ -50,7 +54,6 @@ 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.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException;
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;
@@ -87,6 +90,8 @@ public class AAICreateTasks {
@Autowired
private AAIVnfResources aaiVnfResources;
@Autowired
+ private AAIPnfResources aaiPnfResources;
+ @Autowired
private ExceptionBuilder exceptionUtil;
@Autowired
private ExtractPojosForBB extractPojosForBB;
@@ -252,6 +257,17 @@ public class AAICreateTasks {
}
}
+ public void createPnf(BuildingBlockExecution execution) {
+ try {
+ Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance);
+ } catch (BBObjectNotFoundException e) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
+ }
+ }
+
/**
* This method is used for separating (,) from the string.
*
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 06f6550d51..11a7b83259 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -87,6 +89,10 @@ public class AAIObjectMapper {
return modelMapper.map(vnf, org.onap.aai.domain.yang.GenericVnf.class);
}
+ public org.onap.aai.domain.yang.Pnf mapPnf(Pnf pnf) {
+ return modelMapper.map(pnf, org.onap.aai.domain.yang.Pnf.class);
+ }
+
public org.onap.aai.domain.yang.VfModule mapVfModule(VfModule vfModule) {
if (modelMapper.getTypeMap(VfModule.class, org.onap.aai.domain.yang.VfModule.class) == null) {
modelMapper.addMappings(new PropertyMap<VfModule, org.onap.aai.domain.yang.VfModule>() {
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java
new file mode 100644
index 0000000000..9dd44c43e9
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Nokia 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.client.orchestration;
+
+import java.util.Optional;
+import org.onap.so.bpmn.common.InjectionHelper;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.client.aai.AAIObjectType;
+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;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AAIPnfResources {
+
+ @Autowired
+ private InjectionHelper injectionHelper;
+
+ @Autowired
+ private AAIObjectMapper aaiObjectMapper;
+
+ public void createPnfAndConnectServiceInstance(Pnf pnf, ServiceInstance serviceInstance) {
+ AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName());
+ pnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
+ AAIResourceUri serviceInstanceURI =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstance.getServiceInstanceId());
+ injectionHelper.getAaiClient().createIfNotExists(pnfURI, Optional.of(aaiObjectMapper.mapPnf(pnf)))
+ .connect(pnfURI, serviceInstanceURI);
+ }
+}
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 39efa6dc76..73896d7d6d 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -40,6 +42,7 @@ import org.onap.so.client.orchestration.AAICollectionResources;
import org.onap.so.client.orchestration.AAIConfigurationResources;
import org.onap.so.client.orchestration.AAIInstanceGroupResources;
import org.onap.so.client.orchestration.AAINetworkResources;
+import org.onap.so.client.orchestration.AAIPnfResources;
import org.onap.so.client.orchestration.AAIServiceInstanceResources;
import org.onap.so.client.orchestration.AAIVfModuleResources;
import org.onap.so.client.orchestration.AAIVnfResources;
@@ -69,6 +72,9 @@ public abstract class BaseTaskTest extends TestDataSetup {
protected AAIVnfResources aaiVnfResources;
@Mock
+ protected AAIPnfResources aaiPnfResources;
+
+ @Mock
protected AAIVfModuleResources aaiVfModuleResources;
@Mock
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 a8550d8df9..a8f47fc763 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -55,6 +57,7 @@ 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.Platform;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
@@ -74,6 +77,7 @@ public class AAICreateTasksTest extends BaseTaskTest {
private ServiceInstance serviceInstance;
private L3Network network;
private GenericVnf genericVnf;
+ private Pnf pnf;
private VolumeGroup volumeGroup;
private CloudRegion cloudRegion;
private VfModule vfModule;
@@ -93,6 +97,7 @@ public class AAICreateTasksTest extends BaseTaskTest {
serviceInstance = setServiceInstance();
network = setL3Network();
genericVnf = setGenericVnf();
+ pnf = buildPnf();
volumeGroup = setVolumeGroup();
cloudRegion = setCloudRegion();
vfModule = setVfModule();
@@ -324,6 +329,19 @@ public class AAICreateTasksTest extends BaseTaskTest {
verify(aaiVnfResources, times(1)).createVnfandConnectServiceInstance(genericVnf, serviceInstance);
}
+ @Test
+ public void createPnfShouldCallCreatePnfAndConnectServiceInstance() throws BBObjectNotFoundException {
+ when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
+ aaiCreateTasks.createPnf(execution);
+ verify(aaiPnfResources, times(1)).createPnfAndConnectServiceInstance(pnf, serviceInstance);
+ }
+
+ @Test
+ public void createPnfShouldThrowBpmnErrorWhenPnfIsNotFound() throws BBObjectNotFoundException {
+ expectedException.expect(BpmnError.class);
+ doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(execution, ResourceKey.PNF);
+ aaiCreateTasks.createPnf(execution);
+ }
@Test
public void createVfModuleTest() throws Exception {
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
new file mode 100644
index 0000000000..a929f256ac
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Nokia 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.client.orchestration;
+
+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.times;
+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.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.InjectionHelper;
+import org.onap.so.bpmn.common.data.TestDataSetup;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.mapper.AAIObjectMapper;
+import org.onap.so.db.catalog.beans.OrchestrationStatus;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class AAIPnfResourcesTest extends TestDataSetup {
+
+ private Pnf pnf;
+ private ServiceInstance serviceInstance;
+
+ @Mock
+ protected AAIObjectMapper aaiObjectMapperMock;
+
+ @Mock
+ protected InjectionHelper injectionHelperMock;
+
+ @Mock
+ protected AAIResourcesClient aaiResourcesClientMock;
+
+ @InjectMocks
+ AAIPnfResources aaiPnfResources = new AAIPnfResources();
+
+ @Before
+ public void setUp() {
+ pnf = buildPnf();
+ pnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
+ serviceInstance = buildServiceInstance();
+
+ doReturn(aaiResourcesClientMock).when(injectionHelperMock).getAaiClient();
+ }
+
+ @Test
+ public void createPnfAndConnectServiceInstanceShouldSetInventoriedStatusAndCallConnectMethod() {
+ org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf();
+
+ doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf);
+ doReturn(aaiResourcesClientMock).when(aaiResourcesClientMock).createIfNotExists(any(AAIResourceUri.class),
+ eq(Optional.of(pnfYang)));
+
+ aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance);
+
+ assertEquals(OrchestrationStatus.INVENTORIED, pnf.getOrchestrationStatus());
+ verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
+ }
+
+}