use of org.apache.kafka.connect.runtime.TargetState in project kafka by apache.
the class StandaloneHerder method startConnector.
private boolean startConnector(Map<String, String> connectorProps) {
String connName = connectorProps.get(ConnectorConfig.NAME_CONFIG);
configBackingStore.putConnectorConfig(connName, connectorProps);
TargetState targetState = configState.targetState(connName);
return worker.startConnector(connName, connectorProps, new HerderConnectorContext(this, connName), this, targetState);
}
use of org.apache.kafka.connect.runtime.TargetState in project kafka by apache.
the class DistributedHerder method startConnector.
// Helper for starting a connector with the given name, which will extract & parse the config, generate connector
// context and add to the worker. This needs to be called from within the main worker thread for this herder.
private boolean startConnector(String connectorName) {
log.info("Starting connector {}", connectorName);
final Map<String, String> configProps = configState.connectorConfig(connectorName);
final ConnectorContext ctx = new HerderConnectorContext(this, connectorName);
final TargetState initialState = configState.targetState(connectorName);
boolean started = worker.startConnector(connectorName, configProps, ctx, this, initialState);
// just restoring an existing connector.
if (started && initialState == TargetState.STARTED)
reconfigureConnectorTasksWithRetry(connectorName);
return started;
}
use of org.apache.kafka.connect.runtime.TargetState in project apache-kafka-on-k8s by banzaicloud.
the class DistributedHerder method startConnector.
// Helper for starting a connector with the given name, which will extract & parse the config, generate connector
// context and add to the worker. This needs to be called from within the main worker thread for this herder.
private boolean startConnector(String connectorName) {
log.info("Starting connector {}", connectorName);
final Map<String, String> configProps = configState.connectorConfig(connectorName);
final ConnectorContext ctx = new HerderConnectorContext(this, connectorName);
final TargetState initialState = configState.targetState(connectorName);
boolean started = worker.startConnector(connectorName, configProps, ctx, this, initialState);
// just restoring an existing connector.
if (started && initialState == TargetState.STARTED)
reconfigureConnectorTasksWithRetry(connectorName);
return started;
}
use of org.apache.kafka.connect.runtime.TargetState in project apache-kafka-on-k8s by banzaicloud.
the class StandaloneHerder method startConnector.
private boolean startConnector(Map<String, String> connectorProps) {
String connName = connectorProps.get(ConnectorConfig.NAME_CONFIG);
configBackingStore.putConnectorConfig(connName, connectorProps);
TargetState targetState = configState.targetState(connName);
return worker.startConnector(connName, connectorProps, new HerderConnectorContext(this, connName), this, targetState);
}
use of org.apache.kafka.connect.runtime.TargetState in project kafka by apache.
the class DistributedHerder method doRestartConnectorAndTasks.
/**
* Builds and executes a restart plan for the connector and its tasks from <code>request</code>.
* Execution of a plan involves triggering the stop of eligible connector/tasks and then queuing the start for eligible connector/tasks.
*
* @param request the request to restart connector and tasks
*/
protected synchronized void doRestartConnectorAndTasks(RestartRequest request) {
String connectorName = request.connectorName();
Optional<RestartPlan> maybePlan = buildRestartPlan(request);
if (!maybePlan.isPresent()) {
log.debug("Skipping restart of connector '{}' since no status is available: {}", connectorName, request);
return;
}
RestartPlan plan = maybePlan.get();
log.info("Executing {}", plan);
// If requested, stop the connector and any tasks, marking each as restarting
final ExtendedAssignment currentAssignments = assignment;
final Collection<ConnectorTaskId> assignedIdsToRestart = plan.taskIdsToRestart().stream().filter(taskId -> currentAssignments.tasks().contains(taskId)).collect(Collectors.toList());
final boolean restartConnector = plan.shouldRestartConnector() && currentAssignments.connectors().contains(connectorName);
final boolean restartTasks = !assignedIdsToRestart.isEmpty();
if (restartConnector) {
worker.stopAndAwaitConnector(connectorName);
onRestart(connectorName);
}
if (restartTasks) {
// Stop the tasks and mark as restarting
worker.stopAndAwaitTasks(assignedIdsToRestart);
assignedIdsToRestart.forEach(this::onRestart);
}
// Now restart the connector and tasks
if (restartConnector) {
try {
startConnector(connectorName, (error, targetState) -> {
if (error == null) {
log.info("Connector '{}' restart successful", connectorName);
} else {
log.error("Connector '{}' restart failed", connectorName, error);
}
});
} catch (Throwable t) {
log.error("Connector '{}' restart failed", connectorName, t);
}
}
if (restartTasks) {
log.debug("Restarting {} of {} tasks for {}", plan.restartTaskCount(), plan.totalTaskCount(), request);
plan.taskIdsToRestart().forEach(taskId -> {
try {
if (startTask(taskId)) {
log.info("Task '{}' restart successful", taskId);
} else {
log.error("Task '{}' restart failed", taskId);
}
} catch (Throwable t) {
log.error("Task '{}' restart failed", taskId, t);
}
});
log.debug("Restarted {} of {} tasks for {} as requested", plan.restartTaskCount(), plan.totalTaskCount(), request);
}
log.info("Completed {}", plan);
}
Aggregations