From 6c2c8a66fade016f74b51bdfea3ba04494530b97 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 4 Oct 2018 16:15:13 +0200 Subject: Pnf Spring Environment correction Change-Id: Ic9d83e2919bd1f947fdca07d8982bd5e794c9dbe Issue-ID: SO-1102 Signed-off-by: Lukasz Muszkieta --- .../src/main/resources/application-local.yml | 12 +++- .../resources/applicationContext_forPnfTesting.xml | 16 +++--- .../infrastructure/pnf/aai/AaiConnectionImpl.java | 2 + .../pnf/delegate/CancelDmaapSubscription.java | 2 + .../delegate/CheckAaiForCorrelationIdDelegate.java | 4 +- .../delegate/CreateAaiEntryWithPnfIdDelegate.java | 2 + .../pnf/delegate/InformDmaapClient.java | 2 + .../pnf/delegate/PnfCheckInputs.java | 12 +++- .../pnf/dmaap/PnfEventReadyDmaapClient.java | 67 ++++------------------ .../pnf/delegate/PnfCheckInputsTest.java | 29 +++++----- .../pnf/dmaap/PnfEventReadyDmaapClientTest.java | 20 +++---- .../process/CreateAndActivatePnfResource.bpmn | 10 ++-- .../src/test/resources/application-test.yaml | 11 ++++ 13 files changed, 88 insertions(+), 101 deletions(-) diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/application-local.yml b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-local.yml index 46b46f8833..911aabdaec 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/resources/application-local.yml +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-local.yml @@ -4,6 +4,7 @@ aai: timeout: '30000' endpoint: http://localhost:8443 workflowAaiDistributionDelay: PT30S + pnfEntryNotificationTimeout: P14D camunda: bpm: admin-user: @@ -15,7 +16,16 @@ camunda: core-pool-size: 3 entitymanager: packagesToScan: com - +pnf: + dmaap: + host: message-router + port: 3904 + protocol: http + uriPathPrefix: events + topicName: pnfReady + consumerGroup: consumerGroup + consumerId: consumerId + topicListenerDelayInSeconds: 5 mso: correlation: timeout: 60 diff --git a/bpmn/mso-infrastructure-bpmn/src/test/resources/applicationContext_forPnfTesting.xml b/bpmn/mso-infrastructure-bpmn/src/test/resources/applicationContext_forPnfTesting.xml index 72462bd092..3a41801d4a 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/resources/applicationContext_forPnfTesting.xml +++ b/bpmn/mso-infrastructure-bpmn/src/test/resources/applicationContext_forPnfTesting.xml @@ -28,7 +28,6 @@ - @@ -49,22 +48,21 @@ - + - + - - + + - + - - - + + 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 a92fad2e5f..8bba435d0c 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 @@ -25,7 +25,9 @@ import java.util.UUID; import org.onap.aai.domain.yang.Pnf; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; import org.onap.so.client.aai.AAIRestClientImpl; +import org.springframework.stereotype.Component; +@Component public class AaiConnectionImpl implements AaiConnection { @Override diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java index a10267e666..05109abc84 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java @@ -24,7 +24,9 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +@Component public class CancelDmaapSubscription implements JavaDelegate { private DmaapClient dmaapClient; diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java index 12ddf8465e..b49c4211b1 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -20,12 +20,10 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP; 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.CORRELATION_ID; import java.io.IOException; -import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.common.scripts.ExceptionUtil; @@ -34,6 +32,7 @@ import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiResponse; import org.onap.so.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * Implementation of "Check AAI for correlation_id" task in CreateAndActivatePnfResource.bpmn @@ -46,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired; * - aaiContainsInfoAboutIp - local Boolean */ +@Component public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, CheckAaiForCorrelationIdDelegate.class); private CheckAaiForCorrelationIdImplementation implementation = new CheckAaiForCorrelationIdImplementation(); diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java index ec1ef21028..a8754cd4a0 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java @@ -27,6 +27,7 @@ import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.aai.domain.yang.Pnf; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * Implementation of "Create AAI entry with pnf-id = correlation_id" task in CreateAndActivatePnfResource.bpmn @@ -34,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; * Inputs: * - correlationId - String */ +@Component public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate { private AaiConnection aaiConnection; diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java index 61b1ca4cae..1a75b0998c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java @@ -25,7 +25,9 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +@Component public class InformDmaapClient implements JavaDelegate { private DmaapClient dmaapClient; diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java index d210e5e64f..164f51f579 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java @@ -27,13 +27,22 @@ 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.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component public class PnfCheckInputs implements JavaDelegate { private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, PnfCheckInputs.class); private String defaultTimeout; + @Autowired + public PnfCheckInputs(@Value("${aai.pnfEntryNotificationTimeout}") String defaultTimeout) { + this.defaultTimeout = defaultTimeout; + } + @Override public void execute(DelegateExecution execution) { String correlationId = (String) execution.getVariable(CORRELATION_ID); @@ -51,7 +60,4 @@ public class PnfCheckInputs implements JavaDelegate { } } - public void setDefaultTimeout(String defaultTimeout) { - this.defaultTimeout = defaultTimeout; - } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java index 70323b726c..518d7ff194 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java @@ -21,16 +21,13 @@ package org.onap.so.bpmn.infrastructure.pnf.dmaap; import java.io.IOException; -import java.net.URI; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; - import javax.ws.rs.core.UriBuilder; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; @@ -38,43 +35,35 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component -@Scope("prototype") public class PnfEventReadyDmaapClient implements DmaapClient { - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, PnfEventReadyDmaapClient.class); + private static final MsoLogger LOGGER = MsoLogger + .getMsoLogger(MsoLogger.Catalog.RA, PnfEventReadyDmaapClient.class); - private final Environment env; private HttpClient httpClient; - private String dmaapHost; - private int dmaapPort; - private String dmaapProtocol; - private String dmaapUriPathPrefix; - private String dmaapTopicName; - private String consumerId; - private String consumerGroup; private Map pnfCorrelationIdToThreadMap; private HttpGet getRequest; - private int dmaapClientDelayInSeconds; + private int topicListenerDelayInSeconds; private volatile ScheduledThreadPoolExecutor executor; private volatile boolean dmaapThreadListenerIsRunning; @Autowired public PnfEventReadyDmaapClient(Environment env) { - this.env = env; - } - - public void init() { httpClient = HttpClientBuilder.create().build(); pnfCorrelationIdToThreadMap = new ConcurrentHashMap<>(); - dmaapHost = env.getProperty("pnf.dmaap.host"); - dmaapPort = env.getProperty("pnf.dmaap.port", Integer.class); + topicListenerDelayInSeconds = env.getProperty("pnf.dmaap.topicListenerDelayInSeconds", Integer.class); executor = null; - getRequest = new HttpGet(buildURI()); + getRequest = new HttpGet(UriBuilder.fromUri(env.getProperty("pnf.dmaap.uriPathPrefix")) + .scheme(env.getProperty("pnf.dmaap.protocol")) + .host(env.getProperty("pnf.dmaap.host")) + .port(env.getProperty("pnf.dmaap.port", Integer.class)) + .path(env.getProperty("pnf.dmaap.topicName")) + .path(env.getProperty("pnf.dmaap.consumerGroup")) + .path(env.getProperty("pnf.dmaap.consumerId")).build()); } @Override @@ -102,7 +91,7 @@ public class PnfEventReadyDmaapClient implements DmaapClient { executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); executor.scheduleWithFixedDelay(new DmaapTopicListenerThread(), 0, - dmaapClientDelayInSeconds, TimeUnit.SECONDS); + topicListenerDelayInSeconds, TimeUnit.SECONDS); dmaapThreadListenerIsRunning = true; } } @@ -115,38 +104,6 @@ public class PnfEventReadyDmaapClient implements DmaapClient { } } - private URI buildURI() { - return UriBuilder.fromUri(dmaapUriPathPrefix) - .scheme(dmaapProtocol) - .host(dmaapHost) - .port(dmaapPort).path(dmaapTopicName) - .path(consumerGroup).path(consumerId).build(); - } - - public void setDmaapProtocol(String dmaapProtocol) { - this.dmaapProtocol = dmaapProtocol; - } - - public void setDmaapUriPathPrefix(String dmaapUriPathPrefix) { - this.dmaapUriPathPrefix = dmaapUriPathPrefix; - } - - public void setDmaapTopicName(String dmaapTopicName) { - this.dmaapTopicName = dmaapTopicName; - } - - public void setConsumerId(String consumerId) { - this.consumerId = consumerId; - } - - public void setConsumerGroup(String consumerGroup) { - this.consumerGroup = consumerGroup; - } - - public void setDmaapClientDelayInSeconds(int dmaapClientDelayInSeconds) { - this.dmaapClientDelayInSeconds = dmaapClientDelayInSeconds; - } - class DmaapTopicListenerThread implements Runnable { @Override diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java index aab289fd90..2e8fb4be78 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java @@ -30,55 +30,52 @@ import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableName import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.junit.Before; import org.junit.Test; public class PnfCheckInputsTest { - private PnfCheckInputs delegate; - - @Before - public void setUp() throws Exception { - delegate = new PnfCheckInputs(); - } + private static final String DEFAULT_TIMEOUT = "P1D"; private DelegateExecution mockDelegateExecution() { + new PnfCheckInputs(DEFAULT_TIMEOUT); DelegateExecution delegateExecution = mock(DelegateExecution.class); when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); return delegateExecution; } @Test - public void shouldThrowException_whenPnfIdNotSet() throws Exception { + public void shouldThrowException_whenPnfIdNotSet() { // given + PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT); DelegateExecution delegateExecution = mockDelegateExecution(); // when, then - assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class); + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); } private DelegateExecution mockDelegateExecutionWithCorrelationId() { + new PnfCheckInputs(DEFAULT_TIMEOUT); DelegateExecution delegateExecution = mockDelegateExecution(); when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId"); return delegateExecution; } @Test - public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() throws Exception { + public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() { // given + PnfCheckInputs testedObject = new PnfCheckInputs(null); DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); // when, then - assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class); + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); } @Test - public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() throws Exception { + public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() { // given - String defaultTimeout = "T1D"; - delegate.setDefaultTimeout(defaultTimeout); + PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT); DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); // when - delegate.execute(delegateExecution); + testedObject.execute(delegateExecution); // then - verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(defaultTimeout)); + verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT)); } } \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java index 9ae7ad9bdc..aab01c0a3e 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java @@ -33,7 +33,6 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import org.apache.http.HttpEntity; @@ -47,7 +46,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.onap.so.bpmn.infrastructure.pnf.dmaap.PnfEventReadyDmaapClient.DmaapTopicListenerThread; @@ -81,6 +79,8 @@ public class PnfEventReadyDmaapClientTest { private static final String EVENT_TOPIC_TEST = "eventTopicTest"; private static final String CONSUMER_ID = "consumerTestId"; private static final String CONSUMER_GROUP = "consumerGroupTest"; + private static final int TOPIC_LISTENER_DELAY_IN_SECONDS = 5; + @Mock private Environment env; private PnfEventReadyDmaapClient testedObject; @@ -92,16 +92,16 @@ public class PnfEventReadyDmaapClientTest { @Before public void init() throws NoSuchFieldException, IllegalAccessException { - testedObject = new PnfEventReadyDmaapClient(env); when(env.getProperty(eq("pnf.dmaap.port"), eq(Integer.class))).thenReturn(PORT); when(env.getProperty(eq("pnf.dmaap.host"))).thenReturn(HOST); - testedObject.setDmaapProtocol(PROTOCOL); - testedObject.setDmaapUriPathPrefix(URI_PATH_PREFIX); - testedObject.setDmaapTopicName(EVENT_TOPIC_TEST); - testedObject.setConsumerId(CONSUMER_ID); - testedObject.setConsumerGroup(CONSUMER_GROUP); - testedObject.setDmaapClientDelayInSeconds(1); - testedObject.init(); + when(env.getProperty(eq("pnf.dmaap.protocol"))).thenReturn(PROTOCOL); + when(env.getProperty(eq("pnf.dmaap.uriPathPrefix"))).thenReturn(URI_PATH_PREFIX); + when(env.getProperty(eq("pnf.dmaap.topicName"))).thenReturn(EVENT_TOPIC_TEST); + when(env.getProperty(eq("pnf.dmaap.consumerId"))).thenReturn(CONSUMER_ID); + when(env.getProperty(eq("pnf.dmaap.consumerGroup"))).thenReturn(CONSUMER_GROUP); + when(env.getProperty(eq("pnf.dmaap.topicListenerDelayInSeconds"), eq(Integer.class))) + .thenReturn(TOPIC_LISTENER_DELAY_IN_SECONDS); + testedObject = new PnfEventReadyDmaapClient(env); testedObjectInnerClassThread = testedObject.new DmaapTopicListenerThread(); httpClientMock = mock(HttpClient.class); threadMockToNotifyCamundaFlow = mock(Runnable.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 89d66bfdb6..e0b14ab0db 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 @@ -27,15 +27,15 @@ #{aaiContainsInfoAboutPnf} - + SequenceFlow_0j5ksz1 SequenceFlow_0967g8p - + SequenceFlow_1kc34bc SequenceFlow_1miyzfe - + SequenceFlow_17s9025 SequenceFlow_1o8od8e @@ -44,7 +44,7 @@ SequenceFlow_1l1t6ak SequenceFlow_17s9025 - + SequenceFlow_0v5ffpe SequenceFlow_1qr6cmf @@ -53,7 +53,7 @@ SequenceFlow_1l1t6ak SequenceFlow_0v5ffpe - + SequenceFlow_0967g8p SequenceFlow_1j4r3zt diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml index 6f67a9ccc4..d9ad1363e4 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -1,6 +1,7 @@ aai: auth: 26AFB797A6A57960D5D718491925C50F77CDC22AC394B3DBA09950D8FD1C0764 endpoint: http://localhost:${wiremock.server.port} + pnfEntryNotificationTimeout: P14D appc: client: key: iaEMAfjsVsZnraBP @@ -29,6 +30,16 @@ log: sdncAdapter: 'true' vnfAdapterCreateV1: 'true' vnfAdapterRestV1: 'true' +pnf: + dmaap: + host: hostTest + port: 1234 + protocol: http + uriPathPrefix: events + topicName: pnfReady + consumerGroup: consumerGroup + consumerId: consumerId + topicListenerDelayInSeconds: 5 mso: adapters: requestDb: -- cgit 1.2.3-korg From 373c057bfa82583f615ea46814ad3cdf9ea8d669 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Thu, 25 Oct 2018 11:56:43 -0700 Subject: Resolve vf_module_id setting bug Do not remove vf_module_id and vnf_id from parameters in HeatUtils. Issue-ID: SO-1165 Change-Id: I6f00350a6f7dc419a8be9b90b28188228949cb43 Signed-off-by: Marcus G K Williams --- .../so/openstack/utils/MsoMulticloudUtils.java | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 076e03b6b3..8f71af4dfe 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -76,7 +76,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ public static final String VF_MODULE_ID = "vf_module_id"; public static final String TEMPLATE_TYPE = "template_type"; public static final List MULTICLOUD_INPUTS = - Arrays.asList(OOF_DIRECTIVES, SDNC_DIRECTIVES, GENERIC_VNF_ID, VF_MODULE_ID, TEMPLATE_TYPE); + Arrays.asList(OOF_DIRECTIVES, SDNC_DIRECTIVES, TEMPLATE_TYPE); private static final Logger logger = LoggerFactory.getLogger(MsoMulticloudUtils.class); @@ -157,18 +157,29 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ for (String key: MULTICLOUD_INPUTS) { if (!stackInputs.isEmpty() && stackInputs.containsKey(key)) { - if ( key == OOF_DIRECTIVES) {oofDirectives = (String) stackInputs.get(key);} - if ( key == SDNC_DIRECTIVES) {sdncDirectives = (String) stackInputs.get(key);} - if ( key == GENERIC_VNF_ID) {genericVnfId = (String) stackInputs.get(key);} - if ( key == VF_MODULE_ID) {vfModuleId = (String) stackInputs.get(key);} - if ( key == TEMPLATE_TYPE) {templateType = (String) stackInputs.get(key);} - if (logger.isDebugEnabled()) { + if (key == OOF_DIRECTIVES) { + oofDirectives = (String) stackInputs.get(key); + } + if (key == SDNC_DIRECTIVES) { + sdncDirectives = (String) stackInputs.get(key); + } + if (key == TEMPLATE_TYPE) { + templateType = (String) stackInputs.get(key); + } + if (logger.isDebugEnabled()) { logger.debug(String.format("Found %s: %s", key, stackInputs.get(key))); } stackInputs.remove(key); } } + if (!stackInputs.isEmpty() && stackInputs.containsKey("VF_MODULE_ID")){ + vfModuleId = (String) stackInputs.get("VF_MODULE_ID"); + } + if (!stackInputs.isEmpty() && stackInputs.containsKey("GENERIC_VNF_ID")){ + genericVnfId = (String) stackInputs.get("GENERIC_VNF_ID"); + } + // create the multicloud payload CreateStackParam stack = createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, files, heatFiles); -- cgit 1.2.3-korg From 959493d3274d2f2749586248cf31ee12b730e2af Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 26 Oct 2018 15:05:42 -0400 Subject: Bug fixes October 26th Set non-custom health diagnostic check code to a default value. created custom java serialization for SimpleUri changed property value for cloud-owner in unit test converted aai call to use the AAI Client Correct a JUnit data file to include userParams values that are expected to be set. Set userParams on requestContext to parameters that need to be passed to downstream systems. Change-Id: I3974691875ef967f90a15f076ae27bc0cd76ee8e Issue-ID: SO-1169 Signed-off-by: Benjamin, Max (mb388a) --- .../tasks/BBInputSetupMapperLayer.java | 18 ++++++++++ .../tasks/BBInputSetupMapperLayerTest.java | 19 ++++++++++- .../GeneralBuildingBlockCMExpected.json | 1 + .../GeneralBuildingBlockExpected.json | 21 ++++++++++-- .../RequestContextExpected.json | 24 ++++++++++++-- .../RequestDetailsInput_mapReqContext.json | 17 +++++++++- .../scripts/UpdateVfModuleVolume.groovy | 14 +++++--- ...VfModuleTopologyOperationRequestMapperTest.java | 23 +++++++++---- .../so/client/aai/entities/uri/AAISimpleUri.java | 2 ++ .../entities/uri/AllottedResourceLookupUri.java | 1 + .../onap/so/client/aai/entities/uri/NodesUri.java | 2 ++ .../aai/entities/uri/ServiceInstanceUri.java | 1 + .../graphinventory/entities/uri/SimpleUri.java | 30 +++++++++++++---- .../org/onap/so/client/sdno/SDNOValidatorImpl.java | 2 ++ .../client/aai/entities/uri/AAISimpleUriTest.java | 38 +++++++++++++++++++++- .../java/org/onap/so/constants/DefaultsTest.java | 2 +- common/src/test/resources/application-test.yaml | 2 +- 17 files changed, 189 insertions(+), 28 deletions(-) diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java index d463fde09c..0f52c96d0e 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.servicedecomposition.tasks; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -84,6 +85,8 @@ import org.springframework.stereotype.Component; @Component("BBInputSetupMapperLayer") public class BBInputSetupMapperLayer { + private static final String USER_PARAM_NAME_KEY = "name"; + private static final String USER_PARAM_VALUE_KEY = "value"; private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BBInputSetupMapperLayer.class); @@ -332,6 +335,7 @@ public class BBInputSetupMapperLayer { if (null != requestParameters) { context.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType()); context.setRequestParameters(this.mapRequestParameters(requestDetails.getRequestParameters())); + context.setUserParams(this.mapNameValueUserParams(requestDetails.getRequestParameters())); } return context; } @@ -344,6 +348,20 @@ public class BBInputSetupMapperLayer { requestParams.setPayload(requestParameters.getPayload()); return requestParams; } + + protected HashMap mapNameValueUserParams(org.onap.so.serviceinstancebeans.RequestParameters requestParameters) { + HashMap userParamsResult = new HashMap(); + if (requestParameters.getUserParams() != null) { + List> userParams = requestParameters.getUserParams(); + for (Map userParamsMap : userParams) { + if ( userParamsMap.containsKey(USER_PARAM_NAME_KEY) && (userParamsMap.get(USER_PARAM_NAME_KEY) instanceof String) + && userParamsMap.containsKey(USER_PARAM_VALUE_KEY) && (userParamsMap.get(USER_PARAM_VALUE_KEY) instanceof String)) { + userParamsResult.put((String) userParamsMap.get(USER_PARAM_NAME_KEY), (String) userParamsMap.get(USER_PARAM_VALUE_KEY)); + } + } + } + return userParamsResult; + } protected OrchestrationContext mapOrchestrationContext(RequestDetails requestDetails) { OrchestrationContext context = new OrchestrationContext(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java index 94dbbf427c..1babac68ca 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java @@ -23,6 +23,8 @@ package org.onap.so.bpmn.servicedecomposition.tasks; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; @@ -33,7 +35,6 @@ import java.util.List; import java.util.Map; import org.junit.Test; -import org.mockito.InjectMocks; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; @@ -636,4 +637,20 @@ public class BBInputSetupMapperLayerTest { assertThat(actual, sameBeanAs(expected)); } + + @Test + public void testMapNameValueUserParams() throws IOException { + RequestDetails requestDetails = mapper.readValue(new File(RESOURCE_PATH + "RequestDetailsInput_mapReqContext.json"), RequestDetails.class); + HashMap actual = bbInputSetupMapperLayer.mapNameValueUserParams(requestDetails.getRequestParameters()); + + assertTrue(actual.containsKey("name1")); + assertTrue(actual.containsValue("value1")); + assertTrue(actual.get("name1").equals("value1")); + assertTrue(actual.containsKey("name2")); + assertTrue(actual.containsValue("value2")); + assertTrue(actual.get("name2").equals("value2")); + assertFalse(actual.containsKey("ignore")); + assertFalse(actual.containsValue("ignore")); + } + } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json index 8640c2e899..a53ed4dfde 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json @@ -1,6 +1,7 @@ { "requestContext": { "source": "VID", + "user-params": {}, "mso-request-id": "requestId", "action": "createInstance", "requestParameters": { diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json index cf65143c9a..926bf2ccb7 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json @@ -5,11 +5,28 @@ "requestor-id": "requestorId", "mso-request-id": "requestId", "subscription-service-type": "subscriptionServiceType", - "user-params": null, + "user-params": { + "name1": "value1", + "name2": "value2" + }, "action": "createInstance", "callback-url": "callbackURL", "requestParameters": { - "subscriptionServiceType": "subscriptionServiceType" + "subscriptionServiceType": "subscriptionServiceType", + "userParams": [ + { + "name": "name1", + "value": "value1" + }, + { + "name": "name2", + "value": "value2" + }, + { + "ignore": "false", + "skip": "ignore" + } + ] } }, "orchContext": { diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json index 6f82a9dd75..dfc6d4f555 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestContextExpected.json @@ -2,11 +2,29 @@ "product-family-id": "productFamilyId", "source": "source", "requestor-id": "requestorId", - "subscription-service-type": "subscriptionServiceType", - "user-params": null, + "subscription-service-type": "subscriptionServiceType", "action": null, "callback-url": "callbackURL", + "user-params": { + "name1": "value1", + "name2": "value2" + }, "requestParameters": { - "subscriptionServiceType": "subscriptionServiceType" + "subscriptionServiceType": "subscriptionServiceType", + "userParams": [ + { + "name": "name1", + "value": "value1" + }, + { + "name": "name2", + "value": "value2" + }, + { + "ignore": "false", + "skip": "ignore" + } + ] } + } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json index e91875135b..7386828d27 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/RequestDetailsInput_mapReqContext.json @@ -7,7 +7,22 @@ "requestorId": "requestorId" }, "requestParameters": { - "subscriptionServiceType": "subscriptionServiceType" + "subscriptionServiceType": "subscriptionServiceType", + "userParams": [ + { + "name": "name1", + "value": "value1" + }, + { + "name": "name2", + "value": "value2" + }, + { + "ignore": "false", + "skip": "ignore" + } + ] + } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateVfModuleVolume.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateVfModuleVolume.groovy index 82e27ec116..0f9a0ad292 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateVfModuleVolume.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateVfModuleVolume.groovy @@ -29,10 +29,13 @@ import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.VfModuleBase import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.core.WorkflowException +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.constants.Defaults import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse -import org.springframework.web.util.UriUtils class UpdateVfModuleVolume extends VfModuleBase { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UpdateVfModuleVolume.class); @@ -172,14 +175,15 @@ class UpdateVfModuleVolume extends VfModuleBase { try { def volumeGroupId = execution.getVariable('UPDVfModVol_volumeGroupId') def aicCloudRegion = execution.getVariable('UPDVfModVol_aicCloudRegion') - def endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + - '/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/' + UriUtils.encode(aicCloudRegion, "UTF-8") + - '/volume-groups/volume-group/' + UriUtils.encode(volumeGroupId, "UTF-8") + + AaiUtil aaiUtil = new AaiUtil(this) + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId) + String endPoint = aaiUtil.createAaiUri(uri) + msoLogger.debug('Sending GET to AAI endpoint \'' + endPoint + '\'') msoLogger.debug("UpdateVfModuleVolume sending GET for quering AAI endpoint: " + endPoint) - AaiUtil aaiUtil = new AaiUtil(this) APIResponse response = aaiUtil.executeAAIGetCall(execution, endPoint) def int statusCode = response.getStatusCode() def responseData = response.getResponseBodyAsString() diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java index 04397c499d..f492ba3ead 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java @@ -27,7 +27,10 @@ import static org.junit.Assert.assertNull; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.junit.Rule; import org.junit.Test; @@ -40,6 +43,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; @@ -80,8 +84,8 @@ public class VfModuleTopologyOperationRequestMapperTest { customer.getServiceSubscription().getServiceInstances().add(serviceInstance); // RequestContext requestContext = new RequestContext(); - HashMap userParams = new HashMap(); - userParams.put("key1", "value1"); + HashMap userParams = new HashMap(); + userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); @@ -108,7 +112,7 @@ public class VfModuleTopologyOperationRequestMapperTest { modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); vfModule.setModelInfoVfModule(modelInfoVfModule); HashMap cloudParams = new HashMap(); - userParams.put("key2", "value2"); + cloudParams.put("key2", "value2"); vfModule.setCloudParams(cloudParams); VolumeGroup volumeGroup = new VolumeGroup(); @@ -189,9 +193,14 @@ public class VfModuleTopologyOperationRequestMapperTest { customer.getServiceSubscription().getServiceInstances().add(serviceInstance); // RequestContext requestContext = new RequestContext(); - HashMap userParams = new HashMap(); - userParams.put("key1", "value1"); - requestContext.setUserParams(userParams); + RequestParameters requestParameters = new RequestParameters(); + HashMap userParams1 = new HashMap(); + userParams1.put("key1", "value1"); + List> userParams = new ArrayList>(); + userParams.add(userParams1); + + requestParameters.setUserParams(userParams); + requestContext.setRequestParameters(requestParameters); requestContext.setProductFamilyId("productFamilyId"); GenericVnf vnf = new GenericVnf(); @@ -225,7 +234,7 @@ public class VfModuleTopologyOperationRequestMapperTest { assertNull(vfModuleSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); assertEquals("vnfModelCustomizationUuid", vfModuleSDNCrequest.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("vfModuleModelCustomizationUuid", vfModuleSDNCrequest.getVfModuleInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("vfModuleModelCustomizationUuid", vfModuleSDNCrequest.getVfModuleInformation().getOnapModelInformation().getModelCustomizationUuid()); } @Test diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/AAISimpleUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/AAISimpleUri.java index 9b5acc5bee..76413c2594 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/uri/AAISimpleUri.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/AAISimpleUri.java @@ -34,6 +34,8 @@ import org.onap.so.client.graphinventory.entities.uri.SimpleUri; public class AAISimpleUri extends SimpleUri implements AAIResourceUri { + private static final long serialVersionUID = -6397024057188453229L; + protected AAISimpleUri(AAIObjectType type, Object... values) { super(type, values); diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUri.java index 091d0c9e97..329471243b 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUri.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUri.java @@ -30,6 +30,7 @@ import org.onap.so.client.aai.AAIResourcesClient; public class AllottedResourceLookupUri extends HttpLookupUri { + private static final long serialVersionUID = -9212594383876793188L; protected AllottedResourceLookupUri(Object... values) { super(AAIObjectType.ALLOTTED_RESOURCE, values); } diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/NodesUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/NodesUri.java index 3c9ca0ed7f..6ffc6ecd9b 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/uri/NodesUri.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/NodesUri.java @@ -29,6 +29,8 @@ import org.onap.so.client.graphinventory.GraphInventoryObjectType; public class NodesUri extends AAISimpleUri { + private static final long serialVersionUID = 8818689895730182042L; + protected NodesUri(AAIObjectType type, Object... values) { super(type, values); } diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java index 00a213b264..324193dc84 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java @@ -30,6 +30,7 @@ import org.onap.so.client.aai.AAIResourcesClient; public class ServiceInstanceUri extends HttpLookupUri { + private static final long serialVersionUID = 2248914170527514548L; protected ServiceInstanceUri(Object... values) { super(AAIObjectType.SERVICE_INSTANCE, values); } diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java index 026f1c3929..874b06e192 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java @@ -20,6 +20,10 @@ package org.onap.so.client.graphinventory.entities.uri; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -29,18 +33,19 @@ import java.util.Map; import javax.ws.rs.core.UriBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.onap.so.client.graphinventory.Format; import org.onap.so.client.aai.entities.uri.AAIUri; -import org.onap.so.client.graphinventory.entities.uri.Depth; -import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser; -import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImpl; +import org.onap.so.client.graphinventory.Format; import org.onap.so.client.graphinventory.GraphInventoryObjectPlurals; import org.onap.so.client.graphinventory.GraphInventoryObjectType; +import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser; +import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImpl; import org.springframework.web.util.UriUtils; -public class SimpleUri implements GraphInventoryResourceUri { +public class SimpleUri implements GraphInventoryResourceUri, Serializable { - protected UriBuilder internalURI; + private static final long serialVersionUID = -337701171277616439L; + + protected transient UriBuilder internalURI; protected final static String relationshipAPI = "/relationship-list/relationship"; protected final static String relatedTo = "/related-to"; protected final Object[] values; @@ -89,6 +94,9 @@ public class SimpleUri implements GraphInventoryResourceUri { this.values = childValues; } + protected void setInternalURI(UriBuilder builder) { + this.internalURI = builder; + } @Override public SimpleUri relationshipAPI() { this.internalURI = internalURI.path(relationshipAPI); @@ -236,4 +244,14 @@ public class SimpleUri implements GraphInventoryResourceUri { return type.uriTemplate(); } + private void writeObject(ObjectOutputStream oos) throws IOException { + oos.defaultWriteObject(); + oos.writeUTF(this.internalURI.toTemplate()); + } + + private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { + ois.defaultReadObject(); + String uri = ois.readUTF(); + this.setInternalURI(UriBuilder.fromUri(uri)); + } } diff --git a/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java b/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java index be79c8b927..b11003ed1e 100644 --- a/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java +++ b/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java @@ -47,6 +47,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class SDNOValidatorImpl implements SDNOValidator { private final static String clientName = "MSO"; + private final static String HEALTH_DIAGNOSTIC_CODE_DEFAULT = "default"; @Override public boolean healthDiagnostic(String vnfId, UUID uuid, String requestingUserId) throws IOException, Exception { @@ -99,6 +100,7 @@ public class SDNOValidatorImpl implements SDNOValidator { request.setRequestNodeIp(vnf.getIpv4OamAddress()); //generic-vnf oam ip request.setRequestUserId(requestingUserId); //mech id? request.setRequestId(uuid.toString()); //something to identify this request by for polling + request.setHealthDiagnosticCode(HEALTH_DIAGNOSTIC_CODE_DEFAULT); input.setRequestHealthDiagnostic(request); diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java index fcf054f489..2a0e9df9ed 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java @@ -21,15 +21,24 @@ package org.onap.so.client.aai.entities.uri; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.Map; import org.junit.Test; import org.onap.so.client.aai.AAIObjectPlurals; import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.graphinventory.entities.uri.Depth; +import org.onap.so.client.graphinventory.entities.uri.SimpleUri; public class AAISimpleUriTest { @@ -83,4 +92,31 @@ public class AAISimpleUriTest { assertEquals("my value", keys.get("service-type")); } + + @Test + public void serializeTest() throws IOException, ClassNotFoundException { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + + uri.depth(Depth.ONE); + uri.limit(1); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + ObjectOutputStream objectOutputStream + = new ObjectOutputStream(bos); + objectOutputStream.writeObject(uri); + objectOutputStream.flush(); + objectOutputStream.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + + ObjectInputStream objectInputStream + = new ObjectInputStream(bis); + AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject(); + objectInputStream.close(); + + uri.queryParam("test", "value"); + e2.queryParam("test", "value"); + + assertEquals(e2.build().toString(), uri.build().toString()); + } } diff --git a/common/src/test/java/org/onap/so/constants/DefaultsTest.java b/common/src/test/java/org/onap/so/constants/DefaultsTest.java index 1bcee07118..6383d0ea4c 100644 --- a/common/src/test/java/org/onap/so/constants/DefaultsTest.java +++ b/common/src/test/java/org/onap/so/constants/DefaultsTest.java @@ -41,6 +41,6 @@ public class DefaultsTest { @Test public void checkValue() { - assertEquals("CloudOwner", Defaults.CLOUD_OWNER.toString()); + assertEquals("my-custom-owner", Defaults.CLOUD_OWNER.toString()); } } diff --git a/common/src/test/resources/application-test.yaml b/common/src/test/resources/application-test.yaml index cf386cb6fc..1a3e97c451 100644 --- a/common/src/test/resources/application-test.yaml +++ b/common/src/test/resources/application-test.yaml @@ -1,4 +1,4 @@ org: onap: so: - cloud-owner: CloudOwner \ No newline at end of file + cloud-owner: my-custom-owner \ No newline at end of file -- cgit 1.2.3-korg From 649c4e85cc991ffe9c13fd3fab4cc3a303faa656 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Thu, 25 Oct 2018 07:49:31 -0700 Subject: Fix Error, Check that vimID is present Issue-ID: SO-1156 Change-Id: I14445f0e6dbed00b37a189f3a7c05923c6d4e5ab Signed-off-by: Marcus G K Williams --- .../vcpe/scripts/CreateVcpeResCustService.groovy | 63 +++++++++++----- .../scripts/CreateVcpeResCustServiceTest.groovy | 88 +++++++++++++++++++++- 2 files changed, 133 insertions(+), 18 deletions(-) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy index beac679691..1a47ef88e2 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy @@ -176,17 +176,30 @@ public class CreateVcpeResCustService extends AbstractServiceTaskProcessor { execution.setVariable("subscriberInfo", subscriberInfo) msoLogger.debug("Incoming subscriberInfo is: " + subscriberInfo) - // extract cloud configuration, split vid_ID into cloudOwner and cloudRegionId + // extract cloud configuration - if underscore "_" is present treat as vimId else it's a cloudRegion String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId") - def cloudRegion = vimId.split("_") - def cloudOwner = cloudRegion[0].toString() - def cloudRegionId = cloudRegion[1].toString() - execution.setVariable("cloudOwner", cloudOwner) - utils.log("DEBUG","cloudOwner: " + cloudOwner, isDebugEnabled) - execution.setVariable("cloudRegionId", cloudRegionId) - utils.log("DEBUG","cloudRegionId: " + cloudRegionId, isDebugEnabled) - + if (vimId.contains("_") && vimId.split("_").length == 2 ) { + def cloudRegion = vimId.split("_") + def cloudOwner = cloudRegion[0] + def cloudRegionId = cloudRegion[1] + execution.setVariable("cloudOwner", cloudOwner) + msoLogger.debug("cloudOwner: " + cloudOwner) + execution.setVariable("cloudRegionId", cloudRegionId) + msoLogger.debug("cloudRegionId: " + cloudRegionId) + } else { + msoLogger.debug("vimId is not present - setting cloudRegion/cloudOwner from request.") + String cloudOwner = jsonUtil.getJsonValue(createVcpeServiceRequest, + "requestDetails.cloudConfiguration.cloudOwner") + if (!cloudOwner?.empty && cloudOwner != "") + { + execution.setVariable("cloudOwner", cloudOwner) + msoLogger.debug("cloudOwner: " + cloudOwner) + } + def cloudRegionId = vimId + execution.setVariable("cloudRegionId", cloudRegionId) + msoLogger.debug("cloudRegionId: " + cloudRegionId) + } /* * Extracting User Parameters from incoming Request and converting into a Map */ @@ -592,16 +605,32 @@ public class CreateVcpeResCustService extends AbstractServiceTaskProcessor { msoLogger.debug(" vnfModelInfoString :" + vnfModelInfoString) - // extract cloud configuration + // extract cloud configuration - if underscore "_" is present treat as vimId else it's a cloudRegion String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId") - def cloudRegion = vimId.split("_") - execution.setVariable("cloudOwner", cloudRegion[0]) - msoLogger.debug("cloudOwner: "+ cloudRegion[0]) - execution.setVariable("cloudRegionId", cloudRegion[1]) - msoLogger.debug("cloudRegionId: "+ cloudRegion[1]) - execution.setVariable("lcpCloudRegionId", cloudRegion[1]) - msoLogger.debug("lcpCloudRegionId: "+ cloudRegion[1]) + if (vimId.contains("_") && vimId.split("_").length == 2 ) { + def cloudRegion = vimId.split("_") + execution.setVariable("cloudOwner", cloudRegion[0]) + msoLogger.debug("cloudOwner: " + cloudRegion[0]) + execution.setVariable("cloudRegionId", cloudRegion[1]) + msoLogger.debug("cloudRegionId: " + cloudRegion[1]) + execution.setVariable("lcpCloudRegionId", cloudRegion[1]) + msoLogger.debug("lcpCloudRegionId: " + cloudRegion[1]) + } else { + msoLogger.debug("vimId is not present - setting cloudRegion/cloudOwner from request.") + String cloudOwner = jsonUtil.getJsonValue(createVcpeServiceRequest, + "requestDetails.cloudConfiguration.cloudOwner") + if (!cloudOwner?.empty && cloudOwner != "") + { + execution.setVariable("cloudOwner", cloudOwner) + msoLogger.debug("cloudOwner: " + cloudOwner) + } + execution.setVariable("cloudRegionId", vimId) + msoLogger.debug("cloudRegionId: " + vimId) + execution.setVariable("lcpCloudRegionId", vimId) + msoLogger.debug("lcpCloudRegionId: " + vimId) + } + String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId") execution.setVariable("tenantId", tenantId) diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy index 84da045450..d0ded39146 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy @@ -31,6 +31,7 @@ import org.junit.Test import org.junit.Ignore import org.mockito.MockitoAnnotations import org.camunda.bpm.engine.delegate.BpmnError +import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.domain.HomingSolution import org.onap.so.bpmn.mock.FileUtil @@ -195,7 +196,53 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase { assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) })) } - + + @Test + @Ignore + public void preProcessRequest_vimId() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + UrnPropertiesReader + + def req = request + .replace('"mdt1"', '"CloudOwner_CloudRegion1"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn("PT5S") + when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRequest(mex) + + verify(mex).setVariable("cloudRegionId", "CloudRegion1") + verify(mex).setVariable("cloudOwner", "CloudOwner") + } + + @Test + @Ignore + public void preProcessRequest_noVimId() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + + def req = request + .replace('"mdt1"', '"CloudRegion1_"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn(60) + when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn("PT5S") + when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRequest(mex) + + verify(mex).setVariable("cloudRegionId", "CloudRegion1_") + verify(mex).setVariable("cloudOwner", "my-cloud-owner") + + } + + @Test // @Ignore public void preProcessRequest_BpmnError() { @@ -579,6 +626,45 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase { verify(mex).setVariable("cloudOwner", "my-cloud-owner") verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") } + + @Test + public void prepareVnfAndModulesCreate_noVimId() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + def req = request + .replace('"mdt1"', '"CloudRegion1_"') + + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(req) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("cloudRegionId", "CloudRegion1_") + verify(mex).setVariable("lcpCloudRegionId", "CloudRegion1_") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } + + @Test + public void prepareVnfAndModulesCreate_vimId() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + def req = request + .replace('"mdt1"', '"CloudOwner_CloudRegion1"') + + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(req) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("cloudOwner", "CloudOwner") + verify(mex).setVariable("cloudRegionId", "CloudRegion1") + verify(mex).setVariable("lcpCloudRegionId", "CloudRegion1") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } @Test // @Ignore -- cgit 1.2.3-korg