[ 
https://issues.apache.org/jira/browse/STORM-1084?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14957455#comment-14957455
 ] 

ASF GitHub Bot commented on STORM-1084:
---------------------------------------

Github user revans2 commented on a diff in the pull request:

    https://github.com/apache/storm/pull/785#discussion_r42032063
  
    --- Diff: 
storm-core/src/jvm/backtype/storm/validation/ConfigValidationAnnotations.java 
---
    @@ -0,0 +1,216 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.
    + */
    +
    +package backtype.storm.validation;
    +
    +import java.lang.annotation.Retention;
    +import java.lang.annotation.Target;
    +
    +import java.lang.annotation.ElementType;
    +import java.lang.annotation.RetentionPolicy;
    +
    +/**
    + * Note: every annotation interface must have method validatorClass()
    + * For every annotation there must validator class to do the validation
    + * To add another annotation for config validation, add another annotation 
@interface class.  Implement the corresponding
    + * validator logic in a class in ConfigValidation.  Make sure 
validateField method in ConfigValidation knows how to use the validator
    + * and which method definition/parameters to pass in based on what fields 
are in the annotation.
    + */
    +public class ConfigValidationAnnotations {
    +    /**
    +     * Field names for annotations
    +     */
    +
    +    static final String VALIDATOR_CLASS = "validatorClass";
    +    static final String TYPE = "type";
    +    static final String ENTRY_VALIDATOR_CLASSES = "entryValidatorClasses";
    +    static final String KEY_VALIDATOR_CLASSES = "keyValidatorClasses";
    +    static final String VALUE_VALIDATOR_CLASSES = "valueValidatorClasses";
    +    static final String KEY_TYPE = "keyType";
    +    static final String VALUE_TYPE = "valueType";
    +    static final String INCLUDE_ZERO = "includeZero";
    +
    +    /**
    +     * Validators with fields: validatorClass and type
    +     */
    +
    +    @Retention(RetentionPolicy.RUNTIME)
    +    @Target(ElementType.FIELD)
    +    public @interface isType {
    +        Class validatorClass() default 
ConfigValidation.SimpleTypeValidator.class;
    +
    +        Class type();
    +    }
    +
    +    @Retention(RetentionPolicy.RUNTIME)
    +    @Target(ElementType.FIELD)
    +    public @interface isStrings {
    --- End diff --
    
    Can we make this areStrings or isListOfStrings.  isStrings is too close to 
isString for me, and it feels a bit grammatically suspect.


> Improve Storm config validation process to use java annotations instead of 
> *_SCHEMA format
> ------------------------------------------------------------------------------------------
>
>                 Key: STORM-1084
>                 URL: https://issues.apache.org/jira/browse/STORM-1084
>             Project: Apache Storm
>          Issue Type: Improvement
>          Components: storm-core
>            Reporter: Boyang Jerry Peng
>            Assignee: Boyang Jerry Peng
>
> So currently we specify validators:
>  public static final String STORM_MESSAGING_NETTY_MIN_SLEEP_MS = 
> "storm.messaging.netty.min_wait_ms";
>  public static final Object STORM_MESSAGING_NETTY_MIN_SLEEP_MS_SCHEMA = 
> ConfigValidation.IntegerValidator;
> A better way to do this is using annotations.  Something like:
> @IntegerValidator
>  public static final String STORM_MESSAGING_NETTY_MIN_SLEEP_MS = 
> "storm.messaging.netty.min_wait_ms";
> Do this has many advantages. For one you can stack multiple annotations:
> @IntegerValidator
> @NotNull
>  public static final String STORM_MESSAGING_NETTY_MIN_SLEEP_MS = 
> "storm.messaging.netty.min_wait_ms";
> And we don't have to write another validator for strings that cannot be null
> And we can pass parameters into the annotations: 
> @PositiveIntegerValidator(notNull=true)
>   public static final String DRPC_REQUEST_TIMEOUT_SECS  = 
> "drpc.request.timeout.secs";
> instead of having to write another validator: 
> ConfigValidation.NotNullPosIntegerValidator for checking for not null



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to