From 76a37d03413fd1798e50274c57566c0ed3d752e4 Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Tue, 21 Jan 2020 13:30:45 +0100 Subject: AssignPnfBB connects PNF and service instance in AAI Change-Id: I92ab4b45acb120d647ea3de7a455e2e873c12a72 Issue-ID: SO-2605 Signed-off-by: Joanna Jeremicz --- .../subprocess/BuildingBlock/AssignPnfBB.bpmn | 102 ++++------------ .../pnf/tasks/CheckAaiForPnfCorrelationId.java | 45 ------- .../pnf/tasks/CreatePnfEntryInAai.java | 34 ------ .../infrastructure/pnf/tasks/PnfBaseTasks.java | 29 ----- .../pnf/tasks/CheckAaiForPnfCorrelationIdTest.java | 129 --------------------- .../pnf/tasks/CreatePnfEntryInAaiTest.java | 50 -------- .../infrastructure/pnf/tasks/PnfTasksUtils.java | 17 --- .../infrastructure/aai/tasks/AAICreateTasks.java | 18 ++- .../onap/so/client/aai/mapper/AAIObjectMapper.java | 6 + .../so/client/orchestration/AAIPnfResources.java | 52 +++++++++ .../test/java/org/onap/so/bpmn/BaseTaskTest.java | 6 + .../aai/tasks/AAICreateTasksTest.java | 18 +++ .../client/orchestration/AAIPnfResourcesTest.java | 86 ++++++++++++++ 13 files changed, 208 insertions(+), 384 deletions(-) delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java (limited to 'bpmn') diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn index 930f666bf0..c8600586ce 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignPnfBB.bpmn @@ -1,68 +1,40 @@ - + - - - - SequenceFlow_1fu9o4x - - - SequenceFlow_1fu9o4x - SequenceFlow_081rs5d - - - SequenceFlow_081rs5d - SequenceFlow_0fn5kgz - SequenceFlow_1ewfz8r - - - SequenceFlow_0fn5kgz - SequenceFlow_0l6rtzy - + + - SequenceFlow_1ewfz8r SequenceFlow_0l6rtzy - - - #{!aaiContainsInfoAboutPnf} - - - #{aaiContainsInfoAboutPnf} - - - + + SequenceFlow_1fu9o4x + SequenceFlow_0l6rtzy + + + SequenceFlow_1fu9o4x + + Inputs: - - pnfCorrelationId - String - - uuid - String + - pnfName - String + - - + - + - - - - - - - - - - + @@ -70,55 +42,27 @@ - - - - - - - - - - - - - - - - - - - - - + + - + - + - - - - - - - - - - - + + - + diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java deleted file mode 100644 index 29914252d8..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import joptsimple.internal.Strings; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.client.exception.BBObjectNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import java.io.IOException; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; - -@Component -public class CheckAaiForPnfCorrelationId extends PnfBaseTasks { - private static final Logger logger = LoggerFactory.getLogger(CheckAaiForPnfCorrelationId.class); - - @Override - public void execute(BuildingBlockExecution execution) { - try { - String pnfCorrelationId = extractPnf(execution).getPnfName(); - checkIfPnfCorrelationIdPresent(execution, pnfCorrelationId); - checkIfPnfExistsInAai(execution, pnfCorrelationId); - } catch (BBObjectNotFoundException e) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); - } - - } - - private void checkIfPnfCorrelationIdPresent(BuildingBlockExecution execution, String pnfCorrelationId) { - if (Strings.isNullOrEmpty(pnfCorrelationId)) { - exceptionUtil.buildAndThrowWorkflowException(execution, 500, PNF_CORRELATION_ID + " is not set"); - } - } - - private void checkIfPnfExistsInAai(BuildingBlockExecution execution, String pnfCorrelationId) { - try { - boolean isEntry = pnfManagement.getEntryFor(pnfCorrelationId).isPresent(); - logger.debug("AAI entry is found for pnf correlation id {}: {}", PNF_CORRELATION_ID, isEntry); - execution.setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry); - } catch (IOException e) { - logger.error("Exception in check AAI for pnf_correlation_id execution", e); - exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e); - } - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java deleted file mode 100644 index 6e86ad619e..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.onap.aai.domain.yang.Pnf; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.client.exception.BBObjectNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -@Component -public class CreatePnfEntryInAai extends PnfBaseTasks { - private static final Logger logger = LoggerFactory.getLogger(CreatePnfEntryInAai.class); - - @Override - public void execute(BuildingBlockExecution execution) throws Exception { - try { - org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf = extractPnf(execution); - String pnfCorrelationId = pnf.getPnfName(); - pnfManagement.createEntry(pnfCorrelationId, preparePnfForAai(pnf)); - logger.debug("AAI entry is created for pnf correlation id: {}, pnf uuid: {}", pnfCorrelationId, - pnf.getPnfId()); - } catch (BBObjectNotFoundException e) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); - } - } - - private Pnf preparePnfForAai(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf) { - Pnf pnfAai = new Pnf(); - pnfAai.setPnfId(pnf.getPnfId()); - pnfAai.setPnfName(pnf.getPnfName()); - return pnfAai; - } - -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java deleted file mode 100644 index d8e3379afb..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; -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.springframework.beans.factory.annotation.Autowired; - -public abstract class PnfBaseTasks { - protected PnfManagement pnfManagement; - @Autowired - protected ExceptionBuilder exceptionUtil; - @Autowired - protected ExtractPojosForBB extractPojosForBB; - - @Autowired - public void setPnfManagement(PnfManagement pnfManagement) { - this.pnfManagement = pnfManagement; - } - - public abstract void execute(BuildingBlockExecution execution) throws Exception; - - protected Pnf extractPnf(BuildingBlockExecution execution) throws BBObjectNotFoundException { - return extractPojosForBB.extractByKey(execution, ResourceKey.PNF); - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java deleted file mode 100644 index 3fa9fbf3b5..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationIdTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.camunda.bpm.engine.delegate.BpmnError; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl; -import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementThrowingException; -import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import org.onap.so.client.exception.ExceptionBuilder; -import java.io.IOException; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITHOUT_ENTRY; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf; - -@RunWith(Enclosed.class) -public class CheckAaiForPnfCorrelationIdTest { - - @RunWith(MockitoJUnitRunner.class) - public static class ConnectionOkTests { - - @Mock - private ExtractPojosForBB extractPojosForBB; - @Mock - private ExceptionBuilder exceptionUtil; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @InjectMocks - private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId(); - private PnfManagement pnfManagementTest = new PnfManagementTestImpl(); - - @Before - public void setUp() { - task.setPnfManagement(pnfManagementTest); - } - - @Test - public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception { - // given - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))).thenReturn(preparePnf(null, PNF_UUID)); - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution), - anyInt(), anyString()); - // when, then - expectedException.expect(BpmnError.class); - task.execute(execution); - verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), anyString()); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception { - // given - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(ID_WITHOUT_ENTRY, PNF_UUID)); - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - // when - task.execute(execution); - // then - verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, false); - } - - @Test - public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception { - // given - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(ID_WITH_ENTRY, PNF_UUID)); - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - // when - task.execute(execution); - // then - verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, true); - } - } - - @RunWith(MockitoJUnitRunner.class) - public static class NoConnectionTests { - - @Mock - private ExtractPojosForBB extractPojosForBB; - @Mock - private ExceptionBuilder exceptionUtil; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @InjectMocks - private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId(); - private PnfManagement pnfManagementTest = new PnfManagementThrowingException(); - - @Before - public void setUp() throws Exception { - task.setPnfManagement(pnfManagementTest); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID)); - } - - @Test - public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() { - // given - BuildingBlockExecution execution = mock(BuildingBlockExecution.class); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution), - anyInt(), any(IOException.class)); - // when, then - expectedException.expect(BpmnError.class); - task.execute(execution); - verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), any(IOException.class)); - } - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java deleted file mode 100644 index ed8dd82efb..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAaiTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -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.aai.domain.yang.Pnf; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_CORRELATION_ID; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID; -import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf; - -@RunWith(MockitoJUnitRunner.class) -public class CreatePnfEntryInAaiTest { - - @Mock - private ExtractPojosForBB extractPojosForBB; - @InjectMocks - private CreatePnfEntryInAai task = new CreatePnfEntryInAai(); - private PnfManagementTestImpl pnfManagementTest = new PnfManagementTestImpl(); - - @Before - public void setUp() throws Exception { - task.setPnfManagement(pnfManagementTest); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))) - .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID)); - } - - @Test - public void shouldSetPnfIdAndPnfName() throws Exception { - // when - task.execute(mock(BuildingBlockExecution.class)); - // then - Pnf createdEntry = pnfManagementTest.getCreated().get(PNF_CORRELATION_ID); - assertThat(createdEntry.getPnfId()).isEqualTo(PNF_UUID); - assertThat(createdEntry.getPnfName()).isEqualTo(PNF_CORRELATION_ID); - assertThat(createdEntry.isInMaint()).isNull(); - } - -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java deleted file mode 100644 index 49fe96c3d9..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfTasksUtils.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.tasks; - -import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; -import java.util.UUID; - -public class PnfTasksUtils { - static final String PNF_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString(); - static final String PNF_CORRELATION_ID = "testPnfCorrelationId"; - - public static Pnf preparePnf(String pnfName, String pnfUuid) { - Pnf pnf = new Pnf(); - pnf.setPnfName(pnfName); - pnf.setPnfId(pnfUuid); - return pnf; - } - -} 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() { 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; @@ -68,6 +71,9 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected AAIVnfResources aaiVnfResources; + @Mock + protected AAIPnfResources aaiPnfResources; + @Mock protected AAIVfModuleResources aaiVfModuleResources; 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)); + } + +} -- cgit 1.2.3-korg