aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java (renamed from plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/PssdConfiguration.java)19
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcNotificationCallBack.java45
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java128
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java49
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java (renamed from plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/PssdConfigurationTest.java)26
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java180
-rw-r--r--plugins/reception-plugins/src/test/resources/handling-sdc.json6
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginTerminationException.java51
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java5
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java5
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginInitializationExceptionTest.java (renamed from reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java)18
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginTerminationExceptionTest.java49
12 files changed, 538 insertions, 43 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/PssdConfiguration.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java
index c5c877e1..945670b9 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/PssdConfiguration.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java
@@ -22,31 +22,26 @@ package org.onap.policy.distribution.reception.handling.sdc;
import java.util.List;
-import org.onap.sdc.api.consumer.IConfiguration;
import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
+import org.onap.sdc.api.consumer.IConfiguration;
/**
- * Properties for the handling Sdc
+ * This class represents the configurations needed for SDC Client.
*
*/
-public class PssdConfiguration implements IConfiguration {
+public class SdcConfiguration implements IConfiguration {
- // Configuration file structure
-
- // Configuration file properties
private PssdConfigurationParametersGroup configParameters = null;
/**
- * Original constructor
+ * Constructor for instantiating {@link SdcConfiguration}.
*
- * @param configParameters properties needed to be configured for the model loader
+ * @param configParameters the SDC Client configuration parameters
*/
- public PssdConfiguration(final PssdConfigurationParametersGroup configParameters) {
+ public SdcConfiguration(final PssdConfigurationParametersGroup configParameters) {
this.configParameters = configParameters;
-
}
-
@Override
public String getAsdcAddress() {
return configParameters.getAsdcAddress();
@@ -121,6 +116,4 @@ public class PssdConfiguration implements IConfiguration {
public Boolean isUseHttpsWithDmaap() {
return configParameters.isUseHttpsWithDmaap();
}
-
-
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcNotificationCallBack.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcNotificationCallBack.java
new file mode 100644
index 00000000..0ea57799
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcNotificationCallBack.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.handling.sdc;
+
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.sdc.api.consumer.INotificationCallback;
+import org.onap.sdc.api.notification.INotificationData;
+
+/**
+ * Class to provide an implementation of INotificationCallback interface for receiving the incoming distribution
+ * notifications from SDC.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class SdcNotificationCallBack implements INotificationCallback {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(SdcNotificationCallBack.class);
+
+ @Override
+ public void activateCallback(final INotificationData notificationData) {
+
+ LOGGER.debug("Got the message from SDC:" + notificationData.getDistributionID());
+ // Code for handling notification will come here
+ }
+
+}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
index 494f47f6..60c94e2b 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java
@@ -5,40 +5,150 @@
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.distribution.reception.handling.sdc;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.distribution.reception.decoding.PluginInitializationException;
+import org.onap.policy.distribution.reception.decoding.PluginTerminationException;
import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
+import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.impl.DistributionClientFactory;
+import org.onap.sdc.utils.DistributionActionResultEnum;
/**
- * Handles reception of inputs from ONAP Service Design and Creation (SDC) from which policies may
- * be decoded.
+ * Handles reception of inputs from ONAP Service Design and Creation (SDC) from which policies may be decoded.
*/
public class SdcReceptionHandler extends AbstractReceptionHandler {
+ private static final Logger LOGGER = FlexLogger.getLogger(SdcReceptionHandler.class);
+ private SdcReceptionHandlerStatus sdcReceptionHandlerStatus = SdcReceptionHandlerStatus.STOPPED;
+ private PssdConfigurationParametersGroup handlerParameters;
+ private IDistributionClient distributionClient;
+ private volatile int nbOfNotificationsOngoing = 0;
+
@Override
- protected void initializeReception(String parameterGroupName) {
- // Set up subscription to SDC
+ protected void initializeReception(final String parameterGroupName) throws PluginInitializationException {
+ handlerParameters = (PssdConfigurationParametersGroup) ParameterService.get(parameterGroupName);
+ initializeSdcClient();
+ startSdcClient();
}
// Add functionality for receiving SDC distibutions and invoking AbstractReceptionHandler
// inputReceived()
@Override
- public void destroy() {
- // Tear down subscription etc
+ public void destroy() throws PluginTerminationException {
+ LOGGER.debug("Going to stop the SDC Client...");
+ if (distributionClient != null) {
+ final IDistributionClientResult clientResult = distributionClient.stop();
+ if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+ final String message =
+ "SDC client stop failed with reason:" + clientResult.getDistributionMessageResult();
+ LOGGER.error(message);
+ throw new PluginTerminationException(message);
+ }
+ }
+ changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.STOPPED);
+ LOGGER.debug("SDC Client is stopped successfully");
+ }
+
+ /**
+ * Method to change the status of this reception handler instance.
+ *
+ * @param newStatus the new status
+ */
+ protected synchronized final void changeSdcReceptionHandlerStatus(final SdcReceptionHandlerStatus newStatus) {
+ switch (newStatus) {
+ case INIT:
+ case STOPPED:
+ sdcReceptionHandlerStatus = newStatus;
+ break;
+ case IDLE:
+ if (nbOfNotificationsOngoing > 1) {
+ --nbOfNotificationsOngoing;
+ } else {
+ nbOfNotificationsOngoing = 0;
+ sdcReceptionHandlerStatus = newStatus;
+ }
+ break;
+ case BUSY:
+ ++nbOfNotificationsOngoing;
+ sdcReceptionHandlerStatus = newStatus;
+ break;
+ }
+ }
+
+ /**
+ * Creates an instance of {@link IDistributionClient} from {@link DistributionClientFactory}.
+ *
+ * @return the {@link IDistributionClient} instance
+ */
+ protected IDistributionClient createSdcDistributionClient() {
+ return DistributionClientFactory.createDistributionClient();
}
+ /**
+ * Method to initialize the SDC client.
+ *
+ * @throws PluginInitializationException if the initialization of SDC Client fails
+ */
+ private void initializeSdcClient() throws PluginInitializationException {
+
+ LOGGER.debug("Going to initialize the SDC Client...");
+ if (sdcReceptionHandlerStatus != SdcReceptionHandlerStatus.STOPPED) {
+ final String message = "The SDC Client is already initialized";
+ LOGGER.error(message);
+ throw new PluginInitializationException(message);
+ }
+ final SdcConfiguration sdcConfig = new SdcConfiguration(handlerParameters);
+ distributionClient = createSdcDistributionClient();
+ final IDistributionClientResult clientResult =
+ distributionClient.init(sdcConfig, new SdcNotificationCallBack());
+ if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+ changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.STOPPED);
+ final String message =
+ "SDC client initialization failed with reason:" + clientResult.getDistributionMessageResult();
+ LOGGER.error(message);
+ throw new PluginInitializationException(message);
+ }
+ LOGGER.debug("SDC Client is initialized successfully");
+ this.changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.INIT);
+ }
+
+ /**
+ * Method to start the SDC client.
+ *
+ * @param configParameter the configuration parameters
+ * @throws PluginInitializationException if the start of SDC Client fails
+ */
+ private void startSdcClient() throws PluginInitializationException {
+
+ LOGGER.debug("Going to start the SDC Client...");
+ final IDistributionClientResult clientResult = distributionClient.start();
+ if (!clientResult.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+ changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.STOPPED);
+ final String message = "SDC client start failed with reason:" + clientResult.getDistributionMessageResult();
+ LOGGER.error(message);
+ throw new PluginInitializationException(message);
+ }
+ LOGGER.debug("SDC Client is started successfully");
+ this.changeSdcReceptionHandlerStatus(SdcReceptionHandlerStatus.IDLE);
+ }
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java
new file mode 100644
index 00000000..d0e04c78
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerStatus.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.handling.sdc;
+
+/**
+ * Class to hold the possible values for status of {@link SdcReceptionHandler}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public enum SdcReceptionHandlerStatus {
+
+ /**
+ * The SdcReceptionHandler is not alive.
+ */
+ STOPPED,
+
+ /**
+ * The SdcReceptionHandler is initialized but not started yet.
+ */
+ INIT,
+
+ /**
+ * The SdcReceptionHandler is initialized, started & ready to handle incoming notifications.
+ */
+ IDLE,
+
+ /**
+ * The SdcReceptionHandler is currently busy in handling notifications.
+ */
+ BUSY
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/PssdConfigurationTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
index 5c24a792..e1ba00cf 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/PssdConfigurationTest.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
@@ -30,19 +30,20 @@ import com.google.gson.GsonBuilder;
import java.io.FileReader;
import java.io.IOException;
+import java.util.Arrays;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
-/*-
- * Tests for PssdConfiguration class
+/**
+ * Class to perform unit test of {@link SdcConfiguration}.
*
*/
-public class PssdConfigurationTest {
+public class TestSdcConfiguration {
@Test
- public void testPssdConfigurationParametersGroup() throws IOException {
+ public void testSdcConfiguration() throws IOException {
PssdConfigurationParametersGroup configParameters = null;
try {
final Gson gson = new GsonBuilder().create();
@@ -53,13 +54,26 @@ public class PssdConfigurationTest {
}
final GroupValidationResult validationResult = configParameters.validate();
assertTrue(validationResult.isValid());
- final PssdConfiguration config = new PssdConfiguration(configParameters);
+ final SdcConfiguration config = new SdcConfiguration(configParameters);
+ assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress());
+ assertEquals(Arrays.asList("TOSCA_CSAR", "HEAT"), config.getRelevantArtifactTypes());
+ assertEquals("localhost", config.getAsdcAddress());
+ assertEquals("policy", config.getUser());
+ assertEquals("policy", config.getPassword());
assertEquals(20, config.getPollingInterval());
assertEquals(30, config.getPollingTimeout());
+ assertEquals("policy-id", config.getConsumerID());
+ assertEquals("policy-group", config.getConsumerGroup());
+ assertEquals("TEST", config.getEnvironmentName());
+ assertEquals("null", config.getKeyStorePath());
+ assertEquals("null", config.getKeyStorePassword());
+ assertEquals(false, config.activateServerTLSAuth());
+ assertEquals(true, config.isFilterInEmptyResources());
+ assertEquals(false, config.isUseHttpsWithDmaap());
}
@Test
- public void testInvalidPssdConfigurationParametersGroup() throws IOException {
+ public void testInvalidSdcConfiguration() throws IOException {
PssdConfigurationParametersGroup configParameters = null;
try {
final Gson gson = new GsonBuilder().create();
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
new file mode 100644
index 00000000..02b83849
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java
@@ -0,0 +1,180 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Intel. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.handling.sdc;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.distribution.reception.decoding.PluginInitializationException;
+import org.onap.policy.distribution.reception.decoding.PluginTerminationException;
+import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.impl.mock.DistributionClientStubImpl;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+
+/**
+ * Class to perform unit test of {@link SdcReceptionHandler}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TestSdcReceptionHandler {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(TestSdcReceptionHandler.class);
+
+ @Mock
+ private IDistributionClientResult successfulClientInitResult;
+ @Mock
+ private IDistributionClientResult failureClientInitResult;
+ @Mock
+ private DistributionClientStubImpl distributionClient;
+
+ private PssdConfigurationParametersGroup pssdConfigParameters;
+ private SdcReceptionHandler sypHandler;
+
+ /**
+ * Setup for the test cases.
+ *
+ * @throws IOException if it occurs
+ */
+ @Before
+ public final void init() throws IOException {
+ final Gson gson = new GsonBuilder().create();
+ pssdConfigParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
+ PssdConfigurationParametersGroup.class);
+ ParameterService.register(pssdConfigParameters);
+ final SdcReceptionHandler sdcHandler = new SdcReceptionHandler();
+ sypHandler = Mockito.spy(sdcHandler);
+ Mockito.when(sypHandler.createSdcDistributionClient()).thenReturn(distributionClient);
+ Mockito.when(distributionClient.init(any(), any())).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.start()).thenReturn(successfulClientInitResult);
+ Mockito.when(distributionClient.stop()).thenReturn(successfulClientInitResult);
+ Mockito.when(successfulClientInitResult.getDistributionActionResult())
+ .thenReturn(DistributionActionResultEnum.SUCCESS);
+ }
+
+ @After
+ public void teardown() {
+ ParameterService.deregister(pssdConfigParameters);
+ }
+
+ @Test
+ public final void testInitializeSdcClient() {
+ try {
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ } catch (final PluginInitializationException exp) {
+ LOGGER.error(exp);
+ fail("Test should not throw any exception");
+ }
+ }
+
+ @Test
+ public final void testInitializeSdcClient_Again() throws PluginInitializationException {
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ try {
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ fail("Test must throw an exception here");
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("The SDC Client is already initialized"));
+ }
+ }
+
+ @Test
+ public final void testInitializeSdcClient_Failure() throws PluginInitializationException {
+
+ Mockito.when(successfulClientInitResult.getDistributionActionResult())
+ .thenReturn(DistributionActionResultEnum.FAIL);
+ try {
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ fail("Test must throw an exception here");
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("SDC client initialization failed with reason"));
+ }
+ }
+
+ @Test
+ public final void testStartSdcClient_Failure() throws PluginInitializationException {
+ try {
+ Mockito.when(distributionClient.start()).thenReturn(failureClientInitResult);
+ Mockito.when(failureClientInitResult.getDistributionActionResult())
+ .thenReturn(DistributionActionResultEnum.FAIL);
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+
+ fail("Test must throw an exception here");
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("SDC client start failed with reason"));
+ }
+ }
+
+ @Test
+ public final void testStopSdcClient() {
+ try {
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ sypHandler.destroy();
+ } catch (final PluginInitializationException | PluginTerminationException exp) {
+ LOGGER.error(exp);
+ fail("Test should not throw any exception");
+ }
+
+ }
+
+ @Test
+ public final void testStopSdcClientWithoutStart() {
+ try {
+ sypHandler.destroy();
+ } catch (final PluginTerminationException exp) {
+ LOGGER.error(exp);
+ fail("Test should not throw any exception");
+ }
+
+ }
+
+ @Test
+ public final void testStopSdcClient_Failure() throws PluginInitializationException {
+
+ sypHandler.initializeReception(pssdConfigParameters.getName());
+ Mockito.when(successfulClientInitResult.getDistributionActionResult())
+ .thenReturn(DistributionActionResultEnum.FAIL);
+ try {
+ sypHandler.destroy();
+ fail("Test must throw an exception here");
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("SDC client stop failed with reason"));
+ }
+ }
+}
diff --git a/plugins/reception-plugins/src/test/resources/handling-sdc.json b/plugins/reception-plugins/src/test/resources/handling-sdc.json
index c1ca23aa..b9e63fe0 100644
--- a/plugins/reception-plugins/src/test/resources/handling-sdc.json
+++ b/plugins/reception-plugins/src/test/resources/handling-sdc.json
@@ -6,8 +6,8 @@
"b.com",
"c.com"
],
- "user": "tbdsdc-1480",
- "password": "tbdsdc-1480",
+ "user": "policy",
+ "password": "policy",
"pollingInterval":20,
"pollingTimeout":30,
"consumerId": "policy-id",
@@ -16,7 +16,7 @@
"HEAT"
],
"consumerGroup": "policy-group",
- "environmentName": "environmentName",
+ "environmentName": "TEST",
"keystorePath": "null",
"keystorePassword": "null",
"activeserverTlsAuth": false,
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginTerminationException.java b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginTerminationException.java
new file mode 100644
index 00000000..be9f51cb
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginTerminationException.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.decoding;
+
+/**
+ * This exception will be called if an error occurs while terminating distribution plugins.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class PluginTerminationException extends Exception {
+
+ private static final long serialVersionUID = 3809376274411309160L;
+
+ /**
+ * Construct an instance with the given message.
+ *
+ * @param message the error message
+ */
+ public PluginTerminationException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Construct an instance with the given message and cause.
+ *
+ * @param message the error message
+ * @param cause the cause
+ */
+ public PluginTerminationException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
index b189a2ab..a9d76a01 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
@@ -54,7 +54,7 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
final ReceptionHandlerParameters receptionHandlerParameters =
(ReceptionHandlerParameters) ParameterService.get(parameterGroupName);
pluginHandler = new PluginHandler(receptionHandlerParameters.getPluginHandlerParameters().getName());
- initializeReception(parameterGroupName);
+ initializeReception(receptionHandlerParameters.getPssdConfigurationParametersGroup().getName());
}
/**
@@ -62,8 +62,9 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
* example setting up subscriptions.
*
* @param parameterGroupName the parameter group name
+ * @throws PluginInitializationException if initialization of reception handler fails
*/
- protected abstract void initializeReception(String parameterGroupName);
+ protected abstract void initializeReception(String parameterGroupName) throws PluginInitializationException;
/**
* Handle input that has been received. The given input shall be decoded using the {@link PolicyDecoder}s configured
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
index 5fcfb9c0..3678c69c 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
@@ -21,6 +21,7 @@
package org.onap.policy.distribution.reception.handling;
import org.onap.policy.distribution.reception.decoding.PluginInitializationException;
+import org.onap.policy.distribution.reception.decoding.PluginTerminationException;
/**
* Handles input into Policy Distribution which may be decoded into a Policy.
@@ -37,7 +38,9 @@ public interface ReceptionHandler {
/**
* Destroy the reception handler, removing any subscriptions and releasing all resources.
+ *
+ * @throws PluginTerminationException if it occurs
*/
- void destroy();
+ void destroy() throws PluginTerminationException;
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginInitializationExceptionTest.java
index bf327554..b63e6677 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginInitializationExceptionTest.java
@@ -25,26 +25,26 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
- * Class to perform unit test of PluginInitializationException.
+ * Class to perform unit test of {@link PluginInitializationException}.
*
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
-public class PolicyInitializationExceptionTest {
+public class PluginInitializationExceptionTest {
@Test
- public void testPolicyInitializationExceptionString() {
- final PluginInitializationException policyInitializationException =
+ public void testPluginInitializationExceptionString() {
+ final PluginInitializationException pluginInitializationException =
new PluginInitializationException("error message");
- assertEquals("error message", policyInitializationException.getMessage());
+ assertEquals("error message", pluginInitializationException.getMessage());
}
@Test
- public void testPolicyInitializationExceptionStringThrowable() {
+ public void testPluginInitializationExceptionStringThrowable() {
final Exception cause = new IllegalArgumentException();
- final PluginInitializationException policyInitializationException =
+ final PluginInitializationException pluginInitializationException =
new PluginInitializationException("error message", cause);
- assertEquals("error message", policyInitializationException.getMessage());
- assertEquals(cause, policyInitializationException.getCause());
+ assertEquals("error message", pluginInitializationException.getMessage());
+ assertEquals(cause, pluginInitializationException.getCause());
}
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginTerminationExceptionTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginTerminationExceptionTest.java
new file mode 100644
index 00000000..b450e32b
--- /dev/null
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PluginTerminationExceptionTest.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.reception.decoding;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test of {@link PluginTerminationException}
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class PluginTerminationExceptionTest {
+
+ @Test
+ public void testPluginTerminationExceptionString() {
+ final PluginTerminationException pluginTerminationException = new PluginTerminationException("error message");
+ assertEquals("error message", pluginTerminationException.getMessage());
+ }
+
+ @Test
+ public void testPluginTerminationExceptionStringThrowable() {
+ final Exception cause = new IllegalArgumentException();
+ final PluginTerminationException pluginTerminationException =
+ new PluginTerminationException("error message", cause);
+ assertEquals("error message", pluginTerminationException.getMessage());
+ assertEquals(cause, pluginTerminationException.getCause());
+ }
+
+}