From 4e9403e734752e5d8728b73591bb407c71f83dc1 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Wed, 16 Jan 2019 11:29:46 +0100 Subject: Associate PNF instance with Service Change-Id: I19e25e0daae042b30138bbfc074b0e651b8b1c01 Issue-ID: SO-1274 Signed-off-by: Lukasz Muszkieta --- .../pnf/delegate/AaiConnectionTestImpl.java | 17 ++- .../delegate/CreateAndActivatePnfResourceTest.java | 29 ++++-- .../infrastructure/pnf/aai/AaiConnectionImpl.java | 12 +++ .../pnf/delegate/CreateRelation.java | 58 +++++++++++ .../pnf/implementation/AaiConnection.java | 2 + .../pnf/delegate/AaiConnectionTestImpl.java | 6 +- .../delegate/AaiConnectionThrowingException.java | 6 ++ .../pnf/delegate/CreateRelationTest.java | 67 ++++++++++++ .../process/CreateAndActivatePnfResource.bpmn | 114 ++++++++++++--------- 9 files changed, 246 insertions(+), 65 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelation.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelationTest.java (limited to 'bpmn') diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java index 70d94052e1..4e0bf02685 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java @@ -20,12 +20,10 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; - import org.onap.aai.domain.yang.Pnf; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; import org.springframework.context.annotation.Primary; @@ -39,9 +37,10 @@ public class AaiConnectionTestImpl implements AaiConnection { public static final String ID_WITH_ENTRY = "idWithEntryNoIp"; private Map created = new HashMap<>(); + private Map serviceAndPnfRelationMap = new HashMap<>(); @Override - public Optional getEntryFor(String correlationId) throws IOException { + public Optional getEntryFor(String correlationId) { if (Objects.equals(correlationId, ID_WITH_ENTRY)) { return Optional.of(new Pnf()); } else { @@ -50,15 +49,25 @@ public class AaiConnectionTestImpl implements AaiConnection { } @Override - public void createEntry(String correlationId, Pnf entry) throws IOException { + public void createEntry(String correlationId, Pnf entry) { created.put(correlationId, entry); } + @Override + public void createRelation(String serviceInstanceId, String pnfName) { + serviceAndPnfRelationMap.put(serviceInstanceId, pnfName); + } + public Map getCreated() { return created; } + public Map getServiceAndPnfRelationMap() { + return serviceAndPnfRelationMap; + } + public void reset() { created.clear(); + serviceAndPnfRelationMap.clear(); } } diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java index 2d0d4b51a9..db6cbe06ae 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java @@ -31,15 +31,19 @@ import java.util.Map; import java.util.UUID; import org.assertj.core.api.Assertions; +import org.assertj.core.data.MapEntry; import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Before; import org.junit.Test; import org.onap.so.BaseIntegrationTest; import org.springframework.beans.factory.annotation.Autowired; public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest { - private static final String TIMEOUT_10_S = "PT10S"; private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString(); + private static final String SERVICE_INSTANCE_ID = "serviceForInstance"; + + private Map variables; @Autowired private AaiConnectionTestImpl aaiConnection; @@ -47,14 +51,18 @@ public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest { @Autowired private DmaapClientTestImpl dmaapClientTestImpl; + @Before + public void setup() { + aaiConnection.reset(); + variables = new HashMap<>(); + variables.put("serviceInstanceId", SERVICE_INSTANCE_ID); + variables.put(PNF_UUID, VALID_UUID); + } + @Test public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() { // given - aaiConnection.reset(); - Map variables = new HashMap<>(); - variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITH_ENTRY); - variables.put(PNF_UUID, VALID_UUID); // when ProcessInstance instance = runtimeService .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); @@ -70,19 +78,17 @@ public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest { "AaiEntryExists", "InformDmaapClient", "WaitForDmaapPnfReadyNotification", + "CreateRelationId", "AaiEntryUpdated" ); + Assertions.assertThat(aaiConnection.getServiceAndPnfRelationMap()). + containsOnly(MapEntry.entry(SERVICE_INSTANCE_ID,AaiConnectionTestImpl.ID_WITH_ENTRY)); } @Test public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() { // given - aaiConnection.reset(); - - Map variables = new HashMap<>(); - variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); variables.put(CORRELATION_ID, AaiConnectionTestImpl.ID_WITHOUT_ENTRY); - variables.put(PNF_UUID, VALID_UUID); // when ProcessInstance instance = runtimeService .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); @@ -99,8 +105,11 @@ public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest { "AaiEntryExists", "InformDmaapClient", "WaitForDmaapPnfReadyNotification", + "CreateRelationId", "AaiEntryUpdated" ); Assertions.assertThat(aaiConnection.getCreated()).containsOnlyKeys(AaiConnectionTestImpl.ID_WITHOUT_ENTRY); + Assertions.assertThat(aaiConnection.getServiceAndPnfRelationMap()). + containsOnly(MapEntry.entry(SERVICE_INSTANCE_ID,AaiConnectionTestImpl.ID_WITHOUT_ENTRY)); } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java index d57e48781d..1bf2a290cb 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java @@ -23,7 +23,11 @@ package org.onap.so.bpmn.infrastructure.pnf.aai; import java.util.Optional; import org.onap.aai.domain.yang.Pnf; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.AAIRestClientImpl; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.springframework.stereotype.Component; @Component @@ -40,4 +44,12 @@ public class AaiConnectionImpl implements AaiConnection { AAIRestClientImpl restClient = new AAIRestClientImpl(); restClient.createPnf(correlationId, entry); } + + @Override + public void createRelation(String serviceInstanceId, String pnfName) { + AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + serviceInstanceId); + AAIResourceUri pnfUri = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfName); + new AAIResourcesClient().connect(serviceInstanceURI, pnfUri); + } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelation.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelation.java new file mode 100644 index 0000000000..21d43964f8 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelation.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 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 + * + * 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.bpmn.infrastructure.pnf.delegate; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.so.bpmn.common.scripts.ExceptionUtil; +import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CreateRelation implements JavaDelegate { + + private static final Logger logger = LoggerFactory.getLogger(CreateRelation.class); + + private AaiConnection aaiConnectionImpl; + + @Autowired + public CreateRelation(AaiConnection aaiConnectionImpl) { + this.aaiConnectionImpl = aaiConnectionImpl; + } + + @Override + public void execute(DelegateExecution delegateExecution) { + String serviceInstanceId = (String) delegateExecution.getVariable("serviceInstanceId"); + String pnfName = (String) delegateExecution.getVariable("correlationId"); + try { + aaiConnectionImpl.createRelation(serviceInstanceId, pnfName); + } catch (Exception e) { + new ExceptionUtil().buildAndThrowWorkflowException(delegateExecution, 9999, + "An exception occurred when making service and pnf relation. Exception: " + e.getMessage()); + } + logger.debug("The relation has been made between service with id: {} and pnf with name: {}", + serviceInstanceId, pnfName); + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiConnection.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiConnection.java index 5165912653..eaabb2bfbb 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiConnection.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/implementation/AaiConnection.java @@ -29,4 +29,6 @@ public interface AaiConnection { Optional getEntryFor(String correlationId) throws IOException; void createEntry(String correlationId, Pnf entry) throws IOException; + + void createRelation(String serviceInstanceId, String pnfName) throws IOException; } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java index 201e791a24..76b62a9cea 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java @@ -37,7 +37,7 @@ public class AaiConnectionTestImpl implements AaiConnection { private Map created = new HashMap<>(); @Override - public Optional getEntryFor(String correlationId) throws IOException { + public Optional getEntryFor(String correlationId) { if (Objects.equals(correlationId, ID_WITH_ENTRY)) { return Optional.of(new Pnf()); } else { @@ -50,6 +50,10 @@ public class AaiConnectionTestImpl implements AaiConnection { created.put(correlationId, entry); } + @Override + public void createRelation(String serviceInstanceId, String pnfName) { + } + public Map getCreated() { return created; } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java index 7df6757817..300d1e4c9b 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java @@ -36,4 +36,10 @@ public class AaiConnectionThrowingException implements AaiConnection { public void createEntry(String correlationId, Pnf entry) throws IOException { throw new IOException(); } + + @Override + public void createRelation(String serviceInstanceId, String pnfName) throws IOException { + throw new IOException(); + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelationTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelationTest.java new file mode 100644 index 0000000000..2dd3e23828 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateRelationTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 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 + * + * 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.bpmn.infrastructure.pnf.delegate; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.infrastructure.pnf.aai.AaiConnectionImpl; +import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; + +public class CreateRelationTest { + + private static final String SERVICE_INSTANCE_ID = "serviceTest"; + private static final String PNF_NAME = "pnfNameTest"; + + private DelegateExecutionFake executionFake; + + @Before + public void setUp() { + executionFake = new DelegateExecutionFake(); + executionFake.setVariable("serviceInstanceId", SERVICE_INSTANCE_ID); + executionFake.setVariable("correlationId", PNF_NAME); + } + + @Test + public void createRelationSuccessful() throws IOException { + // given + AaiConnection aaiConnectionMock = mock(AaiConnectionImpl.class); + CreateRelation testedObject = new CreateRelation(aaiConnectionMock); + // when + testedObject.execute(executionFake); + // then + verify(aaiConnectionMock).createRelation(SERVICE_INSTANCE_ID, PNF_NAME); + } + + @Test + public void shouldThrowBpmnErrorWhenExceptionOccurred() { + CreateRelation testedObject = new CreateRelation(new AaiConnectionThrowingException()); + executionFake.setVariable("testProcessKey", "testProcessKeyValue"); + + assertThatThrownBy(() -> testedObject.execute(executionFake)).isInstanceOf(BpmnError.class); + } +} diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateAndActivatePnfResource.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateAndActivatePnfResource.bpmn index d8079174c1..5defe2121b 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateAndActivatePnfResource.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateAndActivatePnfResource.bpmn @@ -1,5 +1,5 @@ - + @@ -17,7 +17,7 @@ #{!aaiContainsInfoAboutPnf} - + @@ -59,9 +59,6 @@ SequenceFlow_1miyzfe - - SequenceFlow_0p09qgm - SequenceFlow_1o8od8e SequenceFlow_0p09qgm @@ -77,13 +74,20 @@ SequenceFlow_1qr6cmf SequenceFlow_17s9025 + + + SequenceFlow_0o6zhjk + + + SequenceFlow_0p09qgm + SequenceFlow_0o6zhjk + - Inputs: + + - uuid - String]]> @@ -100,9 +104,9 @@ - + - + @@ -118,38 +122,38 @@ - - + + - - - - + + + + - - + + - - + + - - + + @@ -158,22 +162,22 @@ - - + + - - + + - - + + @@ -191,19 +195,19 @@ - - + + - - + + - - + + @@ -215,9 +219,9 @@ - - - + + + @@ -226,22 +230,22 @@ - - + + - + - - + + - - + + @@ -250,15 +254,15 @@ - - + + - - + + @@ -267,8 +271,8 @@ - - + + @@ -282,6 +286,16 @@ + + + + + + + + + + -- cgit 1.2.3-korg