Search in sources :

Example 31 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class AbstractHerderTest method connectorStatus.

@Test
public void connectorStatus() {
    ConnectorTaskId taskId = new ConnectorTaskId(connector, 0);
    AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class, ConnectorClientConfigOverridePolicy.class).withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy).addMockedMethod("generation").createMock();
    EasyMock.expect(herder.generation()).andStubReturn(generation);
    EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
    EasyMock.expect(statusStore.get(connector)).andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
    EasyMock.expect(statusStore.getAll(connector)).andReturn(Collections.singletonList(new TaskStatus(taskId, AbstractStatus.State.UNASSIGNED, workerId, generation)));
    EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
    replayAll();
    ConnectorStateInfo state = herder.connectorStatus(connector);
    assertEquals(connector, state.name());
    assertEquals("RUNNING", state.connector().state());
    assertEquals(1, state.tasks().size());
    assertEquals(workerId, state.connector().workerId());
    ConnectorStateInfo.TaskState taskState = state.tasks().get(0);
    assertEquals(0, taskState.id());
    assertEquals("UNASSIGNED", taskState.state());
    assertEquals(workerId, taskState.workerId());
    PowerMock.verifyAll();
}
Also used : StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) NoneConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    ConnectMetrics metrics = new MockConnectMetrics();
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    group.onStartup(taskId);
    assertRunningMetric(group);
    group.onPause(taskId);
    assertPausedMetric(group);
    group.onResume(taskId);
    assertRunningMetric(group);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) RetryWithToleranceOperatorTest(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest) Test(org.junit.Test)

Example 33 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class AbstractHerderTest method testBuildRestartPlanForConnectorAndTasks.

@Test
public void testBuildRestartPlanForConnectorAndTasks() {
    RestartRequest restartRequest = new RestartRequest(connector, false, true);
    ConnectorTaskId taskId1 = new ConnectorTaskId(connector, 1);
    ConnectorTaskId taskId2 = new ConnectorTaskId(connector, 2);
    List<TaskStatus> taskStatuses = new ArrayList<>();
    taskStatuses.add(new TaskStatus(taskId1, AbstractStatus.State.RUNNING, workerId, generation));
    taskStatuses.add(new TaskStatus(taskId2, AbstractStatus.State.FAILED, workerId, generation));
    AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class, ConnectorClientConfigOverridePolicy.class).withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy).addMockedMethod("generation").createMock();
    EasyMock.expect(herder.generation()).andStubReturn(generation);
    EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
    EasyMock.expect(statusStore.get(connector)).andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
    EasyMock.expect(statusStore.getAll(connector)).andReturn(taskStatuses);
    EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
    replayAll();
    Optional<RestartPlan> mayBeRestartPlan = herder.buildRestartPlan(restartRequest);
    assertTrue(mayBeRestartPlan.isPresent());
    RestartPlan restartPlan = mayBeRestartPlan.get();
    assertTrue(restartPlan.shouldRestartConnector());
    assertTrue(restartPlan.shouldRestartTasks());
    assertEquals(2, restartPlan.taskIdsToRestart().size());
    assertTrue(restartPlan.taskIdsToRestart().contains(taskId1));
    assertTrue(restartPlan.taskIdsToRestart().contains(taskId2));
    PowerMock.verifyAll();
}
Also used : StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ArrayList(java.util.ArrayList) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) NoneConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class StandaloneHerder method tasksConfig.

@Override
public void tasksConfig(String connName, Callback<Map<ConnectorTaskId, Map<String, String>>> callback) {
    Map<ConnectorTaskId, Map<String, String>> tasksConfig = buildTasksConfig(connName);
    if (tasksConfig.isEmpty()) {
        callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), tasksConfig);
        return;
    }
    callback.onCompletion(null, tasksConfig);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) Map(java.util.Map)

Example 35 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class StandaloneHerder method createConnectorTasks.

private void createConnectorTasks(String connName, Collection<ConnectorTaskId> taskIds) {
    TargetState initialState = configState.targetState(connName);
    Map<String, String> connConfigs = configState.connectorConfig(connName);
    for (ConnectorTaskId taskId : taskIds) {
        Map<String, String> taskConfigMap = configState.taskConfig(taskId);
        worker.startTask(taskId, configState, connConfigs, taskConfigMap, this, initialState);
    }
}
Also used : TargetState(org.apache.kafka.connect.runtime.TargetState) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId)

Aggregations

ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)111 Test (org.junit.Test)59 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)45 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 Map (java.util.Map)18 FutureCallback (org.apache.kafka.connect.util.FutureCallback)16 ConnectException (org.apache.kafka.connect.errors.ConnectException)15 Callback (org.apache.kafka.connect.util.Callback)15 Connector (org.apache.kafka.connect.connector.Connector)13 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)12 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)12 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)12 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)11 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)11 SourceConnector (org.apache.kafka.connect.source.SourceConnector)11 Herder (org.apache.kafka.connect.runtime.Herder)10 List (java.util.List)9 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)9 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)8