Java Code Examples for io.prestosql.spi.connector.Connector

The following examples show how to use io.prestosql.spi.connector.Connector. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: presto   Source File: KafkaConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new KafkaConnectorModule(),
            extension,
            binder -> {
                binder.bind(ClassLoader.class).toInstance(KafkaConnectorFactory.class.getClassLoader());
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(KafkaConnector.class);
}
 
Example 2
Source Project: presto   Source File: TestKafkaPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSpinup()
{
    KafkaPlugin plugin = new KafkaPlugin();

    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, KafkaConnectorFactory.class);

    Connector c = factory.create(
            "test-connector",
            ImmutableMap.<String, String>builder()
                    .put("kafka.table-names", "test")
                    .put("kafka.nodes", "localhost:9092")
                    .build(),
            new TestingConnectorContext());
    assertNotNull(c);
}
 
Example 3
Source Project: presto   Source File: PrometheusConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");
    try {
        // A plugin is not required to use Guice; it is just very convenient
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new PrometheusModule(context.getTypeManager()));

        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(requiredConfig)
                .initialize();

        return injector.getInstance(PrometheusConnector.class);
    }
    catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example 4
Source Project: presto   Source File: ExampleConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    // A plugin is not required to use Guice; it is just very convenient
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new ExampleModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(requiredConfig)
            .initialize();

    return injector.getInstance(ExampleConnector.class);
}
 
Example 5
Source Project: presto   Source File: TestRedisPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStartup()
{
    RedisPlugin plugin = new RedisPlugin();

    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    assertInstanceOf(factory, RedisConnectorFactory.class);

    Connector c = factory.create(
            "test-connector",
            ImmutableMap.<String, String>builder()
                    .put("redis.table-names", "test")
                    .put("redis.nodes", "localhost:6379")
                    .build(),
            new TestingConnectorContext());
    assertNotNull(c);
}
 
Example 6
Source Project: presto   Source File: TestCoordinatorDynamicFiltering.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
    return ImmutableList.of(new ConnectorFactory()
    {
        private final ConnectorMetadata metadata = new TestingMetadata();

        @Override
        public String getName()
        {
            return "test";
        }

        @Override
        public ConnectorHandleResolver getHandleResolver()
        {
            return new TestingHandleResolver();
        }

        @Override
        public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
        {
            return new TestConnector(metadata, Duration.valueOf("10s"), expectedDynamicFilter);
        }
    });
}
 
Example 7
Source Project: presto   Source File: TestBeginQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConnectorFactory> getConnectorFactories()
{
    return ImmutableList.of(new ConnectorFactory()
    {
        @Override
        public String getName()
        {
            return "test";
        }

        @Override
        public ConnectorHandleResolver getHandleResolver()
        {
            return new TestingHandleResolver();
        }

        @Override
        public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
        {
            return new TestConnector(metadata);
        }
    });
}
 
Example 8
Source Project: presto   Source File: JmxConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    Bootstrap app = new Bootstrap(
            new MBeanServerModule(),
            binder -> {
                configBinder(binder).bindConfig(JmxConnectorConfig.class);
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
                binder.bind(JmxConnector.class).in(Scopes.SINGLETON);
                binder.bind(JmxHistoricalData.class).in(Scopes.SINGLETON);
                binder.bind(JmxMetadata.class).in(Scopes.SINGLETON);
                binder.bind(JmxSplitManager.class).in(Scopes.SINGLETON);
                binder.bind(JmxPeriodicSampler.class).in(Scopes.SINGLETON);
                binder.bind(JmxRecordSetProvider.class).in(Scopes.SINGLETON);
            });

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(JmxConnector.class);
}
 
Example 9
Source Project: presto   Source File: AccumuloConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "requiredConfig is null");
    requireNonNull(context, "context is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new AccumuloModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(AccumuloConnector.class);
}
 
Example 10
Source Project: presto   Source File: JdbcConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    Bootstrap app = new Bootstrap(
            binder -> binder.bind(TypeManager.class).toInstance(context.getTypeManager()),
            binder -> binder.bind(NodeManager.class).toInstance(context.getNodeManager()),
            binder -> binder.bind(VersionEmbedder.class).toInstance(context.getVersionEmbedder()),
            new JdbcModule(catalogName),
            moduleProvider.getModule(catalogName));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(requiredConfig)
            .initialize();

    return injector.getInstance(JdbcConnector.class);
}
 
Example 11
Source Project: presto   Source File: PhoenixConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new MBeanServerModule(),
                new MBeanModule(),
                new PhoenixClientModule(catalogName),
                binder -> {
                    binder.bind(ClassLoader.class).toInstance(PhoenixConnectorFactory.class.getClassLoader());
                    binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                });

        Injector injector = app
                .strictConfig()
                .doNotInitializeLogging()
                .setRequiredConfigurationProperties(requiredConfig)
                .initialize();

        return injector.getInstance(PhoenixConnector.class);
    }
}
 
Example 12
Source Project: presto   Source File: ConnectorManager.java    License: Apache License 2.0 6 votes vote down vote up
@PreDestroy
public synchronized void stop()
{
    if (stopped.getAndSet(true)) {
        return;
    }

    for (Map.Entry<CatalogName, MaterializedConnector> entry : connectors.entrySet()) {
        Connector connector = entry.getValue().getConnector();
        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(connector.getClass().getClassLoader())) {
            connector.shutdown();
        }
        catch (Throwable t) {
            log.error(t, "Error shutting down connector: %s", entry.getKey());
        }
    }
}
 
Example 13
Source Project: presto   Source File: ConnectorManager.java    License: Apache License 2.0 6 votes vote down vote up
private synchronized void removeConnectorInternal(CatalogName catalogName)
{
    splitManager.removeConnectorSplitManager(catalogName);
    pageSourceManager.removeConnectorPageSourceProvider(catalogName);
    pageSinkManager.removeConnectorPageSinkProvider(catalogName);
    indexManager.removeIndexProvider(catalogName);
    nodePartitioningManager.removePartitioningProvider(catalogName);
    metadataManager.getProcedureRegistry().removeProcedures(catalogName);
    accessControlManager.removeCatalogAccessControl(catalogName);
    metadataManager.getTablePropertyManager().removeProperties(catalogName);
    metadataManager.getColumnPropertyManager().removeProperties(catalogName);
    metadataManager.getSchemaPropertyManager().removeProperties(catalogName);
    metadataManager.getAnalyzePropertyManager().removeProperties(catalogName);
    metadataManager.getSessionPropertyManager().removeConnectorSessionProperties(catalogName);

    MaterializedConnector materializedConnector = connectors.remove(catalogName);
    if (materializedConnector != null) {
        Connector connector = materializedConnector.getConnector();
        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(connector.getClass().getClassLoader())) {
            connector.shutdown();
        }
        catch (Throwable t) {
            log.error(t, "Error shutting down connector: %s", catalogName);
        }
    }
}
 
Example 14
Source Project: presto   Source File: Catalog.java    License: Apache License 2.0 6 votes vote down vote up
public Catalog(
        String catalogName,
        CatalogName connectorCatalogName,
        Connector connector,
        CatalogName informationSchemaId,
        Connector informationSchema,
        CatalogName systemTablesId,
        Connector systemTables)
{
    this.catalogName = checkCatalogName(catalogName);
    this.connectorCatalogName = requireNonNull(connectorCatalogName, "connectorConnectorId is null");
    this.connector = requireNonNull(connector, "connector is null");
    this.informationSchemaId = requireNonNull(informationSchemaId, "informationSchemaId is null");
    this.informationSchema = requireNonNull(informationSchema, "informationSchema is null");
    this.systemTablesId = requireNonNull(systemTablesId, "systemTablesId is null");
    this.systemTables = requireNonNull(systemTables, "systemTables is null");
}
 
Example 15
Source Project: presto   Source File: TestingSession.java    License: Apache License 2.0 6 votes vote down vote up
private static Connector createTestSessionConnector()
{
    return new Connector()
    {
        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
        {
            return new ConnectorTransactionHandle() {};
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction)
        {
            return new SystemTablesMetadata(new StaticSystemTablesProvider(ImmutableSet.of()));
        }
    };
}
 
Example 16
Source Project: presto   Source File: TestAccessControlManager.java    License: Apache License 2.0 6 votes vote down vote up
private static CatalogName registerBogusConnector(CatalogManager catalogManager, TransactionManager transactionManager, AccessControl accessControl, String catalogName)
{
    CatalogName catalog = new CatalogName(catalogName);
    Connector connector = new TpchConnectorFactory().create(catalogName, ImmutableMap.of(), new TestingConnectorContext());

    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    Metadata metadata = createTestMetadataManager(catalogManager);
    CatalogName systemId = createSystemTablesCatalogName(catalog);
    catalogManager.registerCatalog(new Catalog(
            catalogName,
            catalog,
            connector,
            createInformationSchemaCatalogName(catalog),
            new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl),
            systemId,
            new SystemConnector(
                    nodeManager,
                    connector.getSystemTables(),
                    transactionId -> transactionManager.getConnectorTransaction(transactionId, catalog))));

    return catalog;
}
 
Example 17
Source Project: presto   Source File: TestTransactionManager.java    License: Apache License 2.0 6 votes vote down vote up
private static void registerConnector(
        CatalogManager catalogManager,
        TransactionManager transactionManager,
        String catalogName,
        CatalogName catalog,
        Connector connector)
{
    CatalogName systemId = createSystemTablesCatalogName(catalog);
    InternalNodeManager nodeManager = new InMemoryNodeManager();
    Metadata metadata = createTestMetadataManager(catalogManager);

    catalogManager.registerCatalog(new Catalog(
            catalogName,
            catalog,
            connector,
            createInformationSchemaCatalogName(catalog),
            new InformationSchemaConnector(catalogName, nodeManager, metadata, new AllowAllAccessControl()),
            systemId,
            new SystemConnector(
                    nodeManager,
                    connector.getSystemTables(),
                    transactionId -> transactionManager.getConnectorTransaction(transactionId, catalog))));
}
 
Example 18
Source Project: presto   Source File: TestAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private Catalog createTestingCatalog(String catalogName, CatalogName catalog)
{
    CatalogName systemId = createSystemTablesCatalogName(catalog);
    Connector connector = createTestingConnector();
    InternalNodeManager nodeManager = new InMemoryNodeManager();
    return new Catalog(
            catalogName,
            catalog,
            connector,
            createInformationSchemaCatalogName(catalog),
            new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl),
            systemId,
            new SystemConnector(
                    nodeManager,
                    connector.getSystemTables(),
                    transactionId -> transactionManager.getConnectorTransaction(transactionId, catalog)));
}
 
Example 19
Source Project: presto   Source File: MongoConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MongoClientModule(),
            binder -> binder.bind(TypeManager.class).toInstance(context.getTypeManager()));

    Injector injector = app.strictConfig().doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(MongoConnector.class);
}
 
Example 20
Source Project: presto   Source File: MemoryConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context)
{
    requireNonNull(requiredConfig, "requiredConfig is null");

    // A plugin is not required to use Guice; it is just very convenient
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MemoryModule(context.getTypeManager(), context.getNodeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(requiredConfig)
            .initialize();

    return injector.getInstance(MemoryConnector.class);
}
 
Example 21
Source Project: presto   Source File: ElasticsearchConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new MBeanModule(),
            new MBeanServerModule(),
            new ConnectorObjectNameGeneratorModule(catalogName, "io.prestosql.elasticsearch", "presto.plugin.elasticsearch"),
            new JsonModule(),
            new ElasticsearchConnectorModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(ElasticsearchConnector.class);
}
 
Example 22
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new ElasticsearchConnectorModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(ElasticsearchConnector.class);
}
 
Example 23
Source Project: presto   Source File: ThriftConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    Bootstrap app = new Bootstrap(
            new MBeanModule(),
            new MBeanServerModule(),
            new ConnectorObjectNameGeneratorModule(catalogName, "io.prestosql.plugin.thrift", "presto.plugin.thrift"),
            new DriftNettyClientModule(),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            },
            locationModule,
            new ThriftModule());

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(ThriftConnector.class);
}
 
Example 24
Source Project: presto   Source File: BigQueryConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new BigQueryConnectorModule(context.getNodeManager()),
            binder -> {
                binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            });

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(BigQueryConnector.class);
}
 
Example 25
Source Project: presto   Source File: LocalFileConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            binder -> binder.bind(NodeManager.class).toInstance(context.getNodeManager()),
            new LocalFileModule());

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(LocalFileConnector.class);
}
 
Example 26
Source Project: presto   Source File: CassandraConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new MBeanModule(),
            new JsonModule(),
            new CassandraClientModule(),
            new MBeanServerModule());

    Injector injector = app.strictConfig().doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(CassandraConnector.class);
}
 
Example 27
Source Project: presto   Source File: KuduConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new KuduModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(KuduConnector.class);
}
 
Example 28
Source Project: presto   Source File: TestKinesisPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSpinUp()
{
    String accessKey = "kinesis.accessKey";
    String secretKey = "kinesis.secretKey";
    ConnectorFactory factory = testConnectorExists();
    // Important: this has to be created before we setup the injector in the factory:
    assertNotNull(factory.getHandleResolver());

    Connector c = factory.create("kinesis.test-connector", ImmutableMap.<String, String>builder()
            .put("kinesis.hide-internal-columns", "false")
            .put("kinesis.access-key", TestUtils.noneToBlank(accessKey))
            .put("kinesis.secret-key", TestUtils.noneToBlank(secretKey))
            .build(), new TestingConnectorContext());
    assertNotNull(c);

    // Verify that the key objects have been created on the connector
    assertNotNull(c.getRecordSetProvider());
    assertNotNull(c.getSplitManager());
    ConnectorMetadata md = c.getMetadata(KinesisTransactionHandle.INSTANCE);
    assertNotNull(md);

    ConnectorTransactionHandle handle = c.beginTransaction(READ_COMMITTED, true);
    assertTrue(handle instanceof KinesisTransactionHandle);
}
 
Example 29
Source Project: presto   Source File: SheetsConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new SheetsModule(context.getTypeManager()));

    Injector injector = app
            .strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(SheetsConnector.class);
}
 
Example 30
Source Project: presto   Source File: PinotConnectorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(catalogName, "connectorId is null");
    requireNonNull(config, "config is null");
    Bootstrap app = new Bootstrap(
            new JsonModule(),
            new MBeanModule(),
            new PinotModule(catalogName, context.getTypeManager(), context.getNodeManager()));

    Injector injector = app.strictConfig()
            .doNotInitializeLogging()
            .setRequiredConfigurationProperties(config)
            .initialize();

    return injector.getInstance(PinotConnector.class);
}