Search in sources :

Example 11 with ClassAliasResolver

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);
    }
}
Also used : ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 12 with ClassAliasResolver

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;
}
Also used : ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) ConfigFactory(com.typesafe.config.ConfigFactory) IOException(java.io.IOException) DatasetStateStore(org.apache.gobblin.metastore.DatasetStateStore) IOException(java.io.IOException)

Example 13 with ClassAliasResolver

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);
    }
}
Also used : RequestAllocatorConfig(org.apache.gobblin.util.request_allocation.RequestAllocatorConfig) MRCompactionTaskFactory(org.apache.gobblin.compaction.mapreduce.MRCompactionTaskFactory) ResourceEstimator(org.apache.gobblin.util.request_allocation.ResourceEstimator) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SimpleDatasetRequest(org.apache.gobblin.data.management.dataset.SimpleDatasetRequest) Comparator(java.util.Comparator) ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) HierarchicalPrioritizer(org.apache.gobblin.util.request_allocation.HierarchicalPrioritizer)

Aggregations

ClassAliasResolver (org.apache.gobblin.util.ClassAliasResolver)13 IOException (java.io.IOException)6 DatasetStateStore (org.apache.gobblin.metastore.DatasetStateStore)5 ExecutionException (java.util.concurrent.ExecutionException)3 BeforeClass (org.testng.annotations.BeforeClass)3 ConfigFactory (com.typesafe.config.ConfigFactory)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 TestingServer (org.apache.curator.test.TestingServer)2 ConfigBuilder (org.apache.gobblin.config.ConfigBuilder)2 LoggerFactory (org.slf4j.LoggerFactory)2 ConfigValueFactory (com.typesafe.config.ConfigValueFactory)1 Closeable (java.io.Closeable)1 File (java.io.File)1 URL (java.net.URL)1 Comparator (java.util.Comparator)1 NoSuchElementException (java.util.NoSuchElementException)1 TimeoutException (java.util.concurrent.TimeoutException)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 AuditCountClientFactory (org.apache.gobblin.compaction.audit.AuditCountClientFactory)1 RecompactionConditionFactory (org.apache.gobblin.compaction.conditions.RecompactionConditionFactory)1