Search in sources :

Example 1 with ConnectorPluginsList

use of io.confluent.ksql.rest.entity.ConnectorPluginsList in project ksql by confluentinc.

the class ListConnectorPluginsExecutor method execute.

@SuppressWarnings("OptionalGetWithoutIsPresent")
public StatementExecutorResponse execute(final ConfiguredStatement<ListConnectorPlugins> configuredStatement, final SessionProperties sessionProperties, final KsqlExecutionContext ksqlExecutionContext, final ServiceContext serviceContext) {
    final ConnectResponse<List<ConnectorPluginInfo>> plugins = serviceContext.getConnectClient().connectorPlugins();
    if (plugins.error().isPresent()) {
        return StatementExecutorResponse.handled(connectErrorHandler.handle(configuredStatement, plugins));
    }
    final List<SimpleConnectorPluginInfo> pluginInfos = new ArrayList<>();
    for (final ConnectorPluginInfo info : plugins.datum().get()) {
        pluginInfos.add(new SimpleConnectorPluginInfo(info.className(), info.type(), info.version()));
    }
    return StatementExecutorResponse.handled(Optional.of(new ConnectorPluginsList(configuredStatement.getStatementText(), Collections.emptyList(), pluginInfos)));
}
Also used : SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) ArrayList(java.util.ArrayList) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) ConnectorPluginInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorPluginInfo)

Example 2 with ConnectorPluginsList

use of io.confluent.ksql.rest.entity.ConnectorPluginsList in project ksql by confluentinc.

the class ListConnectorPluginsTest method shouldListValidConnectorPlugins.

@Test
public void shouldListValidConnectorPlugins() {
    // Given:
    when(connectClient.connectorPlugins()).thenReturn(ConnectClient.ConnectResponse.success(ImmutableList.of(INFO), HttpStatus.SC_OK));
    final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
    final ConfiguredStatement<ListConnectorPlugins> statement = ConfiguredStatement.of(KsqlParser.PreparedStatement.of("", new ListConnectorPlugins(Optional.empty())), 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 ConnectorPluginsList connectorPluginsList = (ConnectorPluginsList) entity.get();
    assertThat(connectorPluginsList, is(new ConnectorPluginsList("", ImmutableList.of(), ImmutableList.of(new SimpleConnectorPluginInfo("org.apache.kafka.connect.file.FileStreamSinkConnector", ConnectorType.SOURCE, "2.1")))));
}
Also used : SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) KsqlConfig(io.confluent.ksql.util.KsqlConfig) ListConnectorPlugins(io.confluent.ksql.parser.tree.ListConnectorPlugins) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Example 3 with ConnectorPluginsList

use of io.confluent.ksql.rest.entity.ConnectorPluginsList in project ksql by confluentinc.

the class ConsoleTest method shouldPrintConnectorPluginsList.

@Test
public void shouldPrintConnectorPluginsList() {
    // Given:
    final KsqlEntityList entities = new KsqlEntityList(ImmutableList.of(new ConnectorPluginsList("statement", ImmutableList.of(), ImmutableList.of(new SimpleConnectorPluginInfo("clazz1", ConnectorType.SOURCE, "v1"), new SimpleConnectorPluginInfo("clazz2", ConnectorType.SINK, "v2")))));
    // When:
    console.printKsqlEntityList(entities);
    // Then:
    final String output = terminal.getOutputString();
    if (console.getOutputFormat() == OutputFormat.JSON) {
        assertThat(output, is("" + "[ {" + NEWLINE + "  \"@type\" : \"connector_plugins_list\"," + NEWLINE + "  \"statementText\" : \"statement\"," + NEWLINE + "  \"warnings\" : [ ]," + NEWLINE + "  \"connectorsPlugins\" : [ {" + NEWLINE + "    \"className\" : \"clazz1\"," + NEWLINE + "    \"type\" : \"source\"," + NEWLINE + "    \"version\" : \"v1\"" + NEWLINE + "  }, {" + NEWLINE + "    \"className\" : \"clazz2\"," + NEWLINE + "    \"type\" : \"sink\"," + NEWLINE + "    \"version\" : \"v2\"" + NEWLINE + "  } ]" + NEWLINE + "} ]" + NEWLINE));
    } else {
        assertThat(output, is("" + NEWLINE + " Class  | Type   | Version " + NEWLINE + "---------------------------" + NEWLINE + " clazz1 | SOURCE | v1      " + NEWLINE + " clazz2 | SINK   | v2      " + NEWLINE + "---------------------------" + NEWLINE));
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

ConnectorPluginsList (io.confluent.ksql.rest.entity.ConnectorPluginsList)3 SimpleConnectorPluginInfo (io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo)3 Test (org.junit.Test)2 ListConnectorPlugins (io.confluent.ksql.parser.tree.ListConnectorPlugins)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConnectorPluginInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorPluginInfo)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1