use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.
the class AbstractHerder method connectorStatus.
@Override
public ConnectorStateInfo connectorStatus(String connName) {
ConnectorStatus connector = statusBackingStore.get(connName);
if (connector == null)
throw new NotFoundException("No status found for connector " + connName);
Collection<TaskStatus> tasks = statusBackingStore.getAll(connName);
ConnectorStateInfo.ConnectorState connectorState = new ConnectorStateInfo.ConnectorState(connector.state().toString(), connector.workerId(), connector.trace());
List<ConnectorStateInfo.TaskState> taskStates = new ArrayList<>();
for (TaskStatus status : tasks) {
taskStates.add(new ConnectorStateInfo.TaskState(status.id().task(), status.state().toString(), status.workerId(), status.trace()));
}
Collections.sort(taskStates);
Map<String, String> conf = rawConfig(connName);
return new ConnectorStateInfo(connName, connectorState, taskStates, conf == null ? ConnectorType.UNKNOWN : connectorTypeForClass(conf.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG)));
}
use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.
the class LoggingResource method getLogger.
/**
* Get the log level of a named logger.
*
* @param namedLogger name of a logger
* @return level of the logger, effective level if the level was not explicitly set.
*/
@GET
@Path("/{logger}")
public Response getLogger(@PathParam("logger") final String namedLogger) {
Objects.requireNonNull(namedLogger, "require non-null name");
Logger logger = null;
if (ROOT_LOGGER_NAME.equalsIgnoreCase(namedLogger)) {
logger = rootLogger();
} else {
Enumeration<Logger> en = currentLoggers();
// (potential leak since these don't get cleaned up).
while (en.hasMoreElements()) {
Logger l = en.nextElement();
if (namedLogger.equals(l.getName())) {
logger = l;
break;
}
}
}
if (logger == null) {
throw new NotFoundException("Logger " + namedLogger + " not found.");
} else {
return Response.ok(effectiveLevelToMap(logger)).build();
}
}
use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.
the class StandaloneHerder method restartConnectorAndTasks.
@Override
public synchronized void restartConnectorAndTasks(RestartRequest request, Callback<ConnectorStateInfo> cb) {
// Ensure the connector exists
String connectorName = request.connectorName();
if (!configState.contains(connectorName)) {
cb.onCompletion(new NotFoundException("Unknown connector: " + connectorName, null), null);
return;
}
Optional<RestartPlan> maybePlan = buildRestartPlan(request);
if (!maybePlan.isPresent()) {
cb.onCompletion(new NotFoundException("Status for connector " + connectorName + " not found", null), null);
return;
}
RestartPlan plan = maybePlan.get();
// If requested, stop the connector and any tasks, marking each as restarting
log.info("Received {}", plan);
if (plan.shouldRestartConnector()) {
worker.stopAndAwaitConnector(connectorName);
onRestart(connectorName);
}
if (plan.shouldRestartTasks()) {
// Stop the tasks and mark as restarting
worker.stopAndAwaitTasks(plan.taskIdsToRestart());
plan.taskIdsToRestart().forEach(this::onRestart);
}
// Now restart the connector and tasks
if (plan.shouldRestartConnector()) {
log.debug("Restarting connector '{}'", connectorName);
startConnector(connectorName, (error, targetState) -> {
if (error == null) {
log.info("Connector '{}' restart successful", connectorName);
} else {
log.error("Connector '{}' restart failed", connectorName, error);
}
});
}
if (plan.shouldRestartTasks()) {
log.debug("Restarting {} of {} tasks for {}", plan.restartTaskCount(), plan.totalTaskCount(), request);
createConnectorTasks(connectorName, plan.taskIdsToRestart());
log.debug("Restarted {} of {} tasks for {} as requested", plan.restartTaskCount(), plan.totalTaskCount(), request);
}
// Complete the restart request
log.info("Completed {}", plan);
cb.onCompletion(null, plan.restartConnectorStateInfo());
}
use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.
the class StandaloneHerder method taskConfigs.
@Override
public synchronized void taskConfigs(String connName, Callback<List<TaskInfo>> callback) {
if (!configState.contains(connName)) {
callback.onCompletion(new NotFoundException("Connector " + connName + " not found", null), null);
return;
}
List<TaskInfo> result = new ArrayList<>();
for (ConnectorTaskId taskId : configState.tasks(connName)) result.add(new TaskInfo(taskId, configState.rawTaskConfig(taskId)));
callback.onCompletion(null, result);
}
use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.
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, configState, connConfigProps, taskConfigProps, this, targetState))
cb.onCompletion(null, null);
else
cb.onCompletion(new ConnectException("Failed to start task: " + taskId), null);
}
Aggregations