Search in sources :

Example 11 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.taskConfig(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 12 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);
    return new ConnectorStateInfo(connName, connectorState, taskStates);
}
Also used : ArrayList(java.util.ArrayList) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)

Example 13 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class StandaloneHerderTest method testDestroyConnector.

@Test
public void testDestroyConnector() throws Exception {
    connector = PowerMock.createMock(BogusSourceConnector.class);
    expectAdd(SourceSink.SOURCE);
    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    expectConfigValidation(config);
    EasyMock.expect(statusBackingStore.getAll(CONNECTOR_NAME)).andReturn(Collections.<TaskStatus>emptyList());
    statusBackingStore.put(new ConnectorStatus(CONNECTOR_NAME, AbstractStatus.State.DESTROYED, WORKER_ID, 0));
    expectDestroy();
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    FutureCallback<Herder.Created<ConnectorInfo>> futureCb = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, futureCb);
    futureCb.get(1000L, TimeUnit.MILLISECONDS);
    // Second deletion should fail since the connector is gone
    futureCb = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, futureCb);
    try {
        futureCb.get(1000L, TimeUnit.MILLISECONDS);
        fail("Should have thrown NotFoundException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotFoundException);
    }
    PowerMock.verifyAll();
}
Also used : ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Test(org.junit.Test)

Example 14 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class ConnectorsResourceTest method testRestartConnectorNotFound.

@Test(expected = NotFoundException.class)
public void testRestartConnectorNotFound() throws Throwable {
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    connectorsResource.restartConnector(CONNECTOR_NAME, FORWARD);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class ConnectorsResourceTest method testGetConnectorTaskConfigsConnectorNotFound.

@Test(expected = NotFoundException.class)
public void testGetConnectorTaskConfigsConnectorNotFound() throws Throwable {
    final Capture<Callback<List<TaskInfo>>> cb = Capture.newInstance();
    herder.taskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("connector not found"));
    PowerMock.replayAll();
    connectorsResource.getTaskConfigs(CONNECTOR_NAME, FORWARD);
    PowerMock.verifyAll();
}
Also used : TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) Callback(org.apache.kafka.connect.util.Callback) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

NotFoundException (org.apache.kafka.connect.errors.NotFoundException)16 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Callback (org.apache.kafka.connect.util.Callback)6 ConnectException (org.apache.kafka.connect.errors.ConnectException)5 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)4 ArrayList (java.util.ArrayList)3 NoSuchElementException (java.util.NoSuchElementException)3 TimeoutException (java.util.concurrent.TimeoutException)3 WakeupException (org.apache.kafka.common.errors.WakeupException)3 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)3 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)3 TaskInfo (org.apache.kafka.connect.runtime.rest.entities.TaskInfo)3 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)3 ExecutionException (java.util.concurrent.ExecutionException)2 FutureCallback (org.apache.kafka.connect.util.FutureCallback)2 List (java.util.List)1 ConnectorStatus (org.apache.kafka.connect.runtime.ConnectorStatus)1 Herder (org.apache.kafka.connect.runtime.Herder)1 TargetState (org.apache.kafka.connect.runtime.TargetState)1