Search in sources :

Example 6 with ClassAliasResolver

use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.

the class GobblinHelixJobLauncherTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    TestingServer testingZKServer = this.closer.register(new TestingServer(-1));
    LOG.info("Testing ZK Server listening on: " + testingZKServer.getConnectString());
    URL url = GobblinHelixJobLauncherTest.class.getClassLoader().getResource(GobblinHelixJobLauncherTest.class.getSimpleName() + ".conf");
    Assert.assertNotNull(url, "Could not find resource " + url);
    this.appWorkDir = new Path(GobblinHelixJobLauncherTest.class.getSimpleName());
    // Prepare the source Json file
    File sourceJsonFile = new File(this.appWorkDir.toString(), TestHelper.TEST_JOB_NAME + ".json");
    TestHelper.createSourceJsonFile(sourceJsonFile);
    baseConfig = ConfigFactory.parseURL(url).withValue("gobblin.cluster.zk.connection.string", ConfigValueFactory.fromAnyRef(testingZKServer.getConnectString())).withValue(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL, ConfigValueFactory.fromAnyRef(sourceJsonFile.getAbsolutePath())).withValue(ConfigurationKeys.JOB_STATE_IN_STATE_STORE, ConfigValueFactory.fromAnyRef("true")).resolve();
    String zkConnectingString = baseConfig.getString(GobblinClusterConfigurationKeys.ZK_CONNECTION_STRING_KEY);
    String helixClusterName = baseConfig.getString(GobblinClusterConfigurationKeys.HELIX_CLUSTER_NAME_KEY);
    HelixUtils.createGobblinHelixCluster(zkConnectingString, helixClusterName);
    this.helixManager = HelixManagerFactory.getZKHelixManager(helixClusterName, TestHelper.TEST_HELIX_INSTANCE_NAME, InstanceType.CONTROLLER, zkConnectingString);
    this.closer.register(new Closeable() {

        @Override
        public void close() throws IOException {
            helixManager.disconnect();
        }
    });
    this.helixManager.connect();
    this.localFs = FileSystem.getLocal(new Configuration());
    this.closer.register(new Closeable() {

        @Override
        public void close() throws IOException {
            if (localFs.exists(appWorkDir)) {
                localFs.delete(appWorkDir, true);
            }
        }
    });
    this.gobblinTaskRunner = new GobblinTaskRunner(TestHelper.TEST_APPLICATION_NAME, TestHelper.TEST_HELIX_INSTANCE_NAME, TestHelper.TEST_APPLICATION_ID, TestHelper.TEST_TASK_RUNNER_ID, baseConfig, Optional.of(appWorkDir));
    String stateStoreType = ConfigUtils.getString(baseConfig, ConfigurationKeys.STATE_STORE_TYPE_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_TYPE);
    ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class);
    DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass(stateStoreType).newInstance();
    this.datasetStateStore = stateStoreFactory.createStateStore(baseConfig);
    this.thread = new Thread(new Runnable() {

        @Override
        public void run() {
            gobblinTaskRunner.start();
        }
    });
    this.thread.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Closeable(java.io.Closeable) LoggerFactory(org.slf4j.LoggerFactory) ConfigValueFactory(com.typesafe.config.ConfigValueFactory) ConfigFactory(com.typesafe.config.ConfigFactory) HelixManagerFactory(org.apache.helix.HelixManagerFactory) IOException(java.io.IOException) DatasetStateStore(org.apache.gobblin.metastore.DatasetStateStore) FsDatasetStateStore(org.apache.gobblin.runtime.FsDatasetStateStore) URL(java.net.URL) ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with ClassAliasResolver

use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.

the class MysqlDatasetStateStoreTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    testMetastoreDatabase = TestMetastoreDatabaseFactory.get();
    String jdbcUrl = testMetastoreDatabase.getJdbcUrl();
    ConfigBuilder configBuilder = ConfigBuilder.create();
    BasicDataSource mySqlDs = new BasicDataSource();
    mySqlDs.setDriverClassName(ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER);
    mySqlDs.setDefaultAutoCommit(false);
    mySqlDs.setUrl(jdbcUrl);
    mySqlDs.setUsername(TEST_USER);
    mySqlDs.setPassword(TEST_PASSWORD);
    dbJobStateStore = new MysqlStateStore<>(mySqlDs, TEST_STATE_STORE, false, JobState.class);
    configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_URL_KEY, jdbcUrl);
    configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_USER_KEY, TEST_USER);
    configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, TEST_PASSWORD);
    ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class);
    DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass("mysql").newInstance();
    dbDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build());
    // clear data that may have been left behind by a prior test run
    dbJobStateStore.delete(TEST_JOB_NAME);
    dbDatasetStateStore.delete(TEST_JOB_NAME);
    dbJobStateStore.delete(TEST_JOB_NAME2);
    dbDatasetStateStore.delete(TEST_JOB_NAME2);
}
Also used : ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) ConfigBuilder(org.apache.gobblin.config.ConfigBuilder) TestMetastoreDatabaseFactory(org.apache.gobblin.metastore.testing.TestMetastoreDatabaseFactory) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) DatasetStateStore(org.apache.gobblin.metastore.DatasetStateStore) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with ClassAliasResolver

use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.

the class MRCompactor method getCompactionCompleteListener.

private CompactorCompletionListener getCompactionCompleteListener() {
    ClassAliasResolver<CompactorCompletionListenerFactory> classAliasResolver = new ClassAliasResolver<>(CompactorCompletionListenerFactory.class);
    String listenerName = this.state.getProp(MRCompactor.COMPACTION_COMPLETE_LISTERNER, MRCompactor.DEFAULT_COMPACTION_COMPLETE_LISTERNER);
    try {
        CompactorCompletionListenerFactory factory = GobblinConstructorUtils.invokeFirstConstructor(classAliasResolver.resolveClass(listenerName), ImmutableList.of());
        return factory.createCompactorCompactionListener(this.state);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) CompactorCompletionListenerFactory(org.apache.gobblin.compaction.listeners.CompactorCompletionListenerFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with ClassAliasResolver

use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.

the class DatasetStateStore method buildDatasetStateStore.

static DatasetStateStore buildDatasetStateStore(Config config) throws IOException {
    ClassAliasResolver<Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class);
    String stateStoreType = ConfigUtils.getString(config, ConfigurationKeys.STATE_STORE_TYPE_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_TYPE);
    try {
        DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass(stateStoreType).newInstance();
        return stateStoreFactory.createStateStore(config);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver) IOException(java.io.IOException) IOException(java.io.IOException)

Example 10 with ClassAliasResolver

use of org.apache.gobblin.util.ClassAliasResolver in project incubator-gobblin by apache.

the class ServiceBasedAppLauncher method createAdminServer.

public static Service createAdminServer(Properties properties, URI executionInfoServerURI) {
    String factoryClassName = properties.getProperty(ConfigurationKeys.ADMIN_SERVER_FACTORY_CLASS_KEY, ConfigurationKeys.DEFAULT_ADMIN_SERVER_FACTORY_CLASS);
    ClassAliasResolver<AdminWebServerFactory> classResolver = new ClassAliasResolver<>(AdminWebServerFactory.class);
    try {
        AdminWebServerFactory factoryInstance = classResolver.resolveClass(factoryClassName).newInstance();
        return factoryInstance.createInstance(properties, executionInfoServerURI);
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new RuntimeException("Unable to instantiate the AdminWebServer factory. " + "Have you included the module in the gobblin distribution? :" + e, e);
    }
}
Also used : AdminWebServerFactory(org.apache.gobblin.runtime.api.AdminWebServerFactory) ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver)

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