com.facebook.presto.spi.connector.Connector Java Examples

The following examples show how to use com.facebook.presto.spi.connector.Connector. 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 File: KubeConnectorFactory.java    From kubesql with 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");

    try {
        Bootstrap app = new Bootstrap(
                binder -> binder.bind(NodeManager.class).toInstance(context.getNodeManager()),
                new KubeModule(catalogName));

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

        return injector.getInstance(KubeConnector.class);
    }
    catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: ParaflowConnectorFactory.java    From paraflow with Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(config, "config is null");

    try {
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new ParaflowModule(connectorId, context.getTypeManager())
        );

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

        return injector.getInstance(ParaflowConnector.class);
    }
    catch (Exception e) {
        throw new PrestoException(CONNECTOR_INIT_ERROR, e);
    }
}
 
Example #3
Source File: KuduConnectorFactory.java    From presto-kudu with Apache License 2.0 6 votes vote down vote up
@Override
public Connector create(String connectorId, Map<String, String> config,
                        ConnectorContext context) {
    requireNonNull(config, "config is null");

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

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

        return injector.getInstance(KuduConnector.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: TestUtils.java    From presto-kinesis with Apache License 2.0 6 votes vote down vote up
/**
 * Build a connector instance from the plug in, supplying the given properties.
 *
 * This can build a connector with the mock client which is normally done in testing.
 * The plug in is created first with createPluginInstance.
 *
 * @param plugin
 * @param properties
 * @param withMockClient
 * @return
 */
public static KinesisConnector createConnector(KinesisPlugin plugin, Map<String, String> properties, boolean withMockClient)
{
    requireNonNull(plugin, "Plugin instance should not be null");
    requireNonNull(properties, "Properties map should not be null (can be empty)");

    if (withMockClient) {
        plugin.setAltProviderClass(KinesisTestClientManager.class);
    }

    ConnectorFactory factory = plugin.getConnectorFactories().iterator().next();
    assertNotNull(factory);

    Connector connector = factory.create("kinesis", properties, new TestingConnectorContext() {});
    assertTrue(connector instanceof KinesisConnector);
    return (KinesisConnector) connector;
}
 
Example #5
Source File: ElasticsearchConnectorFactory.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(connectorId, "connectorId is null");
    requireNonNull(config, "requiredConfig is null");
    requireNonNull(context, "context is null");

    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        final Bootstrap app = new Bootstrap(
                new ElasticsearchModule(), module,
                binder -> {
                    binder.bind(ElasticsearchConnectorId.class).toInstance(new ElasticsearchConnectorId(connectorId));
                    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);
    }
    catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: HbaseConnectorFactory.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context)
{
    requireNonNull(connectorId, "connectorId is null");
    requireNonNull(config, "requiredConfig is null");
    requireNonNull(context, "context is null");

    try {
        Bootstrap app = new Bootstrap(
                new HbaseModule(),
                binder -> {
                    binder.bind(HbaseConnectorId.class).toInstance(new HbaseConnectorId(connectorId));
                    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(HbaseConnector.class);
    }
    catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
Example #7
Source File: EthereumConnectorFactory.java    From presto-ethereum with Apache License 2.0 5 votes vote down vote up
@Override
    public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
        requireNonNull(connectorId, "connectorId is null");
        requireNonNull(config, "config is null");

        try {
            Bootstrap app = new Bootstrap(
//                    new JsonModule(),
                    new EthereumConnectorModule(),
                    binder -> {
                        binder.bind(EthereumConnectorId.class).toInstance(new EthereumConnectorId(connectorId));
                        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(EthereumConnector.class);
        }
        catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
 
Example #8
Source File: TestKinesisPlugin.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Parameters({
        "kinesis.awsAccessKey",
        "kinesis.awsSecretKey"
})
@Test
public void testSpinUp(String awsAccessKey, String awsSecretKey)
{
    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(awsAccessKey))
            .put("kinesis.secret-key", TestUtils.noneToBlank(awsSecretKey))
            .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 != null && handle instanceof KinesisTransactionHandle);
}
 
Example #9
Source File: KinesisConnectorFactory.java    From presto-kinesis with Apache License 2.0 4 votes vote down vote up
@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context)
{
    log.info("In connector factory create method.  Connector id: " + connectorId);
    requireNonNull(connectorId, "connectorId is null");
    requireNonNull(config, "config is null");

    try {
        Bootstrap app = new Bootstrap(
                new JsonModule(),
                new KinesisConnectorModule(),
                binder -> {
                    binder.bindConstant().annotatedWith(Names.named("connectorId")).to(connectorId);
                    binder.bind(ConnectorId.class).toInstance(new ConnectorId(connectorId));
                    binder.bind(TypeManager.class).toInstance(context.getTypeManager());
                    binder.bind(NodeManager.class).toInstance(context.getNodeManager());
                    // Note: moved creation from KinesisConnectorModule because connector manager accesses it earlier!
                    binder.bind(KinesisHandleResolver.class).toInstance(new KinesisHandleResolver(connectorName));

                    // Moved creation here from KinesisConnectorModule to make it easier to parameterize
                    if (altProviderClass.isPresent()) {
                        binder.bind(KinesisClientProvider.class).to(altProviderClass.get()).in(Scopes.SINGLETON);
                    }
                    else {
                        binder.bind(KinesisClientProvider.class).to(KinesisClientManager.class).in(Scopes.SINGLETON);
                    }

                    if (tableDescriptionSupplier.isPresent()) {
                        binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KinesisStreamDescription>>>() {}).toInstance(tableDescriptionSupplier.get());
                    }
                    else {
                        binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KinesisStreamDescription>>>() {}).to(KinesisTableDescriptionSupplier.class).in(Scopes.SINGLETON);
                    }
                }
        );

        this.injector = app.strictConfig()
                    .doNotInitializeLogging()
                    .setRequiredConfigurationProperties(config)
                    .setOptionalConfigurationProperties(optionalConfig)
                    .initialize();

        KinesisConnector connector = this.injector.getInstance(KinesisConnector.class);

        // Register objects for shutdown, at the moment only KinesisTableDescriptionSupplier
        if (!tableDescriptionSupplier.isPresent()) {
            // This will shutdown related dependent objects as well:
            KinesisTableDescriptionSupplier supp = getTableDescSupplier(this.injector);
            connector.registerShutdownObject(supp);
        }

        log.info("Done with injector.  Returning the connector itself.");
        return connector;
    }
    catch (Exception e) {
        throw Throwables.propagate(e);
    }
}