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();
}
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);
}
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();
}
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);
}
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);
}
}
Aggregations