Search in sources :

Example 1 with ConnectorStateInfo

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

the class AbstractHerderTest method connectorStatus.

@Test
public void connectorStatus() {
    Worker worker = null;
    String workerId = "workerId";
    String connector = "connector";
    int generation = 5;
    ConnectorTaskId taskId = new ConnectorTaskId(connector, 0);
    ConfigBackingStore configStore = strictMock(ConfigBackingStore.class);
    StatusBackingStore statusStore = strictMock(StatusBackingStore.class);
    AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, StatusBackingStore.class, ConfigBackingStore.class).withArgs(worker, workerId, statusStore, configStore).addMockedMethod("generation").createMock();
    EasyMock.expect(herder.generation()).andStubReturn(generation);
    EasyMock.expect(statusStore.get(connector)).andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
    EasyMock.expect(statusStore.getAll(connector)).andReturn(Collections.singletonList(new TaskStatus(taskId, AbstractStatus.State.UNASSIGNED, workerId, generation)));
    replayAll();
    ConnectorStateInfo state = herder.connectorStatus(connector);
    assertEquals(connector, state.name());
    assertEquals("RUNNING", state.connector().state());
    assertEquals(1, state.tasks().size());
    assertEquals(workerId, state.connector().workerId());
    ConnectorStateInfo.TaskState taskState = state.tasks().get(0);
    assertEquals(0, taskState.id());
    assertEquals("UNASSIGNED", taskState.state());
    assertEquals(workerId, taskState.workerId());
    verifyAll();
}
Also used : StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) Test(org.junit.Test)

Example 2 with ConnectorStateInfo

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

Aggregations

ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)2 ArrayList (java.util.ArrayList)1 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)1 ConfigBackingStore (org.apache.kafka.connect.storage.ConfigBackingStore)1 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)1 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)1 Test (org.junit.Test)1