Search in sources :

Example 1 with TaskInfo

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

the class DistributedHerder method taskConfigs.

@Override
public void taskConfigs(final String connName, final Callback<List<TaskInfo>> callback) {
    log.trace("Submitting get task configuration request {}", connName);
    addRequest(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (checkRebalanceNeeded(callback))
                return null;
            if (!configState.contains(connName)) {
                callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), null);
            } else {
                List<TaskInfo> result = new ArrayList<>();
                for (int i = 0; i < configState.taskCount(connName); i++) {
                    ConnectorTaskId id = new ConnectorTaskId(connName, i);
                    result.add(new TaskInfo(id, configState.taskConfig(id)));
                }
                callback.onCompletion(null, result);
            }
            return null;
        }
    }, forwardErrorCallback(callback));
}
Also used : TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) WakeupException(org.apache.kafka.common.errors.WakeupException) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) NoSuchElementException(java.util.NoSuchElementException) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 2 with TaskInfo

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

the class DistributedHerderTest method testAccessors.

@Test
public void testAccessors() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.wakeup();
    PowerMock.expectLastCall().anyTimes();
    // list connectors, get connector info, get connector config, get task configs
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    FutureCallback<Collection<String>> listConnectorsCb = new FutureCallback<>();
    herder.connectors(listConnectorsCb);
    FutureCallback<ConnectorInfo> connectorInfoCb = new FutureCallback<>();
    herder.connectorInfo(CONN1, connectorInfoCb);
    FutureCallback<Map<String, String>> connectorConfigCb = new FutureCallback<>();
    herder.connectorConfig(CONN1, connectorConfigCb);
    FutureCallback<List<TaskInfo>> taskConfigsCb = new FutureCallback<>();
    herder.taskConfigs(CONN1, taskConfigsCb);
    herder.tick();
    assertTrue(listConnectorsCb.isDone());
    assertEquals(Collections.singleton(CONN1), listConnectorsCb.get());
    assertTrue(connectorInfoCb.isDone());
    ConnectorInfo info = new ConnectorInfo(CONN1, CONN1_CONFIG, Arrays.asList(TASK0, TASK1, TASK2));
    assertEquals(info, connectorInfoCb.get());
    assertTrue(connectorConfigCb.isDone());
    assertEquals(CONN1_CONFIG, connectorConfigCb.get());
    assertTrue(taskConfigsCb.isDone());
    assertEquals(Arrays.asList(new TaskInfo(TASK0, TASK_CONFIG), new TaskInfo(TASK1, TASK_CONFIG), new TaskInfo(TASK2, TASK_CONFIG)), taskConfigsCb.get());
    PowerMock.verifyAll();
}
Also used : TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Collection(java.util.Collection) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with TaskInfo

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

the class StandaloneHerderTest method testAccessors.

@Test
public void testAccessors() throws Exception {
    Map<String, String> connConfig = connectorConfig(SourceSink.SOURCE);
    Callback<Collection<String>> listConnectorsCb = PowerMock.createMock(Callback.class);
    Callback<ConnectorInfo> connectorInfoCb = PowerMock.createMock(Callback.class);
    Callback<Map<String, String>> connectorConfigCb = PowerMock.createMock(Callback.class);
    Callback<List<TaskInfo>> taskConfigsCb = PowerMock.createMock(Callback.class);
    // Check accessors with empty worker
    listConnectorsCb.onCompletion(null, Collections.EMPTY_SET);
    EasyMock.expectLastCall();
    connectorInfoCb.onCompletion(EasyMock.<NotFoundException>anyObject(), EasyMock.<ConnectorInfo>isNull());
    EasyMock.expectLastCall();
    connectorConfigCb.onCompletion(EasyMock.<NotFoundException>anyObject(), EasyMock.<Map<String, String>>isNull());
    EasyMock.expectLastCall();
    taskConfigsCb.onCompletion(EasyMock.<NotFoundException>anyObject(), EasyMock.<List<TaskInfo>>isNull());
    EasyMock.expectLastCall();
    // Create connector
    connector = PowerMock.createMock(BogusSourceConnector.class);
    expectAdd(SourceSink.SOURCE);
    expectConfigValidation(connConfig);
    // Validate accessors with 1 connector
    listConnectorsCb.onCompletion(null, singleton(CONNECTOR_NAME));
    EasyMock.expectLastCall();
    ConnectorInfo connInfo = new ConnectorInfo(CONNECTOR_NAME, connConfig, Arrays.asList(new ConnectorTaskId(CONNECTOR_NAME, 0)));
    connectorInfoCb.onCompletion(null, connInfo);
    EasyMock.expectLastCall();
    connectorConfigCb.onCompletion(null, connConfig);
    EasyMock.expectLastCall();
    TaskInfo taskInfo = new TaskInfo(new ConnectorTaskId(CONNECTOR_NAME, 0), taskConfig(SourceSink.SOURCE));
    taskConfigsCb.onCompletion(null, Arrays.asList(taskInfo));
    EasyMock.expectLastCall();
    PowerMock.replayAll();
    // All operations are synchronous for StandaloneHerder, so we don't need to actually wait after making each call
    herder.connectors(listConnectorsCb);
    herder.connectorInfo(CONNECTOR_NAME, connectorInfoCb);
    herder.connectorConfig(CONNECTOR_NAME, connectorConfigCb);
    herder.taskConfigs(CONNECTOR_NAME, taskConfigsCb);
    herder.putConnectorConfig(CONNECTOR_NAME, connConfig, false, createCallback);
    herder.connectors(listConnectorsCb);
    herder.connectorInfo(CONNECTOR_NAME, connectorInfoCb);
    herder.connectorConfig(CONNECTOR_NAME, connectorConfigCb);
    herder.taskConfigs(CONNECTOR_NAME, taskConfigsCb);
    PowerMock.verifyAll();
}
Also used : ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) Collection(java.util.Collection) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Example 4 with TaskInfo

use of org.apache.kafka.connect.runtime.rest.entities.TaskInfo 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 5 with TaskInfo

use of org.apache.kafka.connect.runtime.rest.entities.TaskInfo 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

TaskInfo (org.apache.kafka.connect.runtime.rest.entities.TaskInfo)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)3 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)3 Test (org.junit.Test)3 Collection (java.util.Collection)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Collections.singletonMap (java.util.Collections.singletonMap)1 NoSuchElementException (java.util.NoSuchElementException)1 TimeoutException (java.util.concurrent.TimeoutException)1 WakeupException (org.apache.kafka.common.errors.WakeupException)1 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)1 ConnectException (org.apache.kafka.connect.errors.ConnectException)1 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)1 Callback (org.apache.kafka.connect.util.Callback)1