Search in sources :

Example 1 with Description

use of org.apache.flink.configuration.description.Description in project plugins by qlangtech.

the class FlinkDescriptor method addFieldDescriptor.

protected void addFieldDescriptor(String fieldName, ConfigOption<?> configOption) {
    Description desc = configOption.description();
    HtmlFormatter htmlFormatter = new HtmlFormatter();
    Object d = configOption.defaultValue();
    StringBuffer helperContent = new StringBuffer(htmlFormatter.format(desc));
    Class<?> targetClazz = configOption.getClazz();
    List<Option> opts = null;
    if (targetClazz == Duration.class) {
        if (d != null) {
            d = ((Duration) d).getSeconds();
        }
        helperContent.append("\n\n 单位:`秒`");
    } else if (targetClazz.isEnum()) {
        List<Enum> enums = EnumUtils.getEnumList((Class<Enum>) targetClazz);
        opts = enums.stream().map((e) -> new Option(e.name())).collect(Collectors.toList());
    } else if (targetClazz == Boolean.class) {
        opts = Lists.newArrayList(new Option("是", true), new Option("否", false));
    }
    this.addFieldDescriptor(fieldName, d, helperContent.toString(), Optional.ofNullable(opts));
}
Also used : List(java.util.List) Lists(com.google.common.collect.Lists) EnumUtils(org.apache.commons.lang3.EnumUtils) Duration(java.time.Duration) Descriptor(com.qlangtech.tis.extension.Descriptor) Description(org.apache.flink.configuration.description.Description) Optional(java.util.Optional) Option(com.qlangtech.tis.manage.common.Option) ConfigOption(org.apache.flink.configuration.ConfigOption) Collectors(java.util.stream.Collectors) Describable(com.qlangtech.tis.extension.Describable) HtmlFormatter(org.apache.flink.configuration.description.HtmlFormatter) Description(org.apache.flink.configuration.description.Description) Option(com.qlangtech.tis.manage.common.Option) ConfigOption(org.apache.flink.configuration.ConfigOption) List(java.util.List) HtmlFormatter(org.apache.flink.configuration.description.HtmlFormatter)

Aggregations

Lists (com.google.common.collect.Lists)1 Describable (com.qlangtech.tis.extension.Describable)1 Descriptor (com.qlangtech.tis.extension.Descriptor)1 Option (com.qlangtech.tis.manage.common.Option)1 Duration (java.time.Duration)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 EnumUtils (org.apache.commons.lang3.EnumUtils)1 ConfigOption (org.apache.flink.configuration.ConfigOption)1 Description (org.apache.flink.configuration.description.Description)1 HtmlFormatter (org.apache.flink.configuration.description.HtmlFormatter)1