Search in sources :

Example 41 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project kafka by apache.

the class StandaloneHerderTest method testRestartConnectorAndTasksNoStatus.

@Test
public void testRestartConnectorAndTasksNoStatus() throws Exception {
    RestartRequest restartRequest = new RestartRequest(CONNECTOR_NAME, false, true);
    EasyMock.expect(herder.buildRestartPlan(restartRequest)).andReturn(Optional.empty()).anyTimes();
    connector = PowerMock.createMock(BogusSinkConnector.class);
    expectAdd(SourceSink.SINK);
    Map<String, String> connectorConfig = connectorConfig(SourceSink.SINK);
    Connector connectorMock = PowerMock.createMock(SinkConnector.class);
    expectConfigValidation(connectorMock, true, connectorConfig);
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, connectorConfig, false, createCallback);
    Herder.Created<ConnectorInfo> connectorInfo = createCallback.get(1000L, TimeUnit.SECONDS);
    assertEquals(createdInfo(SourceSink.SINK), connectorInfo.result());
    FutureCallback<ConnectorStateInfo> restartCallback = new FutureCallback<>();
    herder.restartConnectorAndTasks(restartRequest, restartCallback);
    ExecutionException ee = assertThrows(ExecutionException.class, () -> restartCallback.get(1000L, TimeUnit.MILLISECONDS));
    assertTrue(ee.getCause() instanceof NotFoundException);
    assertTrue(ee.getMessage().contains("Status for connector"));
    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) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) Herder(org.apache.kafka.connect.runtime.Herder) 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 42 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project kafka by apache.

the class DistributedHerderTest method testPutConnectorConfig.

@Test
public void testPutConnectorConfig() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(1, Arrays.asList(CONN1), Collections.emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    Capture<Callback<TargetState>> onFirstStart = newCapture();
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED), capture(onFirstStart));
    PowerMock.expectLastCall().andAnswer(() -> {
        onFirstStart.getValue().onCompletion(null, TargetState.STARTED);
        return true;
    });
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);
    EasyMock.expect(worker.connectorTaskConfigs(CONN1, conn1SinkConfig)).andReturn(TASK_CONFIGS);
    // list connectors, get connector info, get connector config, get task configs
    member.wakeup();
    PowerMock.expectLastCall().anyTimes();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // Poll loop for second round of calls
    member.ensureActive();
    PowerMock.expectLastCall();
    EasyMock.expect(worker.getPlugins()).andReturn(plugins).anyTimes();
    EasyMock.expect(configBackingStore.snapshot()).andReturn(SNAPSHOT);
    Capture<Callback<ConfigInfos>> validateCallback = newCapture();
    herder.validateConnectorConfig(EasyMock.eq(CONN1_CONFIG_UPDATED), capture(validateCallback));
    PowerMock.expectLastCall().andAnswer(() -> {
        validateCallback.getValue().onCompletion(null, CONN1_CONFIG_INFOS);
        return null;
    });
    configBackingStore.putConnectorConfig(CONN1, CONN1_CONFIG_UPDATED);
    PowerMock.expectLastCall().andAnswer(() -> {
        // Simulate response to writing config + waiting until end of log to be read
        configUpdateListener.onConnectorConfigUpdate(CONN1);
        return null;
    });
    // As a result of reconfig, should need to update snapshot. With only connector updates, we'll just restart
    // connector without rebalance
    EasyMock.expect(configBackingStore.snapshot()).andReturn(SNAPSHOT_UPDATED_CONN1_CONFIG).times(2);
    worker.stopAndAwaitConnector(CONN1);
    PowerMock.expectLastCall();
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    Capture<Callback<TargetState>> onSecondStart = newCapture();
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED), capture(onSecondStart));
    PowerMock.expectLastCall().andAnswer(() -> {
        onSecondStart.getValue().onCompletion(null, TargetState.STARTED);
        return true;
    });
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);
    EasyMock.expect(worker.connectorTaskConfigs(CONN1, conn1SinkConfigUpdated)).andReturn(TASK_CONFIGS);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // Third tick just to read the config
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    // Should pick up original config
    FutureCallback<Map<String, String>> connectorConfigCb = new FutureCallback<>();
    herder.connectorConfig(CONN1, connectorConfigCb);
    herder.tick();
    assertTrue(connectorConfigCb.isDone());
    assertEquals(CONN1_CONFIG, connectorConfigCb.get());
    // Apply new config.
    FutureCallback<Herder.Created<ConnectorInfo>> putConfigCb = new FutureCallback<>();
    herder.putConnectorConfig(CONN1, CONN1_CONFIG_UPDATED, true, putConfigCb);
    herder.tick();
    assertTrue(putConfigCb.isDone());
    ConnectorInfo updatedInfo = new ConnectorInfo(CONN1, CONN1_CONFIG_UPDATED, Arrays.asList(TASK0, TASK1, TASK2), ConnectorType.SOURCE);
    assertEquals(new Herder.Created<>(false, updatedInfo), putConfigCb.get());
    // Check config again to validate change
    connectorConfigCb = new FutureCallback<>();
    herder.connectorConfig(CONN1, connectorConfigCb);
    herder.tick();
    assertTrue(connectorConfigCb.isDone());
    assertEquals(CONN1_CONFIG_UPDATED, connectorConfigCb.get());
    PowerMock.verifyAll();
}
Also used : FutureCallback(org.apache.kafka.connect.util.FutureCallback) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Map(java.util.Map) HashMap(java.util.HashMap) 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 43 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project kafka by apache.

the class ConnectorsResourceTest method testDeleteConnectorNotFound.

// Not found exceptions should pass through to caller so they can be processed for 404s
@Test
public void testDeleteConnectorNotFound() {
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.deleteConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    assertThrows(NotFoundException.class, () -> connectorsResource.destroyConnector(CONNECTOR_NAME, NULL_HEADERS, FORWARD));
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project kafka by apache.

the class ConnectorsResourceTest method testCreateConnectorWithHeaderAuthorization.

@Test
public void testCreateConnectorWithHeaderAuthorization() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    HttpHeaders httpHeaders = EasyMock.mock(HttpHeaders.class);
    EasyMock.expect(httpHeaders.getHeaderString("Authorization")).andReturn("Basic YWxhZGRpbjpvcGVuc2VzYW1l").times(1);
    EasyMock.replay(httpHeaders);
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, httpHeaders, body);
    PowerMock.verifyAll();
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project kafka by apache.

the class ConnectorsResourceTest method testCreateConnectorWithoutHeaderAuthorization.

@Test
public void testCreateConnectorWithoutHeaderAuthorization() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    HttpHeaders httpHeaders = EasyMock.mock(HttpHeaders.class);
    EasyMock.expect(httpHeaders.getHeaderString("Authorization")).andReturn(null).times(1);
    EasyMock.replay(httpHeaders);
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, httpHeaders, body);
    PowerMock.verifyAll();
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)78 Herder (org.apache.kafka.connect.runtime.Herder)65 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)61 Callback (org.apache.kafka.connect.util.Callback)35 Connector (org.apache.kafka.connect.connector.Connector)28 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)28 SourceConnector (org.apache.kafka.connect.source.SourceConnector)28 FutureCallback (org.apache.kafka.connect.util.FutureCallback)25 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)20 CreateConnectorRequest (org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest)19 HashMap (java.util.HashMap)17 URI (java.net.URI)13 Map (java.util.Map)13 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)11 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)11 Config (org.apache.kafka.common.config.Config)10 ConfigDef (org.apache.kafka.common.config.ConfigDef)10 ConfigValue (org.apache.kafka.common.config.ConfigValue)10 TaskConfig (org.apache.kafka.connect.runtime.TaskConfig)10