use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.
the class CliEmbeddedGobblin method run.
@Override
public void run(String[] args) throws IOException {
int startOptions = 1;
Class<? extends EmbeddedGobblinCliFactory> factoryClass;
String alias = "";
if (args.length >= 2 && !args[1].startsWith("-")) {
alias = args[1];
startOptions = 2;
}
if (alias.equals(LIST_QUICK_APPS)) {
listQuickApps();
return;
}
EmbeddedGobblinCliFactory factory;
if (!Strings.isNullOrEmpty(alias)) {
try {
ClassAliasResolver<EmbeddedGobblinCliFactory> resolver = new ClassAliasResolver<>(EmbeddedGobblinCliFactory.class);
factoryClass = resolver.resolveClass(alias);
factory = factoryClass.newInstance();
} catch (ReflectiveOperationException roe) {
System.out.println("Error: Could not find job with alias " + alias);
System.out.println("For a list of jobs available: \"gobblin run " + LIST_QUICK_APPS + "\"");
return;
}
} else {
factory = new EmbeddedGobblin.CliFactory();
}
String usage;
if (Strings.isNullOrEmpty(alias)) {
usage = "gobblin run [listQuickApps] [<quick-app>] " + factory.getUsageString();
} else {
usage = "gobblin run " + alias + " " + factory.getUsageString();
}
EmbeddedGobblin embeddedGobblin = factory.buildObject(args, startOptions, true, usage);
try {
embeddedGobblin.run();
} catch (InterruptedException | TimeoutException | ExecutionException exc) {
throw new RuntimeException("Failed to run Gobblin job.", exc);
}
}
use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.
the class DatasetStateCommitStep method getDatasetStateStore.
private DatasetStateStore getDatasetStateStore() throws IOException {
if (this.stateStore == null) {
ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class);
String stateStoreType = this.props.getProp(ConfigurationKeys.DATASET_STATE_STORE_TYPE_KEY, this.props.getProp(ConfigurationKeys.STATE_STORE_TYPE_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_TYPE));
try {
DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass(stateStoreType).newInstance();
this.stateStore = stateStoreFactory.createStateStore(ConfigFactory.parseProperties(props.getProperties()));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
return this.stateStore;
}
use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.
the class CompactionSource method initRequestAllocator.
private void initRequestAllocator(State state) {
try {
ResourceEstimator estimator = GobblinConstructorUtils.<ResourceEstimator>invokeLongestConstructor(new ClassAliasResolver(ResourceEstimator.class).resolveClass(state.getProp(ConfigurationKeys.COMPACTION_ESTIMATOR, SimpleDatasetRequest.SimpleDatasetCountEstimator.class.getName())));
RequestAllocatorConfig.Builder<SimpleDatasetRequest> configBuilder = RequestAllocatorConfig.builder(estimator).allowParallelization(1).withLimitedScopeConfig(ConfigBuilder.create().loadProps(state.getProperties(), ConfigurationKeys.COMPACTION_PRIORITIZATION_PREFIX).build());
if (!state.contains(ConfigurationKeys.COMPACTION_PRIORITIZER_ALIAS)) {
allocator = new GreedyAllocator<>(configBuilder.build());
return;
}
Comparator<SimpleDatasetRequest> prioritizer = GobblinConstructorUtils.<Comparator>invokeLongestConstructor(new ClassAliasResolver(Comparator.class).resolveClass(state.getProp(ConfigurationKeys.COMPACTION_PRIORITIZER_ALIAS)), state);
configBuilder.withPrioritizer(prioritizer);
if (prioritizer instanceof HierarchicalPrioritizer) {
allocator = new HierarchicalAllocator.Factory().createRequestAllocator(configBuilder.build());
} else {
allocator = RequestAllocatorUtils.inferFromConfig(configBuilder.build());
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Cannot initialize allocator", e);
}
}
Aggregations