summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-07-30 11:17:55 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-07-30 11:17:55 +0000
commitef0641c47e0ffe212f2b850c90069ede7c16e1d7 (patch)
tree1ffdb6c3753e287c89beb9ec00bc81815d25ec71 /policy-endpoints/src/main
parent4513f428543dbd09f855fdd392d90d628f5d403e (diff)
Passing the updated topic parameters to policy-endpoints
Changes to pass the updated parameters from BusTopicParams to PolicyEndpoints. Change-Id: I49d3b9d30a2a4c6b2337d0ab76a61583eb9ef04a Issue-ID: POLICY-1744 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'policy-endpoints/src/main')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java36
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java58
2 files changed, 73 insertions, 21 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java
index 70a06036..b89f47dc 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java
@@ -54,22 +54,38 @@ public class TopicParameterGroup extends ParameterGroupImpl {
@Override
public GroupValidationResult validate() {
GroupValidationResult result = super.validate();
- if (result.isValid() && (checkMissingMandatoryParams(topicSources)
- || checkMissingMandatoryParams(topicSinks))) {
- result.setResult(ValidationStatus.INVALID, "Mandatory parameters are missing. topic, servers "
- + "and topicCommInfrastructure must be specified.");
+ if (result.isValid()) {
+ StringBuilder errorMsg = new StringBuilder();
+ StringBuilder missingSourceParams = checkMissingMandatoryParams(topicSources);
+ if (missingSourceParams.length() > 0) {
+ errorMsg.append(missingSourceParams.append("missing in topicSources. "));
+ }
+ StringBuilder missingSinkParams = checkMissingMandatoryParams(topicSinks);
+ if (missingSinkParams.length() > 0) {
+ errorMsg.append(missingSinkParams.append("missing in topicSinks."));
+ }
+
+ if (errorMsg.length() > 0) {
+ errorMsg.insert(0, "Mandatory parameters are missing. ");
+ result.setResult(ValidationStatus.INVALID, errorMsg.toString());
+ }
}
return result;
}
- private boolean checkMissingMandatoryParams(List<TopicParameters> topicParametersList) {
+ private StringBuilder checkMissingMandatoryParams(List<TopicParameters> topicParametersList) {
+ StringBuilder missingParams = new StringBuilder();
for (TopicParameters topicParameters : topicParametersList) {
- if (StringUtils.isBlank(topicParameters.getTopic())
- || StringUtils.isBlank(topicParameters.getTopicCommInfrastructure())
- || topicParameters.getServers().isEmpty()) {
- return true;
+ if (StringUtils.isBlank(topicParameters.getTopic())) {
+ missingParams.append("topic, ");
+ }
+ if (StringUtils.isBlank(topicParameters.getTopicCommInfrastructure())) {
+ missingParams.append("topicCommInfrastructure, ");
+ }
+ if (null == topicParameters.getServers() || topicParameters.getServers().isEmpty()) {
+ missingParams.append("servers, ");
}
}
- return false;
+ return missingParams;
}
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java
index cabfe58f..5e93cfa4 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java
@@ -21,12 +21,19 @@
package org.onap.policy.common.endpoints.utils;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Properties;
-
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This is common utility class with utility methods for parameters.
@@ -36,6 +43,11 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
public class ParameterUtils {
/**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(ParameterUtils.class);
+
+ /**
* Private constructor used to prevent sub class instantiation.
*/
private ParameterUtils() {
@@ -56,12 +68,10 @@ public class ParameterUtils {
// for each topicCommInfrastructure, there could be multiple topics (specified as comma separated string)
// for each such topics, there could be multiple servers (specified as comma separated string)
for (TopicParameters source : topicSources) {
- updateTopicProperties(topicProperties, "source", source.getTopicCommInfrastructure(), source.getTopic(),
- source.getServers());
+ updateTopicProperties(topicProperties, "source", source);
}
for (TopicParameters sink : topicSinks) {
- updateTopicProperties(topicProperties, "sink", sink.getTopicCommInfrastructure(), sink.getTopic(),
- sink.getServers());
+ updateTopicProperties(topicProperties, "sink", sink);
}
return topicProperties;
@@ -72,19 +82,45 @@ public class ParameterUtils {
*
* @param topicProperties the topic properties object which is to be updated
* @param keyName either it is source or sink
- * @param topicCommInfra the infra such as dmaap, ueb or noop
- * @param topicName the topic
- * @param servers the list of server names for the topic
+ * @param topicParameters the topic parameters object
*/
- public static void updateTopicProperties(Properties topicProperties, String keyName, String topicCommInfra,
- String topicName, List<String> servers) {
+ public static void updateTopicProperties(Properties topicProperties, String keyName,
+ TopicParameters topicParameters) {
+ String topicCommInfra = topicParameters.getTopicCommInfrastructure();
+ String topicName = topicParameters.getTopic();
+ List<String> servers = topicParameters.getServers();
+
String propKey = topicCommInfra + "." + keyName + PolicyEndPointProperties.PROPERTY_TOPIC_TOPICS_SUFFIX;
if (topicProperties.containsKey(propKey)) {
topicProperties.setProperty(propKey, topicProperties.getProperty(propKey) + "," + topicName);
} else {
topicProperties.setProperty(propKey, topicName);
}
- topicProperties.setProperty(propKey + "." + topicName + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX,
+ String propWithTopicKey = propKey + "." + topicName;
+ topicProperties.setProperty(propWithTopicKey + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX,
String.join(",", servers));
+
+ Field[] fields = BusTopicParams.class.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.isSynthetic()) {
+ continue;
+ }
+ try {
+ Object parameter = new PropertyDescriptor(field.getName(), TopicParameters.class)
+ .getReadMethod().invoke(topicParameters);
+ if ((parameter instanceof String && StringUtils.isNotBlank(parameter.toString()))
+ || (parameter instanceof Number && ((Number) parameter).longValue() > 0)) {
+ topicProperties.setProperty(propWithTopicKey + "." + field.getName(), parameter.toString());
+ }
+ if (parameter instanceof Boolean && (Boolean) parameter) {
+ topicProperties.setProperty(propWithTopicKey + "." + field.getName(),
+ Boolean.toString((Boolean) parameter));
+ }
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | IntrospectionException e) {
+ logger.error("Error while creating Properties object from TopicParameters for {}", field.getName(), e);
+ }
+ }
+
}
}