use of org.apache.kafka.connect.runtime.TargetState 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);
}
}
use of org.apache.kafka.connect.runtime.TargetState in project kafka by apache.
the class WorkerCoordinatorTest method setup.
@Before
public void setup() {
LogContext logContext = new LogContext();
this.time = new MockTime();
this.metadata = new Metadata(0, Long.MAX_VALUE, logContext, new ClusterResourceListeners());
this.client = new MockClient(time, metadata);
this.client.updateMetadata(RequestTestUtils.metadataUpdateWith(1, Collections.singletonMap("topic", 1)));
this.node = metadata.fetch().nodes().get(0);
this.consumerClient = new ConsumerNetworkClient(logContext, client, metadata, time, 100, 1000, heartbeatIntervalMs);
this.metrics = new Metrics(time);
this.rebalanceListener = new MockRebalanceListener();
this.configStorage = PowerMock.createMock(KafkaConfigBackingStore.class);
this.rebalanceConfig = new GroupRebalanceConfig(sessionTimeoutMs, rebalanceTimeoutMs, heartbeatIntervalMs, groupId, Optional.empty(), retryBackoffMs, true);
this.coordinator = new WorkerCoordinator(rebalanceConfig, logContext, consumerClient, metrics, "consumer" + groupId, time, LEADER_URL, configStorage, rebalanceListener, compatibility, 0);
configState1 = new ClusterConfigState(1L, null, Collections.singletonMap(connectorId1, 1), Collections.singletonMap(connectorId1, new HashMap<>()), Collections.singletonMap(connectorId1, TargetState.STARTED), Collections.singletonMap(taskId1x0, new HashMap<>()), Collections.emptySet());
Map<String, Integer> configState2ConnectorTaskCounts = new HashMap<>();
configState2ConnectorTaskCounts.put(connectorId1, 2);
configState2ConnectorTaskCounts.put(connectorId2, 1);
Map<String, Map<String, String>> configState2ConnectorConfigs = new HashMap<>();
configState2ConnectorConfigs.put(connectorId1, new HashMap<>());
configState2ConnectorConfigs.put(connectorId2, new HashMap<>());
Map<String, TargetState> configState2TargetStates = new HashMap<>();
configState2TargetStates.put(connectorId1, TargetState.STARTED);
configState2TargetStates.put(connectorId2, TargetState.STARTED);
Map<ConnectorTaskId, Map<String, String>> configState2TaskConfigs = new HashMap<>();
configState2TaskConfigs.put(taskId1x0, new HashMap<>());
configState2TaskConfigs.put(taskId1x1, new HashMap<>());
configState2TaskConfigs.put(taskId2x0, new HashMap<>());
configState2 = new ClusterConfigState(2L, null, configState2ConnectorTaskCounts, configState2ConnectorConfigs, configState2TargetStates, configState2TaskConfigs, Collections.emptySet());
Map<String, Integer> configStateSingleTaskConnectorsConnectorTaskCounts = new HashMap<>();
configStateSingleTaskConnectorsConnectorTaskCounts.put(connectorId1, 1);
configStateSingleTaskConnectorsConnectorTaskCounts.put(connectorId2, 1);
configStateSingleTaskConnectorsConnectorTaskCounts.put(connectorId3, 1);
Map<String, Map<String, String>> configStateSingleTaskConnectorsConnectorConfigs = new HashMap<>();
configStateSingleTaskConnectorsConnectorConfigs.put(connectorId1, new HashMap<>());
configStateSingleTaskConnectorsConnectorConfigs.put(connectorId2, new HashMap<>());
configStateSingleTaskConnectorsConnectorConfigs.put(connectorId3, new HashMap<>());
Map<String, TargetState> configStateSingleTaskConnectorsTargetStates = new HashMap<>();
configStateSingleTaskConnectorsTargetStates.put(connectorId1, TargetState.STARTED);
configStateSingleTaskConnectorsTargetStates.put(connectorId2, TargetState.STARTED);
configStateSingleTaskConnectorsTargetStates.put(connectorId3, TargetState.STARTED);
Map<ConnectorTaskId, Map<String, String>> configStateSingleTaskConnectorsTaskConfigs = new HashMap<>();
configStateSingleTaskConnectorsTaskConfigs.put(taskId1x0, new HashMap<>());
configStateSingleTaskConnectorsTaskConfigs.put(taskId2x0, new HashMap<>());
configStateSingleTaskConnectorsTaskConfigs.put(taskId3x0, new HashMap<>());
configStateSingleTaskConnectors = new ClusterConfigState(2L, null, configStateSingleTaskConnectorsConnectorTaskCounts, configStateSingleTaskConnectorsConnectorConfigs, configStateSingleTaskConnectorsTargetStates, configStateSingleTaskConnectorsTaskConfigs, Collections.emptySet());
}
use of org.apache.kafka.connect.runtime.TargetState in project kafka by apache.
the class DistributedHerderTest method testDoRestartConnectorAndTasksOnlyConnector.
@Test
public void testDoRestartConnectorAndTasksOnlyConnector() {
ConnectorTaskId taskId = new ConnectorTaskId(CONN1, 0);
RestartRequest restartRequest = new RestartRequest(CONN1, false, true);
RestartPlan restartPlan = PowerMock.createMock(RestartPlan.class);
EasyMock.expect(restartPlan.shouldRestartConnector()).andReturn(true).anyTimes();
EasyMock.expect(restartPlan.shouldRestartTasks()).andReturn(true).anyTimes();
EasyMock.expect(restartPlan.taskIdsToRestart()).andReturn(Collections.singletonList(taskId)).anyTimes();
EasyMock.expect(herder.buildRestartPlan(restartRequest)).andReturn(Optional.of(restartPlan)).anyTimes();
herder.assignment = PowerMock.createMock(ExtendedAssignment.class);
EasyMock.expect(herder.assignment.connectors()).andReturn(Collections.singletonList(CONN1)).anyTimes();
EasyMock.expect(herder.assignment.tasks()).andReturn(Collections.emptyList()).anyTimes();
worker.stopAndAwaitConnector(CONN1);
PowerMock.expectLastCall();
Capture<Callback<TargetState>> stateCallback = newCapture();
worker.startConnector(EasyMock.eq(CONN1), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.eq(herder), EasyMock.anyObject(TargetState.class), capture(stateCallback));
herder.onRestart(CONN1);
EasyMock.expectLastCall();
PowerMock.replayAll();
herder.doRestartConnectorAndTasks(restartRequest);
PowerMock.verifyAll();
}
use of org.apache.kafka.connect.runtime.TargetState in project apache-kafka-on-k8s by banzaicloud.
the class DistributedHerder method processTargetStateChanges.
private void processTargetStateChanges(Set<String> connectorTargetStateChanges) {
for (String connector : connectorTargetStateChanges) {
TargetState targetState = configState.targetState(connector);
if (!configState.connectors().contains(connector)) {
log.debug("Received target state change for unknown connector: {}", connector);
continue;
}
// we must propagate the state change to the worker so that the connector's
// tasks can transition to the new target state
worker.setTargetState(connector, targetState);
// request reconfiguration to ensure that config changes while paused take effect
if (targetState == TargetState.STARTED)
reconfigureConnectorTasksWithRetry(connector);
}
}
use of org.apache.kafka.connect.runtime.TargetState in project apache-kafka-on-k8s by banzaicloud.
the class StandaloneHerder method restartTask.
@Override
public synchronized void restartTask(ConnectorTaskId taskId, Callback<Void> cb) {
if (!configState.contains(taskId.connector()))
cb.onCompletion(new NotFoundException("Connector " + taskId.connector() + " not found", null), null);
Map<String, String> taskConfigProps = configState.taskConfig(taskId);
if (taskConfigProps == null)
cb.onCompletion(new NotFoundException("Task " + taskId + " not found", null), null);
Map<String, String> connConfigProps = configState.connectorConfig(taskId.connector());
TargetState targetState = configState.targetState(taskId.connector());
worker.stopAndAwaitTask(taskId);
if (worker.startTask(taskId, connConfigProps, taskConfigProps, this, targetState))
cb.onCompletion(null, null);
else
cb.onCompletion(new ConnectException("Failed to start task: " + taskId), null);
}
Aggregations