summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-08-30 09:37:29 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-08-31 19:23:41 +0100
commitf32508381ce0b555fc14978cbaa458aa4e2d91c5 (patch)
tree1cab66e5372b6467f288ae1351ce836e4eba2d03 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src
parent052038c7a7e0b385462b3b653b7d06094d472df3 (diff)
Use parameter service in apex
Switch parameter handling in apex to use the ONAP PF common parameter service Change-Id: Id318d19c726b18b1a69c630fa81ca7d695355e9c Issue-ID: POLICY-954 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java109
1 files changed, 66 insertions, 43 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java
index 2357b1807..5ce96662e 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java
@@ -25,6 +25,8 @@ import java.util.Collection;
import java.util.Properties;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
/**
* Apex parameters for Kafka as an event carrier technology.
@@ -42,6 +44,9 @@ public class KAFKACarrierTechnologyParameters extends CarrierTechnologyParameter
/** The consumer plugin class for the Kafka carrier technology. */
public static final String KAFKA_EVENT_CONSUMER_PLUGIN_CLASS = ApexKafkaConsumer.class.getCanonicalName();
+ // Repeated strings in messages
+ private static final String SPECIFY_AS_STRING_MESSAGE = "not specified, must be specified as a string";
+
// Default parameter values
private static final String DEFAULT_ACKS = "all";
private static final String DEFAULT_BOOTSTRAP_SERVERS = "localhost:9092";
@@ -102,7 +107,7 @@ public class KAFKACarrierTechnologyParameters extends CarrierTechnologyParameter
* service.
*/
public KAFKACarrierTechnologyParameters() {
- super(KAFKACarrierTechnologyParameters.class.getCanonicalName());
+ super();
// Set the carrier technology properties for the kafka carrier technology
this.setLabel(KAFKA_CARRIER_TECHNOLOGY_LABEL);
@@ -308,89 +313,107 @@ public class KAFKACarrierTechnologyParameters extends CarrierTechnologyParameter
* @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
*/
@Override
- public String validate() {
- final StringBuilder errorMessageBuilder = new StringBuilder();
-
- errorMessageBuilder.append(super.validate());
+ public GroupValidationResult validate() {
+ final GroupValidationResult result = super.validate();
- if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
- errorMessageBuilder
- .append(" bootstrapServers not specified, must be specified as a string of form host:port\n");
+ if (isNullOrBlank(bootstrapServers)) {
+ result.setResult("bootstrapServers", ValidationStatus.INVALID,
+ "not specified, must be specified as a string of form host:port");
}
- if (acks == null || acks.trim().length() == 0) {
- errorMessageBuilder.append(" acks not specified, must be specified as a string with values [0|1|all]\n");
+ if (isNullOrBlank(acks)) {
+ result.setResult("acks", ValidationStatus.INVALID,
+ "not specified, must be specified as a string with values [0|1|all]");
}
if (retries < 0) {
- errorMessageBuilder.append(" retries [" + retries + "] invalid, must be specified as retries >= 0\n");
+ result.setResult(PROPERTY_RETRIES, ValidationStatus.INVALID,
+ "[" + retries + "] invalid, must be specified as retries >= 0");
}
if (batchSize < 0) {
- errorMessageBuilder
- .append(" batchSize [" + batchSize + "] invalid, must be specified as batchSize >= 0\n");
+ result.setResult("batchSize", ValidationStatus.INVALID,
+ "[" + batchSize + "] invalid, must be specified as batchSize >= 0");
}
if (lingerTime < 0) {
- errorMessageBuilder
- .append(" lingerTime [" + lingerTime + "] invalid, must be specified as lingerTime >= 0\n");
+ result.setResult("lingerTime", ValidationStatus.INVALID,
+ "[" + lingerTime + "] invalid, must be specified as lingerTime >= 0");
}
if (bufferMemory < 0) {
- errorMessageBuilder
- .append(" bufferMemory [" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0\n");
+ result.setResult("bufferMemory", ValidationStatus.INVALID,
+ "[" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0");
}
- if (groupId == null || groupId.trim().length() == 0) {
- errorMessageBuilder.append(" groupId not specified, must be specified as a string\n");
+ if (isNullOrBlank(groupId)) {
+ result.setResult("groupId", ValidationStatus.INVALID, SPECIFY_AS_STRING_MESSAGE);
}
if (autoCommitTime < 0) {
- errorMessageBuilder.append(
- " autoCommitTime [" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0\n");
+ result.setResult("autoCommitTime", ValidationStatus.INVALID,
+ "[" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0");
}
if (sessionTimeout < 0) {
- errorMessageBuilder.append(
- " sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0\n");
+ result.setResult("sessionTimeout", ValidationStatus.INVALID,
+ "[" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0");
}
- if (producerTopic == null || producerTopic.trim().length() == 0) {
- errorMessageBuilder.append(" producerTopic not specified, must be specified as a string\n");
+ if (isNullOrBlank(producerTopic)) {
+ result.setResult("producerTopic", ValidationStatus.INVALID,
+ SPECIFY_AS_STRING_MESSAGE);
}
if (consumerPollTime < 0) {
- errorMessageBuilder.append(" consumerPollTime [" + consumerPollTime
- + "] invalid, must be specified as consumerPollTime >= 0\n");
+ result.setResult("consumerPollTime", ValidationStatus.INVALID,
+ "[" + consumerPollTime + "] invalid, must be specified as consumerPollTime >= 0");
}
- if (consumerTopicList == null || consumerTopicList.length == 0) {
- errorMessageBuilder.append(" consumerTopicList not specified, must be specified as a list of strings\n");
+ validateConsumerTopicList(result);
+
+ if (isNullOrBlank(keySerializer)) {
+ result.setResult("keySerializer", ValidationStatus.INVALID,
+ SPECIFY_AS_STRING_MESSAGE);
}
- for (final String consumerTopic : consumerTopicList) {
- if (consumerTopic == null || consumerTopic.trim().length() == 0) {
- errorMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
- + "\" specified on consumerTopicList, consumer topics must be specified as strings\n");
- }
+ if (isNullOrBlank(valueSerializer)) {
+ result.setResult("valueSerializer", ValidationStatus.INVALID,
+ SPECIFY_AS_STRING_MESSAGE);
}
- if (keySerializer == null || keySerializer.trim().length() == 0) {
- errorMessageBuilder.append(" keySerializer not specified, must be specified as a string\n");
+ if (isNullOrBlank(keyDeserializer)) {
+ result.setResult("keyDeserializer", ValidationStatus.INVALID,
+ SPECIFY_AS_STRING_MESSAGE);
}
- if (valueSerializer == null || valueSerializer.trim().length() == 0) {
- errorMessageBuilder.append(" valueSerializer not specified, must be specified as a string\n");
+ if (isNullOrBlank(valueDeserializer)) {
+ result.setResult("valueDeserializer", ValidationStatus.INVALID,
+ SPECIFY_AS_STRING_MESSAGE);
}
- if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
- errorMessageBuilder.append(" keyDeserializer not specified, must be specified as a string\n");
+ return result;
+ }
+
+ private void validateConsumerTopicList(final GroupValidationResult result) {
+ if (consumerTopicList == null || consumerTopicList.length == 0) {
+ result.setResult("consumerTopicList", ValidationStatus.INVALID,
+ "not specified, must be specified as a list of strings");
}
- if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
- errorMessageBuilder.append(" valueDeserializer not specified, must be specified as a string\n");
+ StringBuilder consumerTopicStringBuilder = new StringBuilder();
+ for (final String consumerTopic : consumerTopicList) {
+ if (consumerTopic == null || consumerTopic.trim().length() == 0) {
+ consumerTopicStringBuilder.append(consumerTopic + "/");
+ }
+ }
+ if (consumerTopicStringBuilder.length() > 0) {
+ result.setResult("consumerTopicList", ValidationStatus.INVALID,
+ "invalid consumer topic list entries found: /" + consumerTopicStringBuilder.toString());
}
+ }
- return errorMessageBuilder.toString();
+ private boolean isNullOrBlank(final String stringValue) {
+ return stringValue == null || stringValue.trim().length() == 0;
}
}