summaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src
diff options
context:
space:
mode:
authormmis <michael.morris@ericsson.com>2018-09-05 17:12:03 +0100
committermmis <michael.morris@ericsson.com>2018-09-05 17:34:25 +0100
commit0089e8bc429001eca2997b44168b05889cb75d38 (patch)
tree943152987d7aa192fa35bdd76db713bec2463d55 /plugins/reception-plugins/src
parent461cafda67a99f4cc27ea41539d1748b6c87a79c (diff)
Refactored reception handler parameter handling
Refactored parameter handling for configuration of reception handlers as the previous implementation does not align with the plugin architecture (.e. plugin specific parameters being handled in core code) Issue-ID: POLICY-1094 Change-Id: I31a9fc7f712ca43f0f69c42a6d99fa481b02cd4b Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'plugins/reception-plugins/src')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java6
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java5
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java333
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java9
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java5
5 files changed, 343 insertions, 15 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java
index 945670b9..99529759 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcConfiguration.java
@@ -21,8 +21,6 @@
package org.onap.policy.distribution.reception.handling.sdc;
import java.util.List;
-
-import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
import org.onap.sdc.api.consumer.IConfiguration;
/**
@@ -31,14 +29,14 @@ import org.onap.sdc.api.consumer.IConfiguration;
*/
public class SdcConfiguration implements IConfiguration {
- private PssdConfigurationParametersGroup configParameters = null;
+ private SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
/**
* Constructor for instantiating {@link SdcConfiguration}.
*
* @param configParameters the SDC Client configuration parameters
*/
- public SdcConfiguration(final PssdConfigurationParametersGroup configParameters) {
+ public SdcConfiguration(final SdcReceptionHandlerConfigurationParameterGroup configParameters) {
this.configParameters = configParameters;
}
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 60c94e2b..f0f9e20d 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
@@ -26,7 +26,6 @@ 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;
@@ -39,13 +38,13 @@ public class SdcReceptionHandler extends AbstractReceptionHandler {
private static final Logger LOGGER = FlexLogger.getLogger(SdcReceptionHandler.class);
private SdcReceptionHandlerStatus sdcReceptionHandlerStatus = SdcReceptionHandlerStatus.STOPPED;
- private PssdConfigurationParametersGroup handlerParameters;
+ private SdcReceptionHandlerConfigurationParameterGroup handlerParameters;
private IDistributionClient distributionClient;
private volatile int nbOfNotificationsOngoing = 0;
@Override
protected void initializeReception(final String parameterGroupName) throws PluginInitializationException {
- handlerParameters = (PssdConfigurationParametersGroup) ParameterService.get(parameterGroupName);
+ handlerParameters = (SdcReceptionHandlerConfigurationParameterGroup) ParameterService.get(parameterGroupName);
initializeSdcClient();
startSdcClient();
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java
new file mode 100644
index 00000000..5c46049f
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java
@@ -0,0 +1,333 @@
+/*-
+ * ============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 java.util.List;
+import java.util.UUID;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
+
+/**
+ * This class handles reading, parsing and validating of the Policy SDC Service Distribution
+ * parameters from Json format, which strictly adheres to the interface:IConfiguration, defined by
+ * SDC SDK.
+ */
+public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
+
+ // Interface of IConfiguration item
+ private String asdcAddress;
+ private List<String> messageBusAddress;
+ private String user;
+ private String password;
+ private int pollingInterval;
+ private int pollingTimeout;
+ private String consumerId;
+ private List<String> artifactTypes;
+ private String consumerGroup;
+ private String environmentName;
+ private String keystorePath;
+ private String keystorePassword;
+ private boolean activeserverTlsAuth;
+ private boolean isFilterinEmptyResources;
+ private Boolean isUseHttpsWithDmaap;
+
+ /**
+ * Inner static class is to used as a Builder.
+ *
+ */
+ public static class PssdConfigurationBuilder {
+ private String asdcAddress;
+ private List<String> messageBusAddress;
+ private String user;
+ private String password;
+ private int pollingInterval;
+ private int pollingTimeout;
+ private String consumerId;
+ private List<String> artifactTypes;
+ private String consumerGroup;
+ private String environmentName;
+ private String keystorePath;
+ private String keystorePassword;
+ private boolean activeserverTlsAuth;
+ private boolean isFilterinEmptyResources;
+ private Boolean isUseHttpsWithDmaap;
+
+ public PssdConfigurationBuilder setAsdcAddress(final String val) {
+ asdcAddress = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setMessageBusAddress(final List<String> val) {
+ messageBusAddress = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setUser(final String val) {
+ user = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setPassword(final String val) {
+ password = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setPollingInterval(final int val) {
+ pollingInterval = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setPollingTimeout(final int val) {
+ pollingTimeout = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setConsumerId(final String val) {
+ consumerId = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setArtifactTypes(final List<String> val) {
+ artifactTypes = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setConsumerGroup(final String val) {
+ consumerGroup = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setEnvironmentName(final String val) {
+ environmentName = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setKeystorePath(final String val) {
+ keystorePath = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setKeystorePassword(final String val) {
+ keystorePassword = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setActiveserverTlsAuth(final boolean val) {
+ activeserverTlsAuth = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setIsFilterinEmptyResources(final boolean val) {
+ isFilterinEmptyResources = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setIsUseHttpsWithDmaap(final Boolean val) {
+ isUseHttpsWithDmaap = val;
+ return this;
+ }
+
+ /**
+ * Creates a new PssdConfigurationParametersGroup instance.
+ */
+ public SdcReceptionHandlerConfigurationParameterGroup build() {
+ return new SdcReceptionHandlerConfigurationParameterGroup(this);
+ }
+ }
+
+ /**
+ * The constructor for instantiating PssdConfigurationParametersGroup. It is kept private so
+ * that it could only be called by PssdConfigurationBuilder.
+ *
+ * @param builder stores all the values used by PssdConfigurationParametersGroup
+ */
+ private SdcReceptionHandlerConfigurationParameterGroup(final PssdConfigurationBuilder builder) {
+ asdcAddress = builder.asdcAddress;
+ messageBusAddress = builder.messageBusAddress;
+ user = builder.user;
+ password = builder.password;
+ pollingInterval = builder.pollingInterval;
+ pollingTimeout = builder.pollingTimeout;
+ consumerId = builder.consumerId;
+ artifactTypes = builder.artifactTypes;
+ consumerGroup = builder.consumerGroup;
+ environmentName = builder.environmentName;
+ keystorePath = builder.keystorePath;
+ keystorePassword = builder.keystorePassword;
+ activeserverTlsAuth = builder.activeserverTlsAuth;
+ isFilterinEmptyResources = builder.isFilterinEmptyResources;
+ isUseHttpsWithDmaap = builder.isUseHttpsWithDmaap;
+
+ }
+
+ public String getAsdcAddress() {
+ return asdcAddress;
+ }
+
+ public List<String> getMsgBusAddress() {
+ return messageBusAddress;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public int getPollingInterval() {
+ return pollingInterval;
+ }
+
+ public int getPollingTimeout() {
+ return pollingTimeout;
+ }
+
+ public String getConsumerID() {
+ return consumerId;
+ }
+
+ public List<String> getArtifactTypes() {
+ return artifactTypes;
+ }
+
+ public String getConsumerGroup() {
+ return consumerGroup;
+ }
+
+ public String getEnvironmentName() {
+ return environmentName;
+ }
+
+ public String getKeyStorePassword() {
+ return keystorePassword;
+ }
+
+ public String getKeyStorePath() {
+ return keystorePath;
+ }
+
+ public boolean activateServerTLSAuth() {
+ return activeserverTlsAuth;
+ }
+
+ public boolean isFilterInEmptyResources() {
+ return isFilterinEmptyResources;
+ }
+
+ public Boolean isUseHttpsWithDmaap() {
+ return isUseHttpsWithDmaap;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "name =" + getName() + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
+ + messageBusAddress + ", user = " + user + "]";
+ }
+
+ /**
+ * Set the name of this group.
+ *
+ * @param name the name to set.
+ */
+ @Override
+ public void setName(final String name) {
+ super.setName(name + "_" + UUID.randomUUID().toString());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult validationResult = new GroupValidationResult(this);
+ validateStringElement(validationResult, asdcAddress, "asdcAddress");
+ validateStringElement(validationResult, user, "user");
+ validateStringElement(validationResult, consumerId, "consumerId");
+ validateStringElement(validationResult, consumerGroup, "consumerGroup");
+ validateStringElement(validationResult, keystorePath, "keystorePath");
+ validateStringElement(validationResult, keystorePassword, "keystorePassword");
+ validateIntElement(validationResult, pollingInterval, "pollingInterval");
+ validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
+ validateStringListElement(validationResult, messageBusAddress, "messageBusAddress");
+ validateStringListElement(validationResult, artifactTypes, "artifactTypes");
+ return validationResult;
+ }
+
+ /**
+ * Validate the integer Element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateIntElement(final GroupValidationResult validationResult, final int element,
+ final String elementName) {
+ if (!ParameterValidationUtils.validateIntParameter(element)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a positive integer");
+ }
+ }
+
+ /**
+ * Validate the String List Element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
+ final String elementName) {
+ if (element == null) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a list of non-blank string");
+ } else {
+ for (final String temp : element) {
+ if (!ParameterValidationUtils.validateStringParameter(temp)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ "the string of " + elementName + "must be a non-blank string");
+ }
+ }
+ }
+ }
+
+ /**
+ * Validate the string element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateStringElement(final GroupValidationResult validationResult, final String element,
+ final String elementName) {
+ if (!ParameterValidationUtils.validateStringParameter(asdcAddress)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a non-blank string");
+ }
+ }
+}
+
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
index e1ba00cf..65d7ca10 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcConfiguration.java
@@ -34,7 +34,6 @@ import java.util.Arrays;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
/**
* Class to perform unit test of {@link SdcConfiguration}.
@@ -44,11 +43,11 @@ public class TestSdcConfiguration {
@Test
public void testSdcConfiguration() throws IOException {
- PssdConfigurationParametersGroup configParameters = null;
+ SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
try {
final Gson gson = new GsonBuilder().create();
configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"),
- PssdConfigurationParametersGroup.class);
+ SdcReceptionHandlerConfigurationParameterGroup.class);
} catch (final Exception e) {
fail("test should not thrown an exception here: " + e.getMessage());
}
@@ -74,11 +73,11 @@ public class TestSdcConfiguration {
@Test
public void testInvalidSdcConfiguration() throws IOException {
- PssdConfigurationParametersGroup configParameters = null;
+ SdcReceptionHandlerConfigurationParameterGroup configParameters = null;
try {
final Gson gson = new GsonBuilder().create();
configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"),
- PssdConfigurationParametersGroup.class);
+ SdcReceptionHandlerConfigurationParameterGroup.class);
} catch (final Exception e) {
fail("test should not thrown an exception here: " + e.getMessage());
}
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
index 02b83849..c876f99c 100644
--- 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
@@ -42,7 +42,6 @@ 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;
@@ -64,7 +63,7 @@ public class TestSdcReceptionHandler {
@Mock
private DistributionClientStubImpl distributionClient;
- private PssdConfigurationParametersGroup pssdConfigParameters;
+ private SdcReceptionHandlerConfigurationParameterGroup pssdConfigParameters;
private SdcReceptionHandler sypHandler;
/**
@@ -76,7 +75,7 @@ public class TestSdcReceptionHandler {
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);
+ SdcReceptionHandlerConfigurationParameterGroup.class);
ParameterService.register(pssdConfigParameters);
final SdcReceptionHandler sdcHandler = new SdcReceptionHandler();
sypHandler = Mockito.spy(sdcHandler);