public NewestKSelectionPolicy(Properties props) { this(Params.createFromProps(props)); }
public VersionFinderAndPolicy(RetentionPolicy<T> retentionPolicy, VersionFinder<? extends T> versionFinder) { this(new EmbeddedRetentionSelectionPolicy<>(retentionPolicy), versionFinder); }
public NewestKSelectionPolicy(int versionsRetained, boolean excludeMode) { this(new Params(versionsRetained, excludeMode)); }
@Override public Collection<T> listSelectedVersions(List<T> allVersions) { if (this.isExcludeMode()) { return getBoundarySafeSublist(allVersions, this.getVersionsSelected(), allVersions.size()); } return getBoundarySafeSublist(allVersions, 0, this.getVersionsSelected()); }
/** * Returns the most specific common superclass for the {@link #versionClass} of each embedded policy. */ @Override public Class<? extends DatasetVersion> versionClass() { if (this.selectionPolicies.size() == 1) { return this.selectionPolicies.get(0).versionClass(); } Class<? extends DatasetVersion> klazz = this.selectionPolicies.get(0).versionClass(); for (VersionSelectionPolicy<? extends DatasetVersion> policy : this.selectionPolicies) { klazz = commonSuperclass(klazz, policy.versionClass()); } return klazz; }
public SelectBetweenTimeBasedPolicy(Config conf) { this(conf.hasPath(TIME_BASED_SELECTION_MIN_LOOK_BACK_TIME_KEY) ? Optional.of(getLookBackPeriod(conf .getString(TIME_BASED_SELECTION_MIN_LOOK_BACK_TIME_KEY))) : Optional.<Period> absent(), conf .hasPath(TIME_BASED_SELECTION_MAX_LOOK_BACK_TIME_KEY) ? Optional.of(getLookBackPeriod(conf .getString(TIME_BASED_SELECTION_MAX_LOOK_BACK_TIME_KEY))) : Optional.<Period> absent()); }
public NewestKSelectionPolicy(Config config) { this(Params.createFromConfig(config)); }
@Nullable @Override public Set<DatasetVersion> apply(VersionSelectionPolicy<DatasetVersion> input) { return Sets.newHashSet(input.listSelectedVersions(allVersions)); } }));
@VisibleForTesting boolean isExcludeMode() { return this.params.isExcludeMode(); } }
@VisibleForTesting int getVersionsSelected() { return this.params.getVersionsSelected(); }
public SelectBeforeTimeBasedPolicy(Config conf) { super(Optional.of(getMinLookbackTime(conf)), Optional.<Period>absent()); }
@Override public Collection<FileSystemDatasetVersion> listSelectedVersions(List<FileSystemDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); } }
public SelectAfterTimeBasedPolicy(Config conf) { super(Optional.<Period>absent(), Optional.of(getMaxLookbackTime(conf))); }
@Override public Collection<TimestampedDatasetVersion> listSelectedVersions(List<TimestampedDatasetVersion> allVersions) { return Lists.newArrayList(Collections2.filter(allVersions, getSelectionPredicate())); }
@SuppressWarnings("unchecked") public VersionFinderAndPolicy<T> build() { VersionSelectionPolicy<T> localVersionSelectionPolicy; List<RetentionAction> localRetentionActions; if (this.versionSelectionPolicy == null) { localVersionSelectionPolicy = (VersionSelectionPolicy<T>) new SelectNothingPolicy(new Properties()); } else { localVersionSelectionPolicy = this.versionSelectionPolicy; } if (this.retentionActions == null) { localRetentionActions = Lists.newArrayList(); } else { localRetentionActions = Lists.newArrayList(this.retentionActions); } return new VersionFinderAndPolicy<T>(localVersionSelectionPolicy, this.versionFinder, localRetentionActions); } }
private static Period getMaxLookbackTime(Config conf) { Preconditions.checkArgument(conf.hasPath(TIME_BASED_SELECTION_LOOK_BACK_TIME_KEY), String.format("Required property %s is not specified", TIME_BASED_SELECTION_LOOK_BACK_TIME_KEY)); return SelectBetweenTimeBasedPolicy.getLookBackPeriod(conf.getString(TIME_BASED_SELECTION_LOOK_BACK_TIME_KEY)); } }
static Params createFromConfig(Config config) { if (config.hasPath(NEWEST_K_VERSIONS_SELECTED_KEY)) { if (config.hasPath(NEWEST_K_VERSIONS_NOTSELECTED_KEY)) { throw new RuntimeException("Only one of " + NEWEST_K_VERSIONS_SELECTED_KEY + " and " + NEWEST_K_VERSIONS_NOTSELECTED_KEY + " can be specified."); } return new Params(config.getInt(NEWEST_K_VERSIONS_SELECTED_KEY), false); } else if (config.hasPath(NEWEST_K_VERSIONS_NOTSELECTED_KEY)) { return new Params(config.getInt(NEWEST_K_VERSIONS_NOTSELECTED_KEY), true); } else { return new Params(VERSIONS_SELECTED_DEFAULT, false); } }
static Params createFromProps(Properties props) { return createFromConfig(ConfigFactory.parseProperties(props)); } }
/** * Applies {@link #selectionPolicy} on <code>allVersions</code> and modifies permission/owner to the selected {@link DatasetVersion}s * where necessary. * <p> * This action only available for {@link FileSystemDatasetVersion}. It simply skips the operation if a different type * of {@link DatasetVersion} is passed. * </p> * {@inheritDoc} * @see org.apache.gobblin.data.management.retention.action.RetentionAction#execute(java.util.List) */ @Override public void execute(List<DatasetVersion> allVersions) throws IOException { // Select version on which access control actions need to performed for (DatasetVersion datasetVersion : this.selectionPolicy.listSelectedVersions(allVersions)) { executeOnVersion(datasetVersion); } }
private static Period getMinLookbackTime(Config conf) { Preconditions.checkArgument(conf.hasPath(TIME_BASED_SELECTION_LOOK_BACK_TIME_KEY), String.format("Required property %s is not specified", TIME_BASED_SELECTION_LOOK_BACK_TIME_KEY)); return SelectBetweenTimeBasedPolicy.getLookBackPeriod(conf.getString(TIME_BASED_SELECTION_LOOK_BACK_TIME_KEY)); } }