Search in sources :

Example 51 with HostInfo

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)));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Test(org.junit.Test)

Example 52 with HostInfo

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)));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Test(org.junit.Test)

Example 53 with HostInfo

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/"));
}
Also used : KsqlNode(io.confluent.ksql.physical.scalablepush.locator.PushLocator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) URL(java.net.URL) Test(org.junit.Test)

Example 54 with HostInfo

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;
}
Also used : RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Queries(io.confluent.ksql.rest.entity.Queries) ListQueries(io.confluent.ksql.parser.tree.ListQueries) QueryId(io.confluent.ksql.query.QueryId) Map(java.util.Map) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)

Example 55 with HostInfo

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;
}
Also used : QueryId(io.confluent.ksql.query.QueryId) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Map(java.util.Map) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)

Aggregations

HostInfo (org.apache.kafka.streams.state.HostInfo)57 TopicPartition (org.apache.kafka.common.TopicPartition)31 HashSet (java.util.HashSet)30 Test (org.junit.Test)27 Set (java.util.Set)25 HashMap (java.util.HashMap)22 TaskId (org.apache.kafka.streams.processor.TaskId)18 AssignmentInfo (org.apache.kafka.streams.processor.internals.assignment.AssignmentInfo)16 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)12 Map (java.util.Map)12 PartitionInfo (org.apache.kafka.common.PartitionInfo)11 ArrayList (java.util.ArrayList)10 UUID (java.util.UUID)9 Cluster (org.apache.kafka.common.Cluster)9 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)8 StreamsMetadata (org.apache.kafka.streams.StreamsMetadata)7 SubscriptionInfo (org.apache.kafka.streams.processor.internals.assignment.SubscriptionInfo)7 List (java.util.List)6 Node (org.apache.kafka.common.Node)6 KsqlNode (io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode)5