You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/04/22 18:07:08 UTC

[GitHub] [nifi] SandishKumarHN commented on a change in pull request #3450: NIFI-1642 : Kafka Processors Topic Name Validations

SandishKumarHN commented on a change in pull request #3450: NIFI-1642 : Kafka Processors Topic Name Validations
URL: https://github.com/apache/nifi/pull/3450#discussion_r277377573
 
 

 ##########
 File path: nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-0-10-processors/src/main/java/org/apache/nifi/processors/kafka/pubsub/KafkaProcessorUtils.java
 ##########
 @@ -257,6 +288,54 @@
         return results;
     }
 
+
+    static final class KafkaConsumerTopicNameValidator implements Validator {
+
+        final Class<?> classType;
+
+        public KafkaConsumerTopicNameValidator(final Class<?> classType) {
+            this.classType = classType;
+        }
+
+        @Override
+        public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
+            final String topicType = context.getProperty(CONSUMER_TOPIC_TYPE).evaluateAttributeExpressions().getValue();
+            final String topicListing = context.getProperty(CONSUMER_TOPICS).evaluateAttributeExpressions().getValue();
+            boolean isValidTopicName = true;
+            String topicName = "";
+            if (topicListing != null && topicType.equals(TOPIC_NAME.getValue())) {
+                for (final String topic : topicListing.split(",", 100)) {
+                    if(topic.isEmpty() || TOPIC_NAME_PATTERN.matcher(topic).replaceAll("").length() != 0 ) {
+                        isValidTopicName = false;
+                        topicName = topic;
+                    }
+                }
+            }
+            return new ValidationResult.Builder().subject(subject).explanation(topicName + " is not a valid topic name.").valid(isValidTopicName).build();
+        }
+    };
+
+    static final class KafkaProducerTopicNameValidator implements Validator {
+
+        final Class<?> classType;
+
+        public KafkaProducerTopicNameValidator(final Class<?> classType) {
+            this.classType = classType;
+        }
+
+        @Override
+        public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
+            final String topicName = context.getProperty(PRODUCER_TOPIC).evaluateAttributeExpressions().getValue();
 
 Review comment:
   Does it make sense to change to VARIABLE_REGISTRY instead of a flowfile attribute or write a custom validator like here  https://github.com/apache/nifi/blob/4515b2afe9cef93f823678b4a7ca02a07461dbef/nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-0-10-processors/src/main/java/org/apache/nifi/processors/kafka/pubsub/PublishKafka_0_10.java#L251 ?
   
   or validate in the onTrigger method?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services