summaryrefslogtreecommitdiffstats
path: root/reception/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'reception/src/main')
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java23
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java343
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParameterGroup.java44
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java80
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java19
5 files changed, 147 insertions, 362 deletions
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 a9d76a01..300dae8f 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
@@ -22,7 +22,6 @@ package org.onap.policy.distribution.reception.handling;
import java.util.ArrayList;
import java.util.Collection;
-
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.common.parameters.ParameterService;
@@ -36,9 +35,10 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
/**
- * Base implementation of {@link ReceptionHandler}. All reception handlers should extend this base class by implementing
- * the {@link #initializeReception(String)} method to perform the specific initialization required to receive inputs and
- * by invoking {@link #inputReceived(PolicyInput)} when the reception handler receives input.
+ * Base implementation of {@link ReceptionHandler}. All reception handlers should extend this base
+ * class by implementing the {@link #initializeReception(String)} method to perform the specific
+ * initialization required to receive inputs and by invoking {@link #inputReceived(PolicyInput)}
+ * when the reception handler receives input.
*/
public abstract class AbstractReceptionHandler implements ReceptionHandler {
@@ -54,12 +54,12 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
final ReceptionHandlerParameters receptionHandlerParameters =
(ReceptionHandlerParameters) ParameterService.get(parameterGroupName);
pluginHandler = new PluginHandler(receptionHandlerParameters.getPluginHandlerParameters().getName());
- initializeReception(receptionHandlerParameters.getPssdConfigurationParametersGroup().getName());
+ initializeReception(receptionHandlerParameters.getReceptionHandlerConfigurationName());
}
/**
- * Sub classes must implement this method to perform the specific initialization required to receive inputs, for
- * example setting up subscriptions.
+ * Sub classes must implement this method to perform the specific initialization required to
+ * receive inputs, for example setting up subscriptions.
*
* @param parameterGroupName the parameter group name
* @throws PluginInitializationException if initialization of reception handler fails
@@ -67,12 +67,13 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
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
- * for this reception handler and forwarded using the {@link PolicyForwarder}s configured for this reception
- * handler.
+ * Handle input that has been received. The given input shall be decoded using the
+ * {@link PolicyDecoder}s configured for this reception handler and forwarded using the
+ * {@link PolicyForwarder}s configured for this reception handler.
*
* @param policyInput the input that has been received
- * @throws PolicyDecodingException if an error occurs in decoding a policy from the received input
+ * @throws PolicyDecodingException if an error occurs in decoding a policy from the received
+ * input
*/
protected void inputReceived(final PolicyInput policyInput) throws PolicyDecodingException {
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java
deleted file mode 100644
index 93e3f628..00000000
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*-
- * ============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.parameters;
-
-import java.util.List;
-import java.util.UUID;
-
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
-
-/**
- * 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 PssdConfigurationParametersGroup implements ParameterGroup {
-
- // Policy SDC Service Distribution specified field.
- private String name;
-
- // 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 PssdConfigurationParametersGroup build() {
- return new PssdConfigurationParametersGroup(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 PssdConfigurationParametersGroup(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 =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
- + messageBusAddress + ", user = " + user + "]";
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Set the name of this group.
- *
- * @param name the name to set.
- */
- public void setName(final String name) {
- this.name = 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/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParameterGroup.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParameterGroup.java
new file mode 100644
index 00000000..c3163665
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParameterGroup.java
@@ -0,0 +1,44 @@
+/*-
+ * ============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.parameters;
+
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.distribution.reception.handling.ReceptionHandler;
+
+/**
+ * Base class of all {@link ParameterGroup} classes for configuration parameters for
+ * {@link ReceptionHandler} classes
+ */
+public abstract class ReceptionHandlerConfigurationParameterGroup implements ParameterGroup {
+
+ private String name;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java
new file mode 100644
index 00000000..0890a2ab
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java
@@ -0,0 +1,80 @@
+/*-
+ * ============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.parameters;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import java.lang.reflect.Type;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class deserialises reception handler parameters from JSON.
+ */
+public class ReceptionHandlerConfigurationParametersJsonAdapter
+ implements JsonDeserializer<ReceptionHandlerConfigurationParameterGroup> {
+ private static final XLogger LOGGER =
+ XLoggerFactory.getXLogger(ReceptionHandlerConfigurationParametersJsonAdapter.class);
+
+ private static final String PARAMETER_CLASS_NAME = "parameterClassName";
+ private static final String RECEPTION_HANDLER_PARAMETERS = "parameters";
+
+ @Override
+ public ReceptionHandlerConfigurationParameterGroup deserialize(final JsonElement json, final Type typeOfT,
+ final JsonDeserializationContext context) {
+ final JsonObject jsonObject = json.getAsJsonObject();
+
+ final String receptionHandlerParameterClassName = getParameterGroupClassName(jsonObject);
+ Class<?> receptionHandlerParameterClass = getParameterGroupClass(receptionHandlerParameterClassName);
+
+ return context.deserialize(jsonObject.get(RECEPTION_HANDLER_PARAMETERS), receptionHandlerParameterClass);
+ }
+
+ private String getParameterGroupClassName(final JsonObject jsonObject) {
+ final JsonPrimitive classNameJsonPrimitive = ((JsonPrimitive) jsonObject.get(PARAMETER_CLASS_NAME));
+
+ if (classNameJsonPrimitive == null || classNameJsonPrimitive.getAsString().length() == 0) {
+ final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \""
+ + (classNameJsonPrimitive != null ? classNameJsonPrimitive.getAsString() : "null")
+ + "\" invalid in JSON file";
+ LOGGER.warn(errorMessage);
+ throw new IllegalArgumentException(errorMessage);
+ }
+ return classNameJsonPrimitive.getAsString().replaceAll("\\s+", "");
+ }
+
+ private Class<?> getParameterGroupClass(final String receptionHAndlerParameterClassName) {
+ Class<?> receptionHandlerParameterClass = null;
+ try {
+ receptionHandlerParameterClass = Class.forName(receptionHAndlerParameterClassName);
+ } catch (final ClassNotFoundException e) {
+ final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \""
+ + receptionHAndlerParameterClassName + "\", could not find class";
+ LOGGER.warn(errorMessage, e);
+ throw new IllegalArgumentException(errorMessage, e);
+ }
+ return receptionHandlerParameterClass;
+ }
+
+}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
index 6464eeb6..3839c449 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
@@ -38,7 +38,7 @@ public class ReceptionHandlerParameters implements ParameterGroup {
private String name;
private String receptionHandlerType;
private String receptionHandlerClassName;
- private PssdConfigurationParametersGroup pssdConfiguration;
+ private String receptionHandlerConfigurationName;
private PluginHandlerParameters pluginHandlerParameters;
/**
@@ -46,14 +46,15 @@ public class ReceptionHandlerParameters implements ParameterGroup {
*
* @param receptionHandlerType the reception handler type
* @param receptionHandlerClassName the reception handler class name
+ * @param receptionHandlerConfigurationName the name of the configuration for the reception
+ * handler
* @param pluginHandlerParameters the plugin handler parameters
*/
- public ReceptionHandlerParameters(final String receptionHandlerType, final String receptionHandlerClassName,
- final PssdConfigurationParametersGroup pssdConfiguration,
- final PluginHandlerParameters pluginHandlerParameters) {
+ public ReceptionHandlerParameters(final String receptionHandlerType, final String receptionHandlerClassName,
+ final String receptionHandlerConfigurationName, final PluginHandlerParameters pluginHandlerParameters) {
this.receptionHandlerType = receptionHandlerType;
this.receptionHandlerClassName = receptionHandlerClassName;
- this.pssdConfiguration = pssdConfiguration;
+ this.receptionHandlerConfigurationName = receptionHandlerConfigurationName;
this.pluginHandlerParameters = pluginHandlerParameters;
}
@@ -76,12 +77,13 @@ public class ReceptionHandlerParameters implements ParameterGroup {
}
/**
- * Return the PssdConfigurationParametersGroup of this ReceptionHandlerParameters instance.
+ * Return the name of the reception handler configuration for this ReceptionHandlerParameters
+ * instance.
*
* @return the PssdConfigurationParametersGroup
*/
- public PssdConfigurationParametersGroup getPssdConfigurationParametersGroup() {
- return pssdConfiguration;
+ public String getReceptionHandlerConfigurationName() {
+ return receptionHandlerConfigurationName;
}
/**
@@ -138,6 +140,7 @@ public class ReceptionHandlerParameters implements ParameterGroup {
*
* @param name the name to set
*/
+ @Override
public void setName(final String name) {
this.name = name;
}