Search in sources :

Example 36 with NotFoundException

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)));
}
Also used : ArrayList(java.util.ArrayList) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)

Example 37 with NotFoundException

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();
    }
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException) Logger(org.apache.log4j.Logger) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 38 with NotFoundException

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());
}
Also used : RestartPlan(org.apache.kafka.connect.runtime.RestartPlan) NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Example 39 with NotFoundException

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);
}
Also used : TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ArrayList(java.util.ArrayList) NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Example 40 with NotFoundException

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);
}
Also used : TargetState(org.apache.kafka.connect.runtime.TargetState) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

NotFoundException (org.apache.kafka.connect.errors.NotFoundException)48 Test (org.junit.Test)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 Callback (org.apache.kafka.connect.util.Callback)14 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)11 ConnectException (org.apache.kafka.connect.errors.ConnectException)9 ExecutionException (java.util.concurrent.ExecutionException)8 FutureCallback (org.apache.kafka.connect.util.FutureCallback)8 ArrayList (java.util.ArrayList)7 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)7 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)6 TaskInfo (org.apache.kafka.connect.runtime.rest.entities.TaskInfo)6 NoSuchElementException (java.util.NoSuchElementException)5 TimeoutException (java.util.concurrent.TimeoutException)5 WakeupException (org.apache.kafka.common.errors.WakeupException)5 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)5 RestartRequest (org.apache.kafka.connect.runtime.RestartRequest)5 Herder (org.apache.kafka.connect.runtime.Herder)4 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)4 Connector (org.apache.kafka.connect.connector.Connector)3