use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class DefaultConnectClient method connectors.
@SuppressWarnings("unchecked")
@Override
public ConnectResponse<List<String>> connectors() {
try {
LOG.debug("Issuing request to Kafka Connect at URI {} to list connectors", connectUri);
final ConnectResponse<List<String>> connectResponse = withRetries(() -> Request.get(resolveUri(CONNECTORS)).setHeaders(requestHeaders).responseTimeout(Timeout.ofMilliseconds(requestTimeoutMs)).connectTimeout(Timeout.ofMilliseconds(requestTimeoutMs)).execute(httpClient).handleResponse(createHandler(HttpStatus.SC_OK, new TypeReference<List<String>>() {
}, Function.identity())));
connectResponse.error().ifPresent(error -> LOG.warn("Could not list connectors: {}.", error));
return connectResponse;
} catch (final Exception e) {
throw new KsqlServerException(e);
}
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class DefaultConnectClient method topics.
@Override
public ConnectResponse<Map<String, Map<String, List<String>>>> topics(final String connector) {
try {
LOG.debug("Issuing request to Kafka Connect at URI {} to get active topics for {}", connectUri, connector);
final ConnectResponse<Map<String, Map<String, List<String>>>> connectResponse = withRetries(() -> Request.get(resolveUri(CONNECTORS + "/" + connector + TOPICS)).setHeaders(requestHeaders).responseTimeout(Timeout.ofMilliseconds(requestTimeoutMs)).connectTimeout(Timeout.ofMilliseconds(requestTimeoutMs)).execute(httpClient).handleResponse(createHandler(HttpStatus.SC_OK, new TypeReference<Map<String, Map<String, List<String>>>>() {
}, Function.identity())));
connectResponse.error().ifPresent(error -> LOG.warn("Could not query topics of connector {}: {}", connector, error));
return connectResponse;
} catch (final Exception e) {
throw new KsqlServerException(e);
}
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class DefaultConnectClient method create.
@Override
public ConnectResponse<ConnectorInfo> create(final String connector, final Map<String, String> config) {
try {
LOG.debug("Issuing create request to Kafka Connect at URI {} with name {} and config {}", connectUri, connector, config);
final ConnectResponse<ConnectorInfo> connectResponse = withRetries(() -> Request.post(resolveUri(CONNECTORS)).setHeaders(requestHeaders).responseTimeout(Timeout.ofMilliseconds(requestTimeoutMs)).connectTimeout(Timeout.ofMilliseconds(requestTimeoutMs)).bodyString(MAPPER.writeValueAsString(ImmutableMap.of("name", connector, "config", config)), ContentType.APPLICATION_JSON).execute(httpClient).handleResponse(createHandler(HttpStatus.SC_CREATED, new TypeReference<ConnectorInfo>() {
}, Function.identity())));
connectResponse.error().ifPresent(error -> LOG.warn("Did not CREATE connector {}: {}", connector, error));
return connectResponse;
} catch (final Exception e) {
throw new KsqlServerException(e);
}
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class RestTestExecutor method compareKeyValueTimestamp.
private static void compareKeyValueTimestamp(final ConsumerRecord<?, ?> actual, final Record expected) {
final long actualTimestamp = actual.timestamp();
final Object actualKey = actual.key();
final Object actualValue = actual.value();
final Object expectedKey = coerceExpectedKey(expected.key(), actualKey);
final JsonNode expectedValue = expected.getJsonValue().orElseThrow(() -> new KsqlServerException("could not get expected value from test record: " + expected));
final long expectedTimestamp = expected.timestamp().orElse(actualTimestamp);
final AssertionError error = new AssertionError("Expected <" + expectedKey + ", " + expectedValue + "> " + "with timestamp=" + expectedTimestamp + " but was <" + actualKey + ", " + actualValue + "> " + "with timestamp=" + actualTimestamp);
if (!Objects.equals(actualKey, expectedKey)) {
throw error;
}
if (!ExpectedRecordComparator.matches(actualValue, expectedValue)) {
throw error;
}
if (actualTimestamp != expectedTimestamp) {
throw error;
}
}
use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class KsqlEngine method getStartOffsetsForStreamPullQuery.
private ImmutableMap<TopicPartition, Long> getStartOffsetsForStreamPullQuery(final Admin admin, final TopicDescription topicDescription) {
final Map<TopicPartition, OffsetSpec> topicPartitions = topicDescription.partitions().stream().map(td -> new TopicPartition(topicDescription.name(), td.partition())).collect(toMap(identity(), tp -> OffsetSpec.earliest()));
final ListOffsetsResult listOffsetsResult = admin.listOffsets(topicPartitions, // so we should do the same when checking end offsets.
new ListOffsetsOptions(IsolationLevel.READ_UNCOMMITTED));
try {
final Map<TopicPartition, ListOffsetsResult.ListOffsetsResultInfo> partitionResultMap = listOffsetsResult.all().get(10, TimeUnit.SECONDS);
final Map<TopicPartition, Long> result = partitionResultMap.entrySet().stream().collect(toMap(Entry::getKey, e -> e.getValue().offset()));
return ImmutableMap.copyOf(result);
} catch (final InterruptedException e) {
log.error("Admin#listOffsets(" + topicDescription.name() + ") interrupted", e);
throw new KsqlServerException("Interrupted");
} catch (final ExecutionException e) {
log.error("Error executing Admin#listOffsets(" + topicDescription.name() + ")", e);
throw new KsqlServerException("Internal Server Error");
} catch (final TimeoutException e) {
log.error("Admin#listOffsets(" + topicDescription.name() + ") timed out", e);
throw new KsqlServerException("Backend timed out");
}
}
Aggregations