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));
}
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();
}
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();
}
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);
}
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();
}
Aggregations