Search in sources :

Example 11 with Plugins

use of org.apache.kafka.connect.runtime.isolation.Plugins in project kafka by apache.

the class TransformationConfigTest method testEmbeddedConfigCast.

@Test
public void testEmbeddedConfigCast() {
    // Validate that we can construct a Connector config containing the extended config for the transform
    HashMap<String, String> connProps = new HashMap<>();
    connProps.put("name", "foo");
    connProps.put("connector.class", MockConnector.class.getName());
    connProps.put("transforms", "example");
    connProps.put("transforms.example.type", Cast.Value.class.getName());
    connProps.put("transforms.example.spec", "int8");
    // Safe when we're only constructing the config
    Plugins plugins = null;
    new ConnectorConfig(plugins, connProps);
}
Also used : HashMap(java.util.HashMap) MockConnector(org.apache.kafka.connect.tools.MockConnector) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) Test(org.junit.Test)

Example 12 with Plugins

use of org.apache.kafka.connect.runtime.isolation.Plugins in project kafka by apache.

the class TransformationConfigTest method testEmbeddedConfigMaskField.

@Test
public void testEmbeddedConfigMaskField() {
    // Validate that we can construct a Connector config containing the extended config for the transform
    HashMap<String, String> connProps = new HashMap<>();
    connProps.put("name", "foo");
    connProps.put("connector.class", MockConnector.class.getName());
    connProps.put("transforms", "example");
    connProps.put("transforms.example.type", MaskField.Value.class.getName());
    connProps.put("transforms.example.fields", "field");
    connProps.put("transforms.example.replacement", "nothing");
    // Safe when we're only constructing the config
    Plugins plugins = null;
    new ConnectorConfig(plugins, connProps);
}
Also used : HashMap(java.util.HashMap) MockConnector(org.apache.kafka.connect.tools.MockConnector) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) Test(org.junit.Test)

Example 13 with Plugins

use of org.apache.kafka.connect.runtime.isolation.Plugins in project kafka by apache.

the class ConnectStandalone method main.

public static void main(String[] args) {
    if (args.length < 2 || Arrays.asList(args).contains("--help")) {
        log.info("Usage: ConnectStandalone worker.properties connector1.properties [connector2.properties ...]");
        Exit.exit(1);
    }
    try {
        Time time = Time.SYSTEM;
        log.info("Kafka Connect standalone worker initializing ...");
        long initStart = time.hiResClockMs();
        WorkerInfo initInfo = new WorkerInfo();
        initInfo.logAll();
        String workerPropsFile = args[0];
        Map<String, String> workerProps = !workerPropsFile.isEmpty() ? Utils.propsToStringMap(Utils.loadProps(workerPropsFile)) : Collections.emptyMap();
        log.info("Scanning for plugin classes. This might take a moment ...");
        Plugins plugins = new Plugins(workerProps);
        plugins.compareAndSwapWithDelegatingLoader();
        StandaloneConfig config = new StandaloneConfig(workerProps);
        String kafkaClusterId = ConnectUtils.lookupKafkaClusterId(config);
        log.debug("Kafka cluster ID: {}", kafkaClusterId);
        RestServer rest = new RestServer(config);
        rest.initializeServer();
        URI advertisedUrl = rest.advertisedUrl();
        String workerId = advertisedUrl.getHost() + ":" + advertisedUrl.getPort();
        ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy = plugins.newPlugin(config.getString(WorkerConfig.CONNECTOR_CLIENT_POLICY_CLASS_CONFIG), config, ConnectorClientConfigOverridePolicy.class);
        Worker worker = new Worker(workerId, time, plugins, config, new FileOffsetBackingStore(), connectorClientConfigOverridePolicy);
        Herder herder = new StandaloneHerder(worker, kafkaClusterId, connectorClientConfigOverridePolicy);
        final Connect connect = new Connect(herder, rest);
        log.info("Kafka Connect standalone worker initialization took {}ms", time.hiResClockMs() - initStart);
        try {
            connect.start();
            for (final String connectorPropsFile : Arrays.copyOfRange(args, 1, args.length)) {
                Map<String, String> connectorProps = Utils.propsToStringMap(Utils.loadProps(connectorPropsFile));
                FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>((error, info) -> {
                    if (error != null)
                        log.error("Failed to create job for {}", connectorPropsFile);
                    else
                        log.info("Created connector {}", info.result().name());
                });
                herder.putConnectorConfig(connectorProps.get(ConnectorConfig.NAME_CONFIG), connectorProps, false, cb);
                cb.get();
            }
        } catch (Throwable t) {
            log.error("Stopping after connector error", t);
            connect.stop();
            Exit.exit(3);
        }
        // Shutdown will be triggered by Ctrl-C or via HTTP shutdown request
        connect.awaitStop();
    } catch (Throwable t) {
        log.error("Stopping due to error", t);
        Exit.exit(2);
    }
}
Also used : Connect(org.apache.kafka.connect.runtime.Connect) WorkerInfo(org.apache.kafka.connect.runtime.WorkerInfo) Time(org.apache.kafka.common.utils.Time) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) URI(java.net.URI) FileOffsetBackingStore(org.apache.kafka.connect.storage.FileOffsetBackingStore) RestServer(org.apache.kafka.connect.runtime.rest.RestServer) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) Worker(org.apache.kafka.connect.runtime.Worker) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) Herder(org.apache.kafka.connect.runtime.Herder) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins)

Example 14 with Plugins

use of org.apache.kafka.connect.runtime.isolation.Plugins in project kafka by apache.

the class DistributedHerderTest method setUp.

@Before
public void setUp() throws Exception {
    time = new MockTime();
    metrics = new MockConnectMetrics(time);
    worker = PowerMock.createMock(Worker.class);
    EasyMock.expect(worker.isSinkConnector(CONN1)).andStubReturn(Boolean.TRUE);
    AutoCloseable uponShutdown = () -> shutdownCalled.countDown();
    // Default to the old protocol unless specified otherwise
    connectProtocolVersion = CONNECT_PROTOCOL_V0;
    herder = PowerMock.createPartialMock(DistributedHerder.class, new String[] { "connectorTypeForClass", "updateDeletedConnectorStatus", "updateDeletedTaskStatus", "validateConnectorConfig", "buildRestartPlan", "recordRestarting" }, new DistributedConfig(HERDER_CONFIG), worker, WORKER_ID, KAFKA_CLUSTER_ID, statusBackingStore, configBackingStore, member, MEMBER_URL, metrics, time, noneConnectorClientConfigOverridePolicy, new AutoCloseable[] { uponShutdown });
    configUpdateListener = herder.new ConfigUpdateListener();
    rebalanceListener = herder.new RebalanceListener(time);
    plugins = PowerMock.createMock(Plugins.class);
    conn1SinkConfig = new SinkConnectorConfig(plugins, CONN1_CONFIG);
    conn1SinkConfigUpdated = new SinkConnectorConfig(plugins, CONN1_CONFIG_UPDATED);
    EasyMock.expect(herder.connectorTypeForClass(BogusSourceConnector.class.getName())).andReturn(ConnectorType.SOURCE).anyTimes();
    pluginLoader = PowerMock.createMock(PluginClassLoader.class);
    delegatingLoader = PowerMock.createMock(DelegatingClassLoader.class);
    PowerMock.mockStatic(Plugins.class);
    PowerMock.expectPrivate(herder, "updateDeletedConnectorStatus").andVoid().anyTimes();
    PowerMock.expectPrivate(herder, "updateDeletedTaskStatus").andVoid().anyTimes();
}
Also used : MockConnectMetrics(org.apache.kafka.connect.runtime.MockConnectMetrics) DelegatingClassLoader(org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader) SinkConnectorConfig(org.apache.kafka.connect.runtime.SinkConnectorConfig) Worker(org.apache.kafka.connect.runtime.Worker) MockTime(org.apache.kafka.common.utils.MockTime) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) PluginClassLoader(org.apache.kafka.connect.runtime.isolation.PluginClassLoader) Before(org.junit.Before)

Example 15 with Plugins

use of org.apache.kafka.connect.runtime.isolation.Plugins in project kafka by apache.

the class WorkerSourceTaskTest method setup.

@Override
public void setup() {
    super.setup();
    Map<String, String> workerProps = workerProps();
    plugins = new Plugins(workerProps);
    config = new StandaloneConfig(workerProps);
    sourceConfig = new SourceConnectorConfig(plugins, sourceConnectorPropsWithGroups(TOPIC), true);
    producerCallbacks = EasyMock.newCapture();
    metrics = new MockConnectMetrics();
}
Also used : StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins)

Aggregations

Plugins (org.apache.kafka.connect.runtime.isolation.Plugins)34 HashMap (java.util.HashMap)27 MockConnector (org.apache.kafka.connect.tools.MockConnector)24 Test (org.junit.Test)24 Worker (org.apache.kafka.connect.runtime.Worker)7 URI (java.net.URI)4 Connect (org.apache.kafka.connect.runtime.Connect)4 RestServer (org.apache.kafka.connect.runtime.rest.RestServer)4 DistributedConfig (org.apache.kafka.connect.runtime.distributed.DistributedConfig)3 DistributedHerder (org.apache.kafka.connect.runtime.distributed.DistributedHerder)3 StandaloneConfig (org.apache.kafka.connect.runtime.standalone.StandaloneConfig)3 ConfigBackingStore (org.apache.kafka.connect.storage.ConfigBackingStore)3 Converter (org.apache.kafka.connect.storage.Converter)3 KafkaConfigBackingStore (org.apache.kafka.connect.storage.KafkaConfigBackingStore)3 KafkaOffsetBackingStore (org.apache.kafka.connect.storage.KafkaOffsetBackingStore)3 KafkaStatusBackingStore (org.apache.kafka.connect.storage.KafkaStatusBackingStore)3 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)3 MockTime (org.apache.kafka.common.utils.MockTime)2 Time (org.apache.kafka.common.utils.Time)2 Herder (org.apache.kafka.connect.runtime.Herder)2