[GOBBLIN-401] Provide a constructor for CombineSelectionPolicy with only the selection config as argument[]
Closes #2275 from sv2000/gobblin-401 Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/8879cdec Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/8879cdec Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/8879cdec Branch: refs/heads/0.12.0 Commit: 8879cdec2680e9e748d7e89f5cef5d72110c1c07 Parents: fd3a547 Author: suvasude <[email protected]> Authored: Fri Feb 2 07:54:44 2018 -0800 Committer: Hung Tran <[email protected]> Committed: Fri Feb 2 07:54:44 2018 -0800 ---------------------------------------------------------------------- .../policy/CombineSelectionPolicy.java | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/8879cdec/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/policy/CombineSelectionPolicy.java ---------------------------------------------------------------------- diff --git a/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/policy/CombineSelectionPolicy.java b/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/policy/CombineSelectionPolicy.java index b6377a0..c3c70f8 100644 --- a/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/policy/CombineSelectionPolicy.java +++ b/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/policy/CombineSelectionPolicy.java @@ -71,13 +71,17 @@ public class CombineSelectionPolicy implements VersionSelectionPolicy<DatasetVer public static final String VERSION_SELECTION_COMBINE_OPERATION = "selection.combine.operation"; public enum CombineOperation { - INTERSECT, - UNION + INTERSECT, UNION } private final List<VersionSelectionPolicy<DatasetVersion>> selectionPolicies; private final CombineOperation combineOperation; + public CombineSelectionPolicy(Config config) + throws IOException { + this(config, new Properties()); + } + public CombineSelectionPolicy(List<VersionSelectionPolicy<DatasetVersion>> selectionPolicies, CombineOperation combineOperation) { this.combineOperation = combineOperation; @@ -85,17 +89,18 @@ public class CombineSelectionPolicy implements VersionSelectionPolicy<DatasetVer } @SuppressWarnings("unchecked") - public CombineSelectionPolicy(Config config, Properties jobProps) throws IOException { + public CombineSelectionPolicy(Config config, Properties jobProps) + throws IOException { Preconditions.checkArgument(config.hasPath(VERSION_SELECTION_POLICIES_PREFIX), "Combine operation not specified."); ImmutableList.Builder<VersionSelectionPolicy<DatasetVersion>> builder = ImmutableList.builder(); for (String combineClassName : config.getStringList(VERSION_SELECTION_POLICIES_PREFIX)) { try { - builder.add((VersionSelectionPolicy<DatasetVersion>) GobblinConstructorUtils.invokeFirstConstructor( - Class.forName(combineClassName), ImmutableList.<Object> of(config), ImmutableList.<Object> of(jobProps))); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException - | ClassNotFoundException e) { + builder.add((VersionSelectionPolicy<DatasetVersion>) GobblinConstructorUtils + .invokeFirstConstructor(Class.forName(combineClassName), ImmutableList.<Object>of(config), + ImmutableList.<Object>of(jobProps))); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } } @@ -109,9 +114,9 @@ public class CombineSelectionPolicy implements VersionSelectionPolicy<DatasetVer CombineOperation.valueOf(config.getString(VERSION_SELECTION_COMBINE_OPERATION).toUpperCase()); } - public CombineSelectionPolicy(Properties props) throws IOException { + public CombineSelectionPolicy(Properties props) + throws IOException { this(ConfigFactory.parseProperties(props), props); - } /** @@ -150,7 +155,6 @@ public class CombineSelectionPolicy implements VersionSelectionPolicy<DatasetVer default: throw new RuntimeException("Combine operation " + this.combineOperation + " not recognized."); } - } @VisibleForTesting
