Search in sources :

Example 1 with ListConnectors

use of io.confluent.ksql.parser.tree.ListConnectors in project ksql by confluentinc.

the class ListConnectorsExecutor method execute.

@SuppressWarnings("OptionalGetWithoutIsPresent")
public StatementExecutorResponse execute(final ConfiguredStatement<ListConnectors> configuredStatement, final SessionProperties sessionProperties, final KsqlExecutionContext ksqlExecutionContext, final ServiceContext serviceContext) {
    final ConnectClient connectClient = serviceContext.getConnectClient();
    final ConnectResponse<List<String>> connectors = serviceContext.getConnectClient().connectors();
    if (connectors.error().isPresent()) {
        return StatementExecutorResponse.handled(connectErrorHandler.handle(configuredStatement, connectors));
    }
    final List<SimpleConnectorInfo> infos = new ArrayList<>();
    final List<KsqlWarning> warnings = new ArrayList<>();
    final Scope scope = configuredStatement.getStatement().getScope();
    for (final String name : connectors.datum().get()) {
        final ConnectResponse<ConnectorInfo> response = connectClient.describe(name);
        if (response.datum().filter(i -> inScope(i.type(), scope)).isPresent()) {
            final ConnectResponse<ConnectorStateInfo> status = connectClient.status(name);
            infos.add(fromConnectorInfoResponse(name, response, status));
        } else if (response.error().isPresent()) {
            if (scope == Scope.ALL) {
                infos.add(new SimpleConnectorInfo(name, ConnectorType.UNKNOWN, null, null));
            }
            warnings.add(new KsqlWarning(String.format("Could not describe connector %s: %s", name, response.error().get())));
        }
    }
    return StatementExecutorResponse.handled(Optional.of(new ConnectorList(configuredStatement.getStatementText(), warnings, infos)));
}
Also used : SessionProperties(io.confluent.ksql.rest.SessionProperties) Scope(io.confluent.ksql.parser.tree.ListConnectors.Scope) ConnectClient(io.confluent.ksql.services.ConnectClient) ServiceContext(io.confluent.ksql.services.ServiceContext) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) ArrayList(java.util.ArrayList) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) State(org.apache.kafka.connect.runtime.AbstractStatus.State) ConnectResponse(io.confluent.ksql.services.ConnectClient.ConnectResponse) Optional(java.util.Optional) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) AbstractState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.AbstractState) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ArrayList(java.util.ArrayList) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) Scope(io.confluent.ksql.parser.tree.ListConnectors.Scope) ConnectClient(io.confluent.ksql.services.ConnectClient) ArrayList(java.util.ArrayList) List(java.util.List) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)

Example 2 with ListConnectors

use of io.confluent.ksql.parser.tree.ListConnectors in project ksql by confluentinc.

the class ListConnectorsExecutorTest method shouldLabelConnectorsWithNoRunningTasksAsWarning.

@Test
public void shouldLabelConnectorsWithNoRunningTasksAsWarning() {
    // Given:
    when(connectClient.status("connector")).thenReturn(ConnectResponse.success(STATUS_WARNING, HttpStatus.SC_OK));
    when(connectClient.connectors()).thenReturn(ConnectResponse.success(ImmutableList.of("connector"), HttpStatus.SC_OK));
    final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
    final ConfiguredStatement<ListConnectors> statement = ConfiguredStatement.of(PreparedStatement.of("", new ListConnectors(Optional.empty(), Scope.ALL)), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(statement, mock(SessionProperties.class), engine, serviceContext).getEntity();
    // Then:
    assertThat("expected response!", entity.isPresent());
    final ConnectorList connectorList = (ConnectorList) entity.get();
    assertThat(connectorList, is(new ConnectorList("", ImmutableList.of(), ImmutableList.of(new SimpleConnectorInfo("connector", ConnectorType.SOURCE, CONNECTOR_CLASS, "WARNING (0/2 tasks RUNNING)")))));
}
Also used : SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) KsqlConfig(io.confluent.ksql.util.KsqlConfig) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) Test(org.junit.Test)

Example 3 with ListConnectors

use of io.confluent.ksql.parser.tree.ListConnectors in project ksql by confluentinc.

the class ListConnectorsExecutorTest method shouldFilterNonMatchingConnectors.

@Test
public void shouldFilterNonMatchingConnectors() {
    // Given:
    when(connectClient.connectors()).thenReturn(ConnectResponse.success(ImmutableList.of("connector", "connector2"), HttpStatus.SC_OK));
    final ConfiguredStatement<ListConnectors> statement = ConfiguredStatement.of(PreparedStatement.of("", new ListConnectors(Optional.empty(), Scope.SINK)), SessionConfig.of(new KsqlConfig(ImmutableMap.of()), ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(statement, mock(SessionProperties.class), engine, serviceContext).getEntity();
    // Then:
    assertThat("expected response!", entity.isPresent());
    final ConnectorList connectorList = (ConnectorList) entity.get();
    assertThat(connectorList, is(new ConnectorList("", ImmutableList.of(), ImmutableList.of())));
}
Also used : KsqlConfig(io.confluent.ksql.util.KsqlConfig) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) Test(org.junit.Test)

Example 4 with ListConnectors

use of io.confluent.ksql.parser.tree.ListConnectors in project ksql by confluentinc.

the class ListConnectorsExecutorTest method shouldListValidConnector.

@Test
public void shouldListValidConnector() {
    // Given:
    when(connectClient.connectors()).thenReturn(ConnectResponse.success(ImmutableList.of("connector"), HttpStatus.SC_OK));
    final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
    final ConfiguredStatement<ListConnectors> statement = ConfiguredStatement.of(PreparedStatement.of("", new ListConnectors(Optional.empty(), Scope.ALL)), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(statement, mock(SessionProperties.class), engine, serviceContext).getEntity();
    // Then:
    assertThat("expected response!", entity.isPresent());
    final ConnectorList connectorList = (ConnectorList) entity.get();
    assertThat(connectorList, is(new ConnectorList("", ImmutableList.of(), ImmutableList.of(new SimpleConnectorInfo("connector", ConnectorType.SOURCE, CONNECTOR_CLASS, "RUNNING (1/2 tasks RUNNING)")))));
}
Also used : SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) KsqlConfig(io.confluent.ksql.util.KsqlConfig) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) Test(org.junit.Test)

Example 5 with ListConnectors

use of io.confluent.ksql.parser.tree.ListConnectors in project ksql by confluentinc.

the class ListConnectorsExecutorTest method shouldListInvalidConnectorWithNoInfo.

@Test
public void shouldListInvalidConnectorWithNoInfo() {
    // Given:
    when(connectClient.connectors()).thenReturn(ConnectResponse.success(ImmutableList.of("connector2"), HttpStatus.SC_OK));
    final ConfiguredStatement<ListConnectors> statement = ConfiguredStatement.of(PreparedStatement.of("", new ListConnectors(Optional.empty(), Scope.ALL)), SessionConfig.of(new KsqlConfig(ImmutableMap.of()), ImmutableMap.of()));
    // When:
    final Optional<KsqlEntity> entity = EXECUTOR.execute(statement, mock(SessionProperties.class), engine, serviceContext).getEntity();
    // Then:
    assertThat("expected response!", entity.isPresent());
    final ConnectorList connectorList = (ConnectorList) entity.get();
    assertThat(connectorList, is(new ConnectorList("", ImmutableList.of(new KsqlWarning("Could not describe connector connector2: DANGER WILL ROBINSON.")), ImmutableList.of(new SimpleConnectorInfo("connector2", ConnectorType.UNKNOWN, null, null)))));
}
Also used : SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) Test(org.junit.Test)

Aggregations

ListConnectors (io.confluent.ksql.parser.tree.ListConnectors)5 ConnectorList (io.confluent.ksql.rest.entity.ConnectorList)5 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 SimpleConnectorInfo (io.confluent.ksql.rest.entity.SimpleConnectorInfo)4 KsqlConfig (io.confluent.ksql.util.KsqlConfig)4 Test (org.junit.Test)4 KsqlWarning (io.confluent.ksql.rest.entity.KsqlWarning)2 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 Scope (io.confluent.ksql.parser.tree.ListConnectors.Scope)1 SessionProperties (io.confluent.ksql.rest.SessionProperties)1 ConnectClient (io.confluent.ksql.services.ConnectClient)1 ConnectResponse (io.confluent.ksql.services.ConnectClient.ConnectResponse)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 State (org.apache.kafka.connect.runtime.AbstractStatus.State)1 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)1 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)1