Search in sources :

Example 1 with WorkerConfigTransformer

use of org.apache.kafka.connect.runtime.WorkerConfigTransformer in project kafka by apache.

the class DistributedHerderTest method testAccessors.

@Test
public void testAccessors() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    EasyMock.expect(worker.getPlugins()).andReturn(plugins).anyTimes();
    expectRebalance(1, Collections.emptyList(), Collections.emptyList());
    EasyMock.expect(configBackingStore.snapshot()).andReturn(SNAPSHOT).times(2);
    WorkerConfigTransformer configTransformer = EasyMock.mock(WorkerConfigTransformer.class);
    EasyMock.expect(configTransformer.transform(EasyMock.eq(CONN1), EasyMock.anyObject())).andThrow(new AssertionError("Config transformation should not occur when requesting connector or task info"));
    EasyMock.replay(configTransformer);
    ClusterConfigState snapshotWithTransform = new ClusterConfigState(1, null, Collections.singletonMap(CONN1, 3), Collections.singletonMap(CONN1, CONN1_CONFIG), Collections.singletonMap(CONN1, TargetState.STARTED), TASK_CONFIGS_MAP, Collections.emptySet(), configTransformer);
    expectPostRebalanceCatchup(snapshotWithTransform);
    member.wakeup();
    PowerMock.expectLastCall().anyTimes();
    // list connectors, get connector info, get connector config, get task configs
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    PowerMock.replayAll();
    FutureCallback<Collection<String>> listConnectorsCb = new FutureCallback<>();
    herder.connectors(listConnectorsCb);
    FutureCallback<ConnectorInfo> connectorInfoCb = new FutureCallback<>();
    herder.connectorInfo(CONN1, connectorInfoCb);
    FutureCallback<Map<String, String>> connectorConfigCb = new FutureCallback<>();
    herder.connectorConfig(CONN1, connectorConfigCb);
    FutureCallback<List<TaskInfo>> taskConfigsCb = new FutureCallback<>();
    herder.taskConfigs(CONN1, taskConfigsCb);
    herder.tick();
    assertTrue(listConnectorsCb.isDone());
    assertEquals(Collections.singleton(CONN1), listConnectorsCb.get());
    assertTrue(connectorInfoCb.isDone());
    ConnectorInfo info = new ConnectorInfo(CONN1, CONN1_CONFIG, Arrays.asList(TASK0, TASK1, TASK2), ConnectorType.SOURCE);
    assertEquals(info, connectorInfoCb.get());
    assertTrue(connectorConfigCb.isDone());
    assertEquals(CONN1_CONFIG, connectorConfigCb.get());
    assertTrue(taskConfigsCb.isDone());
    assertEquals(Arrays.asList(new TaskInfo(TASK0, TASK_CONFIG), new TaskInfo(TASK1, TASK_CONFIG), new TaskInfo(TASK2, TASK_CONFIG)), taskConfigsCb.get());
    PowerMock.verifyAll();
}
Also used : ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) WorkerConfigTransformer(org.apache.kafka.connect.runtime.WorkerConfigTransformer) TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) Collection(java.util.Collection) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with WorkerConfigTransformer

use of org.apache.kafka.connect.runtime.WorkerConfigTransformer in project kafka by apache.

the class MirrorMaker method addHerder.

private void addHerder(SourceAndTarget sourceAndTarget) {
    log.info("creating herder for " + sourceAndTarget.toString());
    Map<String, String> workerProps = config.workerConfig(sourceAndTarget);
    String advertisedUrl = advertisedBaseUrl + "/" + sourceAndTarget.source();
    String workerId = sourceAndTarget.toString();
    Plugins plugins = new Plugins(workerProps);
    plugins.compareAndSwapWithDelegatingLoader();
    DistributedConfig distributedConfig = new DistributedConfig(workerProps);
    String kafkaClusterId = ConnectUtils.lookupKafkaClusterId(distributedConfig);
    // Create the admin client to be shared by all backing stores for this herder
    Map<String, Object> adminProps = new HashMap<>(distributedConfig.originals());
    ConnectUtils.addMetricsContextProperties(adminProps, distributedConfig, kafkaClusterId);
    SharedTopicAdmin sharedAdmin = new SharedTopicAdmin(adminProps);
    KafkaOffsetBackingStore offsetBackingStore = new KafkaOffsetBackingStore(sharedAdmin);
    offsetBackingStore.configure(distributedConfig);
    Worker worker = new Worker(workerId, time, plugins, distributedConfig, offsetBackingStore, CLIENT_CONFIG_OVERRIDE_POLICY);
    WorkerConfigTransformer configTransformer = worker.configTransformer();
    Converter internalValueConverter = worker.getInternalValueConverter();
    StatusBackingStore statusBackingStore = new KafkaStatusBackingStore(time, internalValueConverter, sharedAdmin);
    statusBackingStore.configure(distributedConfig);
    ConfigBackingStore configBackingStore = new KafkaConfigBackingStore(internalValueConverter, distributedConfig, configTransformer, sharedAdmin);
    // Pass the shared admin to the distributed herder as an additional AutoCloseable object that should be closed when the
    // herder is stopped. MirrorMaker has multiple herders, and having the herder own the close responsibility is much easier than
    // tracking the various shared admin objects in this class.
    Herder herder = new DistributedHerder(distributedConfig, time, worker, kafkaClusterId, statusBackingStore, configBackingStore, advertisedUrl, CLIENT_CONFIG_OVERRIDE_POLICY, sharedAdmin);
    herders.put(sourceAndTarget, herder);
}
Also used : KafkaStatusBackingStore(org.apache.kafka.connect.storage.KafkaStatusBackingStore) StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) DistributedHerder(org.apache.kafka.connect.runtime.distributed.DistributedHerder) SharedTopicAdmin(org.apache.kafka.connect.util.SharedTopicAdmin) HashMap(java.util.HashMap) DistributedConfig(org.apache.kafka.connect.runtime.distributed.DistributedConfig) WorkerConfigTransformer(org.apache.kafka.connect.runtime.WorkerConfigTransformer) KafkaStatusBackingStore(org.apache.kafka.connect.storage.KafkaStatusBackingStore) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) KafkaConfigBackingStore(org.apache.kafka.connect.storage.KafkaConfigBackingStore) KafkaConfigBackingStore(org.apache.kafka.connect.storage.KafkaConfigBackingStore) Worker(org.apache.kafka.connect.runtime.Worker) Converter(org.apache.kafka.connect.storage.Converter) KafkaOffsetBackingStore(org.apache.kafka.connect.storage.KafkaOffsetBackingStore) Herder(org.apache.kafka.connect.runtime.Herder) DistributedHerder(org.apache.kafka.connect.runtime.distributed.DistributedHerder) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins)

Example 3 with WorkerConfigTransformer

use of org.apache.kafka.connect.runtime.WorkerConfigTransformer in project kafka by apache.

the class ConnectDistributed method startConnect.

public Connect startConnect(Map<String, String> workerProps) {
    log.info("Scanning for plugin classes. This might take a moment ...");
    Plugins plugins = new Plugins(workerProps);
    plugins.compareAndSwapWithDelegatingLoader();
    DistributedConfig config = new DistributedConfig(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();
    // Create the admin client to be shared by all backing stores.
    Map<String, Object> adminProps = new HashMap<>(config.originals());
    ConnectUtils.addMetricsContextProperties(adminProps, config, kafkaClusterId);
    SharedTopicAdmin sharedAdmin = new SharedTopicAdmin(adminProps);
    KafkaOffsetBackingStore offsetBackingStore = new KafkaOffsetBackingStore(sharedAdmin);
    offsetBackingStore.configure(config);
    ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy = plugins.newPlugin(config.getString(WorkerConfig.CONNECTOR_CLIENT_POLICY_CLASS_CONFIG), config, ConnectorClientConfigOverridePolicy.class);
    Worker worker = new Worker(workerId, time, plugins, config, offsetBackingStore, connectorClientConfigOverridePolicy);
    WorkerConfigTransformer configTransformer = worker.configTransformer();
    Converter internalValueConverter = worker.getInternalValueConverter();
    StatusBackingStore statusBackingStore = new KafkaStatusBackingStore(time, internalValueConverter, sharedAdmin);
    statusBackingStore.configure(config);
    ConfigBackingStore configBackingStore = new KafkaConfigBackingStore(internalValueConverter, config, configTransformer, sharedAdmin);
    // Pass the shared admin to the distributed herder as an additional AutoCloseable object that should be closed when the
    // herder is stopped. This is easier than having to track and own the lifecycle ourselves.
    DistributedHerder herder = new DistributedHerder(config, time, worker, kafkaClusterId, statusBackingStore, configBackingStore, advertisedUrl.toString(), connectorClientConfigOverridePolicy, sharedAdmin);
    final Connect connect = new Connect(herder, rest);
    log.info("Kafka Connect distributed worker initialization took {}ms", time.hiResClockMs() - initStart);
    try {
        connect.start();
    } catch (Exception e) {
        log.error("Failed to start Connect", e);
        connect.stop();
        Exit.exit(3);
    }
    return connect;
}
Also used : KafkaStatusBackingStore(org.apache.kafka.connect.storage.KafkaStatusBackingStore) StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) DistributedHerder(org.apache.kafka.connect.runtime.distributed.DistributedHerder) SharedTopicAdmin(org.apache.kafka.connect.util.SharedTopicAdmin) HashMap(java.util.HashMap) DistributedConfig(org.apache.kafka.connect.runtime.distributed.DistributedConfig) Connect(org.apache.kafka.connect.runtime.Connect) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) URI(java.net.URI) WorkerConfigTransformer(org.apache.kafka.connect.runtime.WorkerConfigTransformer) KafkaStatusBackingStore(org.apache.kafka.connect.storage.KafkaStatusBackingStore) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) KafkaConfigBackingStore(org.apache.kafka.connect.storage.KafkaConfigBackingStore) KafkaConfigBackingStore(org.apache.kafka.connect.storage.KafkaConfigBackingStore) RestServer(org.apache.kafka.connect.runtime.rest.RestServer) Worker(org.apache.kafka.connect.runtime.Worker) Converter(org.apache.kafka.connect.storage.Converter) KafkaOffsetBackingStore(org.apache.kafka.connect.storage.KafkaOffsetBackingStore) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins)

Aggregations

HashMap (java.util.HashMap)3 WorkerConfigTransformer (org.apache.kafka.connect.runtime.WorkerConfigTransformer)3 Worker (org.apache.kafka.connect.runtime.Worker)2 DistributedConfig (org.apache.kafka.connect.runtime.distributed.DistributedConfig)2 DistributedHerder (org.apache.kafka.connect.runtime.distributed.DistributedHerder)2 Plugins (org.apache.kafka.connect.runtime.isolation.Plugins)2 ConfigBackingStore (org.apache.kafka.connect.storage.ConfigBackingStore)2 Converter (org.apache.kafka.connect.storage.Converter)2 KafkaConfigBackingStore (org.apache.kafka.connect.storage.KafkaConfigBackingStore)2 KafkaOffsetBackingStore (org.apache.kafka.connect.storage.KafkaOffsetBackingStore)2 KafkaStatusBackingStore (org.apache.kafka.connect.storage.KafkaStatusBackingStore)2 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)2 SharedTopicAdmin (org.apache.kafka.connect.util.SharedTopicAdmin)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 ConnectorClientConfigOverridePolicy (org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy)1