Search in sources :

Example 66 with PluginPropertyField

use of io.cdap.cdap.api.plugin.PluginPropertyField in project cdap by caskdata.

the class DefaultArtifactInspector method createPluginProperties.

/**
 * Creates a collection of {@link PluginPropertyField} based on the given field.
 */
private Collection<PluginPropertyField> createPluginProperties(Field field, TypeToken<?> resolvingType, boolean inspectNested) throws UnsupportedTypeException {
    TypeToken<?> fieldType = resolvingType.resolveType(field.getGenericType());
    Class<?> rawType = fieldType.getRawType();
    Name nameAnnotation = field.getAnnotation(Name.class);
    Description descAnnotation = field.getAnnotation(Description.class);
    String name = nameAnnotation == null ? field.getName() : nameAnnotation.value();
    String description = descAnnotation == null ? "" : descAnnotation.value();
    Macro macroAnnotation = field.getAnnotation(Macro.class);
    boolean macroSupported = macroAnnotation != null;
    if (rawType.isPrimitive()) {
        return Collections.singleton(new PluginPropertyField(name, description, rawType.getName(), true, macroSupported));
    }
    rawType = Primitives.unwrap(rawType);
    boolean required = true;
    for (Annotation annotation : field.getAnnotations()) {
        if (annotation.annotationType().getName().endsWith(".Nullable")) {
            required = false;
            break;
        }
    }
    Map<String, PluginPropertyField> properties = new HashMap<>();
    if (PluginConfig.class.isAssignableFrom(rawType)) {
        if (!inspectNested) {
            throw new IllegalArgumentException("Plugin config with name " + name + " is a subclass of PluginGroupConfig and can " + "only be defined within PluginConfig.");
        }
        // don't inspect if the field is already nested
        inspectConfigField(fieldType, properties, false);
    }
    PluginPropertyField curField = new PluginPropertyField(name, description, rawType.getSimpleName().toLowerCase(), required, macroSupported, false, new HashSet<>(properties.keySet()));
    properties.put(name, curField);
    return properties.values();
}
Also used : Description(io.cdap.cdap.api.annotation.Description) HashMap(java.util.HashMap) Macro(io.cdap.cdap.api.annotation.Macro) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField) Annotation(java.lang.annotation.Annotation) Name(io.cdap.cdap.api.annotation.Name)

Example 67 with PluginPropertyField

use of io.cdap.cdap.api.plugin.PluginPropertyField in project cdap by caskdata.

the class MockSQLEngineWithCapabilities method getPluginClass.

private static PluginClass getPluginClass() {
    Map<String, PluginPropertyField> properties = new HashMap<>();
    properties.put("name", new PluginPropertyField("name", "", "string", true, false));
    properties.put("outputDirName", new PluginPropertyField("outputDirName", "", "string", true, false));
    properties.put("outputSchema", new PluginPropertyField("outputSchema", "", "string", true, false));
    properties.put("expected", new PluginPropertyField("expected", "", "string", true, false));
    return new PluginClass(BatchSQLEngine.PLUGIN_TYPE, NAME, "", MockSQLEngineWithCapabilities.class.getName(), "config", properties);
}
Also used : HashMap(java.util.HashMap) PluginClass(io.cdap.cdap.api.plugin.PluginClass) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField)

Example 68 with PluginPropertyField

use of io.cdap.cdap.api.plugin.PluginPropertyField in project cdap by caskdata.

the class FieldLineageAction method getPluginClass.

private static PluginClass getPluginClass() {
    Map<String, PluginPropertyField> properties = new HashMap<>();
    properties.put("readDataset", new PluginPropertyField("readDataset", "", "string", true, false));
    properties.put("writeDataset", new PluginPropertyField("writeDataset", "", "string", true, false));
    properties.put("fieldOperations", new PluginPropertyField("fieldOperations", "", "string", true, false));
    return PluginClass.builder().setName("FieldLineageAction").setType(Action.PLUGIN_TYPE).setDescription("").setClassName(FieldLineageAction.class.getName()).setProperties(properties).setConfigFieldName("config").build();
}
Also used : HashMap(java.util.HashMap) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField)

Example 69 with PluginPropertyField

use of io.cdap.cdap.api.plugin.PluginPropertyField in project cdap by caskdata.

the class FileMoveAction method getPluginClass.

private static PluginClass getPluginClass() {
    Map<String, PluginPropertyField> properties = new HashMap<>();
    properties.put("sourceFileset", new PluginPropertyField("sourceFileset", "", "string", true, false));
    properties.put("destinationFileset", new PluginPropertyField("destinationFileset", "", "string", true, false));
    properties.put("filterRegex", new PluginPropertyField("filterRegex", "", "string", false, false));
    return PluginClass.builder().setName(NAME).setType(Action.PLUGIN_TYPE).setDescription("").setClassName(FileMoveAction.class.getName()).setProperties(properties).setConfigFieldName("conf").build();
}
Also used : HashMap(java.util.HashMap) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField)

Example 70 with PluginPropertyField

use of io.cdap.cdap.api.plugin.PluginPropertyField in project cdap by caskdata.

the class TMSAlertPublisher method getPluginClass.

private static PluginClass getPluginClass() {
    Map<String, PluginPropertyField> properties = new HashMap<>();
    properties.put("topic", new PluginPropertyField("topic", "", "string", true, false));
    properties.put("topicNamespace", new PluginPropertyField("topicNamespace", "", "string", true, false));
    return PluginClass.builder().setName(NAME).setType(AlertPublisher.PLUGIN_TYPE).setDescription("").setClassName(TMSAlertPublisher.class.getName()).setProperties(properties).setConfigFieldName("conf").build();
}
Also used : HashMap(java.util.HashMap) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField)

Aggregations

PluginPropertyField (io.cdap.cdap.api.plugin.PluginPropertyField)115 HashMap (java.util.HashMap)93 PluginClass (io.cdap.cdap.api.plugin.PluginClass)29 Test (org.junit.Test)16 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)12 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)12 Id (io.cdap.cdap.common.id.Id)12 File (java.io.File)10 ArtifactClasses (io.cdap.cdap.api.artifact.ArtifactClasses)8 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 Location (org.apache.twill.filesystem.Location)8 ImmutableMap (com.google.common.collect.ImmutableMap)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)6 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)6 Requirements (io.cdap.cdap.api.plugin.Requirements)6 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6