Search in sources :

Example 41 with NotFoundException

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

the class StandaloneHerder method deleteConnectorConfig.

@Override
public synchronized void deleteConnectorConfig(String connName, Callback<Created<ConnectorInfo>> callback) {
    try {
        if (!configState.contains(connName)) {
            // Deletion, must already exist
            callback.onCompletion(new NotFoundException("Connector " + connName + " not found", null), null);
            return;
        }
        removeConnectorTasks(connName);
        worker.stopAndAwaitConnector(connName);
        configBackingStore.removeConnectorConfig(connName);
        onDeletion(connName);
        callback.onCompletion(null, new Created<>(false, null));
    } catch (ConnectException e) {
        callback.onCompletion(e, null);
    }
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 42 with NotFoundException

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

the class DistributedHerderTest method testRestartConnectorAndTasksUnknownConnector.

@Test
public void testRestartConnectorAndTasksUnknownConnector() throws Exception {
    String connectorName = "UnknownConnector";
    RestartRequest restartRequest = new RestartRequest(connectorName, false, true);
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    expectRebalance(1, Collections.emptyList(), Collections.emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // now handle the connector restart
    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    herder.tick();
    FutureCallback<ConnectorStateInfo> callback = new FutureCallback<>();
    herder.restartConnectorAndTasks(restartRequest, callback);
    herder.tick();
    ExecutionException ee = assertThrows(ExecutionException.class, () -> callback.get(1000L, TimeUnit.MILLISECONDS));
    assertTrue(ee.getCause() instanceof NotFoundException);
    assertTrue(ee.getMessage().contains("Unknown connector:"));
    PowerMock.verifyAll();
}
Also used : RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with NotFoundException

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

the class StandaloneHerderTest method testRestartConnectorAndTasksUnknownConnector.

@Test
public void testRestartConnectorAndTasksUnknownConnector() {
    PowerMock.replayAll();
    FutureCallback<ConnectorStateInfo> restartCallback = new FutureCallback<>();
    RestartRequest restartRequest = new RestartRequest("UnknownConnector", false, true);
    herder.restartConnectorAndTasks(restartRequest, restartCallback);
    ExecutionException ee = assertThrows(ExecutionException.class, () -> restartCallback.get(1000L, TimeUnit.MILLISECONDS));
    assertTrue(ee.getCause() instanceof NotFoundException);
    PowerMock.verifyAll();
}
Also used : RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 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);
    Connector connectorMock = PowerMock.createMock(SourceConnector.class);
    expectConfigValidation(connectorMock, true, config);
    EasyMock.expect(statusBackingStore.getAll(CONNECTOR_NAME)).andReturn(Collections.emptyList());
    statusBackingStore.put(new ConnectorStatus(CONNECTOR_NAME, AbstractStatus.State.DESTROYED, WORKER_ID, 0));
    statusBackingStore.put(new TaskStatus(new ConnectorTaskId(CONNECTOR_NAME, 0), TaskStatus.State.DESTROYED, WORKER_ID, 0));
    expectDestroy();
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    Herder.Created<ConnectorInfo> connectorInfo = createCallback.get(1000L, TimeUnit.SECONDS);
    assertEquals(createdInfo(SourceSink.SOURCE), connectorInfo.result());
    FutureCallback<Herder.Created<ConnectorInfo>> deleteCallback = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, deleteCallback);
    deleteCallback.get(1000L, TimeUnit.MILLISECONDS);
    // Second deletion should fail since the connector is gone
    FutureCallback<Herder.Created<ConnectorInfo>> failedDeleteCallback = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, failedDeleteCallback);
    try {
        failedDeleteCallback.get(1000L, TimeUnit.MILLISECONDS);
        fail("Should have thrown NotFoundException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotFoundException);
    }
    PowerMock.verifyAll();
}
Also used : SourceConnector(org.apache.kafka.connect.source.SourceConnector) WorkerConnector(org.apache.kafka.connect.runtime.WorkerConnector) Connector(org.apache.kafka.connect.connector.Connector) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) TaskStatus(org.apache.kafka.connect.runtime.TaskStatus) ExecutionException(java.util.concurrent.ExecutionException) Herder(org.apache.kafka.connect.runtime.Herder) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with NotFoundException

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

the class ConnectorsResourceTest method testRestartConnectorAndTasksConnectorNotFound.

@Test
public void testRestartConnectorAndTasksConnectorNotFound() {
    RestartRequest restartRequest = new RestartRequest(CONNECTOR_NAME, true, false);
    final Capture<Callback<ConnectorStateInfo>> cb = Capture.newInstance();
    herder.restartConnectorAndTasks(EasyMock.eq(restartRequest), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    assertThrows(NotFoundException.class, () -> connectorsResource.restartConnector(CONNECTOR_NAME, NULL_HEADERS, restartRequest.includeTasks(), restartRequest.onlyFailed(), FORWARD));
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) 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)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