use of org.apache.kafka.streams.state.HostInfo in project ksql by confluentinc.
the class KsLocatorTest method shouldReturnRemoteOwnerForDifferentPort.
@Test
public void shouldReturnRemoteOwnerForDifferentPort() {
// Given:
final HostInfo localHostInfo = new HostInfo(LOCAL_HOST_URL.getHost(), LOCAL_HOST_URL.getPort() + 1);
final KsqlHostInfo localHost = locator.asKsqlHost(localHostInfo);
getActiveAndStandbyMetadata(localHostInfo);
when(activeFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
when(livenessFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
// When:
final List<KsqlPartitionLocation> result = locator.locate(ImmutableList.of(KEY), routingOptions, routingFilterFactoryActive, false);
// Then:
List<KsqlNode> nodeList = result.get(0).getNodes();
assertThat(nodeList.stream().findFirst().map(KsqlNode::isLocal), is(Optional.of(false)));
}
use of org.apache.kafka.streams.state.HostInfo in project ksql by confluentinc.
the class KsLocatorTest method shouldReturnLocalOwnerIfExplicitlyLocalHostOnSamePortAsSuppliedLocalHost.
@Test
public void shouldReturnLocalOwnerIfExplicitlyLocalHostOnSamePortAsSuppliedLocalHost() {
// Given:
final HostInfo localHostInfo = new HostInfo("LocalHOST", LOCAL_HOST_URL.getPort());
final KsqlHostInfo localHost = locator.asKsqlHost(localHostInfo);
getActiveAndStandbyMetadata(localHostInfo);
when(activeFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
when(livenessFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
// When:
final List<KsqlPartitionLocation> result = locator.locate(ImmutableList.of(KEY), routingOptions, routingFilterFactoryActive, false);
// Then:
List<KsqlNode> nodeList = result.get(0).getNodes();
assertThat(nodeList.stream().findFirst().map(KsqlNode::isLocal), is(Optional.of(true)));
}
use of org.apache.kafka.streams.state.HostInfo in project ksql by confluentinc.
the class AllHostsLocatorTest method shouldLocate.
@Test
public void shouldLocate() throws MalformedURLException {
// Given:
final AllHostsLocator locator = new AllHostsLocator(() -> ImmutableList.of(metadata1, metadata2), new URL("http://localhost:8088"));
when(metadata1.getAllStreamsHostMetadata()).thenReturn(ImmutableList.of(streamsMetadata1, streamsMetadata2));
when(metadata2.getAllStreamsHostMetadata()).thenReturn(ImmutableList.of(streamsMetadata3));
when(streamsMetadata1.hostInfo()).thenReturn(new HostInfo("abc", 101), new HostInfo("localhost", 8088));
when(streamsMetadata2.hostInfo()).thenReturn(new HostInfo("localhost", 8088));
when(streamsMetadata3.hostInfo()).thenReturn(new HostInfo("localhost", 8089));
// When:
final List<KsqlNode> nodes = ImmutableList.copyOf(locator.locate());
// Then:
assertThat(nodes.size(), is(3));
assertThat(nodes.get(0).isLocal(), is(false));
assertThat(nodes.get(0).location().toString(), is("http://abc:101/"));
assertThat(nodes.get(1).isLocal(), is(true));
assertThat(nodes.get(1).location().toString(), is("http://localhost:8088/"));
assertThat(nodes.get(2).isLocal(), is(false));
assertThat(nodes.get(2).location().toString(), is("http://localhost:8089/"));
}
use of org.apache.kafka.streams.state.HostInfo in project ksql by confluentinc.
the class ListQueriesExecutor method mergeSimple.
private static Map<QueryId, RunningQuery> mergeSimple(final Map<QueryId, RunningQuery> allResults, final Pair<Map<HostInfo, KsqlEntity>, Set<HostInfo>> remoteResults) {
final List<RunningQuery> remoteRunningQueries = remoteResults.getLeft().values().stream().map(Queries.class::cast).map(Queries::getQueries).flatMap(List::stream).collect(Collectors.toList());
for (RunningQuery q : remoteRunningQueries) {
final QueryId queryId = q.getId();
// If the query has already been discovered, update the QueryStatusCount object
if (allResults.containsKey(queryId)) {
for (Map.Entry<KsqlQueryStatus, Integer> entry : q.getStatusCount().getStatuses().entrySet()) {
allResults.get(queryId).getStatusCount().updateStatusCount(entry.getKey(), entry.getValue());
}
} else {
allResults.put(queryId, q);
}
}
final Set<HostInfo> unresponsiveRemoteHosts = remoteResults.getRight();
if (!unresponsiveRemoteHosts.isEmpty()) {
for (RunningQuery runningQuery : allResults.values()) {
runningQuery.getStatusCount().updateStatusCount(KsqlQueryStatus.UNRESPONSIVE, unresponsiveRemoteHosts.size());
}
}
return allResults;
}
use of org.apache.kafka.streams.state.HostInfo in project ksql by confluentinc.
the class ListQueriesExecutor method mergeExtended.
private static Map<QueryId, QueryDescription> mergeExtended(final Map<QueryId, QueryDescription> allResults, final Pair<Map<HostInfo, KsqlEntity>, Set<HostInfo>> remoteResults) {
final List<QueryDescription> remoteQueryDescriptions = remoteResults.getLeft().values().stream().map(QueryDescriptionList.class::cast).map(QueryDescriptionList::getQueryDescriptions).flatMap(List::stream).collect(Collectors.toList());
for (QueryDescription q : remoteQueryDescriptions) {
final QueryId queryId = q.getId();
// and the streams metadata task set
if (allResults.containsKey(queryId)) {
for (Map.Entry<KsqlHostInfoEntity, KsqlQueryStatus> entry : q.getKsqlHostQueryStatus().entrySet()) {
allResults.get(queryId).updateKsqlHostQueryStatus(entry.getKey(), entry.getValue());
}
allResults.get(queryId).updateTaskMetadata(q.getTasksMetadata());
} else {
allResults.put(queryId, q);
}
}
final Set<HostInfo> unresponsiveRemoteHosts = remoteResults.getRight();
for (HostInfo hostInfo : unresponsiveRemoteHosts) {
for (QueryDescription queryDescription : allResults.values()) {
queryDescription.updateKsqlHostQueryStatus(new KsqlHostInfoEntity(hostInfo.host(), hostInfo.port()), KsqlQueryStatus.UNRESPONSIVE);
}
}
return allResults;
}
Aggregations