Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public final class PluginConstants {
public static final String PROPERTY_CONFIG_KEY_FREQUENCY = "cdap.hello.world.config.frequency";
public static final int PROPERTY_DEFAULT_FREQUENCY = 1;

// Output

public static final String PROPERTY_NAME_USER_MESSAGE="User Message";
public static final String PROPERTY_CONFIG_KEY_USER_MESSAGE = "cdap.hello.world.config.message";
public static final String PROPERTY_CONFIG_DEFAULT_MESSAGE = "Hello world, this is a custom message";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the default message same as before for backwards compatibility!



public static final String PLUGIN_OUT_VALUE = "Hello World!";
public static final Schema PLUGIN_OUT_SCHEMA = Schema.recordOf("data", Schema.Field.of("message", Schema.of(Schema.Type.STRING)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
import io.cdap.cdap.api.plugin.PluginConfig;
import io.cdap.cdap.etl.api.FailureCollector;

import javax.annotation.Nullable;

public class HelloWorldBatchSourceConfig extends PluginConfig {

@Name(PluginConstants.PROPERTY_NAME_FREQUENCY)
@Description("Number of times the plugin says hello world.")
public Integer frequency;


@Name(PluginConstants.PROPERTY_NAME_USER_MESSAGE)
@Description("Custom message")
@Nullable
public String message;
Comment on lines +18 to +21
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep these consistent, userMessage is more appropriate.



public void validate(FailureCollector failureCollector) {
if (frequency != null && frequency < 1) {
failureCollector.addFailure("Property cannot be lower than 1.", "Use a frequency value of equal to or more than 1.").withConfigProperty(PluginConstants.PROPERTY_NAME_FREQUENCY);
Expand All @@ -21,5 +30,6 @@ public void validate(FailureCollector failureCollector) {
public int getFrequency() {
return frequency == null ? PluginConstants.PROPERTY_DEFAULT_FREQUENCY : frequency;
}
public String getMessage(){ return (message == null || message.isEmpty()) ? PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE: message; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix formatting !


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public class HelloWorldInputFormatProvider implements InputFormatProvider {

public HelloWorldInputFormatProvider(HelloWorldBatchSourceConfig config) {
configMap = new HashMap<>();

configMap.put(PluginConstants.PROPERTY_CONFIG_KEY_FREQUENCY, Integer.toString(config.getFrequency()));
configMap.put(PluginConstants.PROPERTY_CONFIG_KEY_MESSAGE, config.getMessage());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROPERTY_CONFIG_KEY_USER_MESSAGE

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done sir


}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ public class HelloWorldRecordReader extends RecordReader<NullWritable, String> {

private int frequency;
private int countProcessed = 0;
private String message;

@Override
public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
Configuration conf = taskAttemptContext.getConfiguration();
// Plugin configuration

frequency = conf.getInt(PluginConstants.PROPERTY_CONFIG_KEY_FREQUENCY, 1);

message = conf.get(PluginConstants.PROPERTY_CONFIG_KEY_MESSAGE,PluginConstants.PROPERTY_CONFIG_DEFAULT_MESSAGE);


}

@Override
Expand Down