/** * No-op plugin, for CLI testing */ @Plugin(type = "runnable") @Name("FakePlugin") public class FakePlugin implements Runnable { public static final String NAME = "FakePlugin"; @Override public void run() { // do nothing } }
public static final class Config extends PluginConfig { @Name("x") private Long x; } }
/** * Config class for LogParserTransform */ public static class LogParserConfig extends PluginConfig { @Name("logFormat") @Description(LOG_FORMAT_DESCRIPTION) private String logFormat; @Name("inputName") @Description(INPUT_NAME_DESCRIPTION) private String inputName; public LogParserConfig(String logFormat, String inputName) { this.logFormat = logFormat; this.inputName = inputName; } } }
/** * Adds a class that extends from <code>AbstractDirective</code> to usage registry. * * @param classz representing an AbstractDirective</code> implementation. */ public void addUsage(Class<? extends Executor> classz) { Name name = classz.getAnnotation(Name.class); Description description = classz.getAnnotation(Description.class); Usage usage = classz.getAnnotation(Usage.class); if (usage == null || name == null || description == null) { return; } usages.put(name.value(), new UsageEntry(name.value(), usage.value(), description.value())); usageList.add(new UsageEntry(name.value(), usage.value(), description.value())); }
/** * Config class for KVTableSink */ public static class KVTableConfig extends BatchReadableWritableConfig { @Name(Properties.KeyValueTable.KEY_FIELD) @Description(KEY_FIELD_DESC) @Nullable private String keyField; @Name(Properties.KeyValueTable.VALUE_FIELD) @Description(VALUE_FIELD_DESC) @Nullable private String valueField; public KVTableConfig() { this(null, Properties.KeyValueTable.DEFAULT_KEY_FIELD, Properties.KeyValueTable.DEFAULT_VALUE_FIELD); } public KVTableConfig(String name, String keyField, String valueField) { super(name); this.keyField = keyField; this.valueField = valueField; } }
@Override public void visit(Object instance, Type inspectType, Type declareType, Field field) throws Exception { int modifiers = field.getModifiers(); if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers) || field.isSynthetic()) { return; } TypeToken<?> declareTypeToken = TypeToken.of(declareType); if (PluginConfig.class.equals(declareTypeToken.getRawType())) { if (field.getName().equals("properties")) { field.set(instance, properties); } else if (field.getName().equals("macroFields")) { field.set(instance, macroFields); } return; } Name nameAnnotation = field.getAnnotation(Name.class); String name = nameAnnotation == null ? field.getName() : nameAnnotation.value(); PluginPropertyField pluginPropertyField = pluginClass.getProperties().get(name); if (pluginPropertyField.isRequired() && !properties.getProperties().containsKey(name)) { throw new IllegalArgumentException("Missing required plugin property " + name + " for " + pluginClass.getName() + " in artifact " + artifactId); } String value = properties.getProperties().get(name); if (pluginPropertyField.isRequired() || value != null) { field.set(instance, convertValue(declareTypeToken.resolveType(field.getGenericType()), value)); } }
/** * Creates a {@link PluginPropertyField} based on the given field. */ private PluginPropertyField createPluginProperty(Field field, TypeToken<?> resolvingType) 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 new PluginPropertyField(name, description, rawType.getName(), true, macroSupported); } rawType = Primitives.unwrap(rawType); if (!rawType.isPrimitive() && !String.class.equals(rawType)) { throw new UnsupportedTypeException("Only primitive and String types are supported"); } boolean required = true; for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType().getName().endsWith(".Nullable")) { required = false; break; } } return new PluginPropertyField(name, description, rawType.getSimpleName().toLowerCase(), required, macroSupported); }
/** * Transform used to test error emission. Writes all its input as errors. */ @Plugin(type = Transform.PLUGIN_TYPE) @Name("AllError") public class AllErrorTransform extends Transform<StructuredRecord, StructuredRecord> { public static final PluginClass PLUGIN_CLASS = getPluginClass(); @Override public void configurePipeline(PipelineConfigurer pipelineConfigurer) throws IllegalArgumentException { StageConfigurer stageConfigurer = pipelineConfigurer.getStageConfigurer(); stageConfigurer.setOutputSchema(stageConfigurer.getInputSchema()); } @Override public void transform(StructuredRecord input, Emitter<StructuredRecord> emitter) throws Exception { emitter.emitError(new InvalidEntry<>(500, "msg", input)); } public static ETLPlugin getPlugin() { return new ETLPlugin("AllError", Transform.PLUGIN_TYPE, new HashMap<String, String>(), null); } private static PluginClass getPluginClass() { Map<String, PluginPropertyField> properties = new HashMap<>(); return new PluginClass(Transform.PLUGIN_TYPE, "AllError", "", AllErrorTransform.class.getName(), null, properties); } }
/** * Creates a {@link PluginPropertyField} based on the given field. */ private PluginPropertyField createPluginProperty(Field field, TypeToken<?> resolvingType) 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 new PluginPropertyField(name, description, rawType.getName(), true, macroSupported); } rawType = Primitives.unwrap(rawType); if (!rawType.isPrimitive() && !String.class.equals(rawType)) { throw new UnsupportedTypeException("Only primitive and String types are supported"); } boolean required = true; for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType().getName().endsWith(".Nullable")) { required = false; break; } } return new PluginPropertyField(name, description, rawType.getSimpleName().toLowerCase(), required, macroSupported); }
/** * Transform that doubles every record it receives. */ @Plugin(type = Transform.PLUGIN_TYPE) @Name("Double") public class DoubleTransform extends Transform<StructuredRecord, StructuredRecord> { public static final PluginClass PLUGIN_CLASS = getPluginClass(); @Override public void configurePipeline(PipelineConfigurer pipelineConfigurer) throws IllegalArgumentException { StageConfigurer stageConfigurer = pipelineConfigurer.getStageConfigurer(); stageConfigurer.setOutputSchema(stageConfigurer.getInputSchema()); } @Override public void transform(StructuredRecord input, Emitter<StructuredRecord> emitter) throws Exception { emitter.emit(input); emitter.emit(input); } public static ETLPlugin getPlugin() { return new ETLPlugin("Double", Transform.PLUGIN_TYPE, new HashMap<String, String>(), null); } private static PluginClass getPluginClass() { Map<String, PluginPropertyField> properties = new HashMap<>(); return new PluginClass(Transform.PLUGIN_TYPE, "Double", "", DoubleTransform.class.getName(), null, properties); } }
@Override public void visit(Object instance, Type inspectType, Type declareType, Field field) throws Exception { int modifiers = field.getModifiers(); if (Modifier.isTransient(modifiers) || Modifier.isStatic(modifiers) || field.isSynthetic()) { return; } TypeToken<?> declareTypeToken = TypeToken.of(declareType); if (PluginConfig.class.equals(declareTypeToken.getRawType())) { if (field.getName().equals("properties")) { field.set(instance, properties); } else if (field.getName().equals("macroFields")) { field.set(instance, macroFields); } return; } Name nameAnnotation = field.getAnnotation(Name.class); String name = nameAnnotation == null ? field.getName() : nameAnnotation.value(); PluginPropertyField pluginPropertyField = pluginClass.getProperties().get(name); if (pluginPropertyField.isRequired() && !properties.getProperties().containsKey(name)) { throw new IllegalArgumentException("Missing required plugin property " + name + " for " + pluginClass.getName() + " in artifact " + artifactId); } String value = properties.getProperties().get(name); if (pluginPropertyField.isRequired() || value != null) { field.set(instance, convertValue(declareTypeToken.resolveType(field.getGenericType()), value)); } }
public DirectiveInfo(Scope scope, Class<?> directive) throws IllegalAccessException, InstantiationException { this.scope = scope; this.directive = directive; Object object = directive.newInstance(); this.definition = ((Directive) object).define(); if (definition != null) { this.usage = definition.toString(); } else { this.usage = "No definition available for directive '" + directive + "'"; } this.name = directive.getAnnotation(Name.class).value(); Description desc = directive.getAnnotation(Description.class); if (desc == null) { this.description = "No description specified for directive class '" + directive.getSimpleName() + "'"; } else { this.description = desc.value(); } Deprecated annotation = directive.getAnnotation(Deprecated.class); if (annotation == null) { deprecated = false; } else { deprecated = true; } Categories category = directive.getAnnotation(Categories.class); if (category == null) { categories = new String[] { "default" }; } else { categories = category.categories(); } }
@Name("Identity") public class IdentityAggregator extends BatchAggregator<StructuredRecord, StructuredRecord, StructuredRecord> { public static final PluginClass PLUGIN_CLASS = getPluginClass();