Search in sources :

Example 1 with Description

use of org.apache.beam.sdk.options.Description in project beam by apache.

the class PipelineOptionsTableGenerator method extractOptions.

/**
 * Returns the extracted list of options via reflections on FlinkPipelineOptions. Options are
 * returned sorted in alphabetical order since Java does not guarantee any consistent order on the
 * class methods.
 */
private static List<Option> extractOptions(boolean isPython) {
    List<Option> options = new ArrayList<>();
    for (Method method : FlinkPipelineOptions.class.getDeclaredMethods()) {
        String name;
        String description;
        String defaultValue = null;
        name = method.getName();
        if (name.matches("^(get|is).*")) {
            name = name.replaceFirst("^(get|is)", "");
            if (isPython) {
                name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
            } else {
                name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
            }
            Description descriptionAnnotation = method.getAnnotation(Description.class);
            if (descriptionAnnotation == null) {
                throw new RuntimeException("All pipeline options should have a description. Please add one for " + name);
            }
            description = descriptionAnnotation.value();
            Optional<String> defaultValueFromAnnotation = getDefaultValueFromAnnotation(method);
            if (defaultValueFromAnnotation.isPresent()) {
                defaultValue = defaultValueFromAnnotation.get();
            }
            options.add(new Option(name, description, defaultValue));
        }
    }
    options.sort(Comparator.comparing(option -> option.name));
    return options;
}
Also used : List(java.util.List) FlinkPipelineOptions(org.apache.beam.runners.flink.FlinkPipelineOptions) Default(org.apache.beam.sdk.options.Default) Annotation(java.lang.annotation.Annotation) CaseFormat(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.CaseFormat) Optional(java.util.Optional) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Comparator(java.util.Comparator) Method(java.lang.reflect.Method) Nullable(org.checkerframework.checker.nullness.qual.Nullable) ArrayList(java.util.ArrayList) Description(org.apache.beam.sdk.options.Description) Description(org.apache.beam.sdk.options.Description) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 FlinkPipelineOptions (org.apache.beam.runners.flink.FlinkPipelineOptions)1 Default (org.apache.beam.sdk.options.Default)1 Description (org.apache.beam.sdk.options.Description)1 CaseFormat (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.CaseFormat)1 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1