Search in sources :

Example 1 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class HeartbeatAgent method setLocalAddress.

void setLocalAddress(final String applicationServer) {
    final HostInfo hostInfo = ServerUtil.parseHostInfo(applicationServer);
    this.localHost = new KsqlHostInfo(hostInfo.host(), hostInfo.port());
    try {
        this.localUrl = new URL(applicationServer);
    } catch (final Exception e) {
        throw new IllegalStateException("Failed to convert remote host info to URL." + " remoteInfo: " + localHost.host() + ":" + localHost.host());
    }
    // This is called on startup of the heartbeat agent, no other entries should exist in the map
    Preconditions.checkState(hostsStatus.isEmpty(), "expected empty host status map on startup");
    hostsStatus.putIfAbsent(localHost, new HostStatus(true, clock.millis()));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) HostStatus(io.confluent.ksql.util.HostStatus) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class LivenessFilter method filter.

/**
 * Returns true if the host is alive. If the heartbeat agent is not enabled, all hosts are
 * assumed to be alive.
 * @param host The host for which the status is checked
 * @return true if the host is alive, false otherwise.
 */
@Override
public Host filter(final KsqlHostInfo host) {
    if (!heartbeatAgent.isPresent()) {
        return Host.include(host);
    }
    final Map<KsqlHostInfo, HostStatus> allHostsStatus = heartbeatAgent.get().getHostsStatus();
    final HostStatus status = allHostsStatus.get(host);
    if (status == null) {
        return Host.include(host);
    }
    if (status.isHostAlive()) {
        return Host.include(host);
    } else {
        return Host.exclude(host, "Host is not alive as of time " + status.getLastStatusUpdateMs());
    }
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) HostStatus(io.confluent.ksql.util.HostStatus)

Example 3 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class MaximumLagFilter method create.

/**
 * Creates a FreshnessFilter
 * @param lagReportingAgent The optional lag reporting agent.
 * @param routingOptions The routing options
 * @param hosts The set of all hosts that have the store, including actives and standbys
 * @param applicationQueryId The query id of the persistent query that materialized the table
 * @param storeName The state store name of the materialized table
 * @param partition The partition of the topic
 * @return a new FreshnessFilter, unless lag reporting is disabled.
 */
public static Optional<MaximumLagFilter> create(final Optional<LagReportingAgent> lagReportingAgent, final RoutingOptions routingOptions, final List<KsqlHostInfo> hosts, final String applicationQueryId, final String storeName, final int partition) {
    if (!lagReportingAgent.isPresent()) {
        return Optional.empty();
    }
    final QueryStateStoreId queryStateStoreId = QueryStateStoreId.of(applicationQueryId, storeName);
    final ImmutableMap<KsqlHostInfo, Optional<LagInfoEntity>> lagByHost = hosts.stream().collect(ImmutableMap.toImmutableMap(Function.identity(), host -> lagReportingAgent.get().getLagInfoForHost(host, queryStateStoreId, partition)));
    final OptionalLong maxEndOffset = lagByHost.values().stream().filter(Optional::isPresent).map(Optional::get).mapToLong(LagInfoEntity::getEndOffsetPosition).max();
    return Optional.of(new MaximumLagFilter(routingOptions, lagByHost, maxEndOffset));
}
Also used : OptionalLong(java.util.OptionalLong) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) Objects.requireNonNull(java.util.Objects.requireNonNull) RoutingOptions(io.confluent.ksql.execution.streams.RoutingOptions) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) QueryStateStoreId(io.confluent.ksql.rest.entity.QueryStateStoreId) Function(java.util.function.Function) RoutingFilter(io.confluent.ksql.execution.streams.RoutingFilter) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Optional(java.util.Optional) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) QueryStateStoreId(io.confluent.ksql.rest.entity.QueryStateStoreId) OptionalLong(java.util.OptionalLong)

Example 4 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class HeartbeatResource method handleHeartbeat.

private void handleHeartbeat(final HeartbeatMessage request) {
    final KsqlHostInfoEntity ksqlHostInfoEntity = request.getHostInfo();
    final KsqlHostInfo ksqlHostInfo = new KsqlHostInfo(ksqlHostInfoEntity.getHost(), ksqlHostInfoEntity.getPort());
    final long timestamp = request.getTimestamp();
    heartbeatAgent.receiveHeartbeat(ksqlHostInfo, timestamp);
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity)

Example 5 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsLocatorTest method shouldReturnLocalOwnerIfSameAsSuppliedLocalHost.

@Test
public void shouldReturnLocalOwnerIfSameAsSuppliedLocalHost() {
    // Given:
    final HostInfo localHostInfo = new HostInfo(LOCAL_HOST_URL.getHost(), 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)

Aggregations

KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)19 HostInfo (org.apache.kafka.streams.state.HostInfo)9 Test (org.junit.Test)7 KsqlPartitionLocation (io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation)6 KsqlNode (io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode)5 Before (org.junit.Before)4 HostStatus (io.confluent.ksql.util.HostStatus)3 RoutingFilter (io.confluent.ksql.execution.streams.RoutingFilter)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 List (java.util.List)2 Optional (java.util.Optional)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 RoutingOptions (io.confluent.ksql.execution.streams.RoutingOptions)1