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/decoding/PolicyDecoder.java8
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java1
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParameterGroup.java45
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java84
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java15
5 files changed, 152 insertions, 1 deletions
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java
index 2a07ec72..9cd660a9 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java
@@ -34,6 +34,14 @@ import org.onap.policy.distribution.model.PolicyInput;
public interface PolicyDecoder<S extends PolicyInput, T extends Policy> {
/**
+ * Configure the policy decoder. This method will be invoked immediately after instantiation in order for the policy
+ * decoder to configure itself.
+ *
+ * @param parameterGroupName the name of the parameter group which contains the configuration for the policy decoder
+ */
+ void configure(String parameterGroupName);
+
+ /**
* Can the decoder handle input of the specified type.
*
* @param policyInput the type
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
index e6bfefea..74b8eb16 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
@@ -92,6 +92,7 @@ public class PluginHandler {
(Class<PolicyDecoder<PolicyInput, Policy>>) Class
.forName(decoderParameters.getDecoderClassName());
final PolicyDecoder<PolicyInput, Policy> decoder = policyDecoderClass.newInstance();
+ decoder.configure(decoderParameters.getDecoderConfigurationName());
policyDecoders.add(decoder);
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) {
LOGGER.error("exception occured while initializing decoders", exp);
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParameterGroup.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParameterGroup.java
new file mode 100644
index 00000000..00ae0a3a
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParameterGroup.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.parameters;
+
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
+
+/**
+ * Base class of all {@link ParameterGroup} classes for configuration parameters for {@link PolicyDecoder} classes.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public abstract class PolicyDecoderConfigurationParameterGroup 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/PolicyDecoderConfigurationParametersJsonAdapter.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java
new file mode 100644
index 00000000..64eb4ed7
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java
@@ -0,0 +1,84 @@
+/*-
+ * ============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 policy decoder parameters from JSON.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class PolicyDecoderConfigurationParametersJsonAdapter
+ implements JsonDeserializer<PolicyDecoderConfigurationParameterGroup> {
+ private static final XLogger LOGGER =
+ XLoggerFactory.getXLogger(PolicyDecoderConfigurationParametersJsonAdapter.class);
+
+ private static final String PARAMETER_CLASS_NAME = "parameterClassName";
+ private static final String POLICY_DECODER_PARAMETERS = "parameters";
+
+ @Override
+ public PolicyDecoderConfigurationParameterGroup deserialize(final JsonElement json, final Type typeOfT,
+ final JsonDeserializationContext context) {
+ final JsonObject jsonObject = json.getAsJsonObject();
+
+ final String policyDecoderParameterClassName = getParameterGroupClassName(jsonObject);
+ final Class<?> policyDecoderParameterClass = getParameterGroupClass(policyDecoderParameterClassName);
+
+ return context.deserialize(jsonObject.get(POLICY_DECODER_PARAMETERS), policyDecoderParameterClass);
+ }
+
+ 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 policyDecoderParameterClassName) {
+ Class<?> policyDecoderParameterClass = null;
+ try {
+ policyDecoderParameterClass = Class.forName(policyDecoderParameterClassName);
+ } catch (final ClassNotFoundException exp) {
+ final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \""
+ + policyDecoderParameterClassName + "\", could not find class";
+ LOGGER.warn(errorMessage, exp);
+ throw new IllegalArgumentException(errorMessage, exp);
+ }
+ return policyDecoderParameterClass;
+ }
+
+}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
index 0b7ae0b7..91ada5ff 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
@@ -37,16 +37,20 @@ public class PolicyDecoderParameters implements ParameterGroup {
private String decoderType;
private String decoderClassName;
+ private String decoderConfigurationName;
/**
* Constructor for instantiating PolicyDecoderParameters.
*
* @param decoderType the policy decoder type
* @param decoderClassName the policy decoder class name
+ * @param decoderConfigurationName the policy decoder configuration name
*/
- public PolicyDecoderParameters(final String decoderType, final String decoderClassName) {
+ public PolicyDecoderParameters(final String decoderType, final String decoderClassName,
+ final String decoderConfigurationName) {
this.decoderType = decoderType;
this.decoderClassName = decoderClassName;
+ this.decoderConfigurationName = decoderConfigurationName;
}
/**
@@ -68,6 +72,15 @@ public class PolicyDecoderParameters implements ParameterGroup {
}
/**
+ * Return the name of the decoder configuration of this {@link PolicyDecoderParameters} instance.
+ *
+ * @return the the name of the decoder configuration
+ */
+ public String getDecoderConfigurationName() {
+ return decoderConfigurationName;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override