use of io.confluent.ksql.rest.entity.SimpleConnectorInfo in project ksql by confluentinc.
the class ClientTest method shouldListConnectors.
@Test
public void shouldListConnectors() throws Exception {
// Given:
final ConnectorList entity = new ConnectorList("list connectors;", Collections.emptyList(), Collections.singletonList(new SimpleConnectorInfo("name", SOURCE_TYPE, "class", "state")));
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When:
final List<io.confluent.ksql.api.client.ConnectorInfo> connectors = javaClient.listConnectors().get();
// Then:
assertThat(connectors.size(), is(1));
assertThat(connectors.get(0).state(), is("state"));
assertThat(connectors.get(0).name(), is("name"));
assertThat(connectors.get(0).type(), is(new ConnectorTypeImpl("SOURCE")));
}
use of io.confluent.ksql.rest.entity.SimpleConnectorInfo 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)));
}
use of io.confluent.ksql.rest.entity.SimpleConnectorInfo in project ksql by confluentinc.
the class ConsoleTest method shouldPrintConnectorsList.
@Test
public void shouldPrintConnectorsList() {
// Given:
final KsqlEntityList entities = new KsqlEntityList(ImmutableList.of(new ConnectorList("statement", ImmutableList.of(), ImmutableList.of(new SimpleConnectorInfo("foo", ConnectorType.SOURCE, "clazz", "STATUS"), new SimpleConnectorInfo("bar", null, null, null)))));
// When:
console.printKsqlEntityList(entities);
// Then:
final String output = terminal.getOutputString();
Approvals.verify(output, approvalOptions);
}
use of io.confluent.ksql.rest.entity.SimpleConnectorInfo 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)")))));
}
use of io.confluent.ksql.rest.entity.SimpleConnectorInfo 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)")))));
}
Aggregations