-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix: Enforce wrangler directive config in wrangler service and pipeline transform #1039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ | |
| import io.cdap.cdap.spi.data.table.field.Field; | ||
| import io.cdap.cdap.spi.data.table.field.FieldType; | ||
| import io.cdap.cdap.spi.data.table.field.Fields; | ||
| import io.cdap.cdap.spi.data.transaction.TransactionRunner; | ||
| import io.cdap.cdap.spi.data.transaction.TransactionRunners; | ||
| import io.cdap.wrangler.api.DirectiveConfig; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -55,9 +57,16 @@ public class ConfigStore { | |
| .withPrimaryKeys(KEY_COL) | ||
| .build(); | ||
| private final StructuredTable table; | ||
| private final TransactionRunner transactionRunner; | ||
|
|
||
| public ConfigStore(StructuredTable table) { | ||
| this.table = table; | ||
| this.transactionRunner = null; | ||
| } | ||
|
|
||
| public ConfigStore(TransactionRunner transactionRunner) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a need for separate constructor?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just to make sure adding But rethinking this, maybe we can make this change and go forward with updating the current methods because ConfigStore is in |
||
| this.table = null; | ||
| this.transactionRunner = transactionRunner; | ||
| } | ||
|
|
||
| public static ConfigStore get(StructuredTableContext context) { | ||
|
|
@@ -70,14 +79,29 @@ public static ConfigStore get(StructuredTableContext context) { | |
| } | ||
| } | ||
|
|
||
| public static ConfigStore get(TransactionRunner transactionRunner) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a need for a separate overload?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as mentioned in #1039 (comment) |
||
| return new ConfigStore(transactionRunner); | ||
| } | ||
|
|
||
| public void updateConfig(DirectiveConfig config) throws IOException { | ||
| if (transactionRunner != null) { | ||
| TransactionRunners.run(transactionRunner, context -> { | ||
| get(context).updateConfig(config); | ||
| }); | ||
| return; | ||
| } | ||
| List<Field<?>> fields = new ArrayList<>(2); | ||
| fields.add(keyField); | ||
| fields.add(Fields.stringField(VAL_COL, GSON.toJson(config))); | ||
| table.upsert(fields); | ||
| } | ||
|
|
||
| public DirectiveConfig getConfig() throws IOException { | ||
| if (transactionRunner != null) { | ||
| return TransactionRunners.run(transactionRunner, context -> { | ||
| return get(context).getConfig(); | ||
| }); | ||
| } | ||
| Optional<StructuredRow> row = table.read(Collections.singletonList(keyField)); | ||
| String configStr = row.map(r -> r.getString(VAL_COL)).orElse("{}"); | ||
| return GSON.fromJson(configStr, DirectiveConfig.class); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there was a failure reading from Database, IOException would be thrown. You are ignoring the exception and returning default configuration, which is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, my bad, changed - throwing IOException for this method in case of error rather than handling locally.