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()));
}
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());
}
}
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));
}
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);
}
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)));
}
Aggregations