diff options
author | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2020-01-21 13:30:45 +0100 |
---|---|---|
committer | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2020-01-29 07:57:39 +0100 |
commit | 76a37d03413fd1798e50274c57566c0ed3d752e4 (patch) | |
tree | 73aa936f3c01f9e890d9460749e7c8faa5b85f3b /bpmn/so-bpmn-infrastructure-common | |
parent | 48cb43adc20ac10fa6f22c0e03fe2b6775d45b87 (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-infrastructure-common')
6 files changed, 0 insertions, 304 deletions
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; - } - -} |