use of io.confluent.ksql.util.HostStatus 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.HostStatus 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.HostStatus in project ksql by confluentinc.
the class HeartbeatAgentTest method setUp.
@Before
public void setUp() {
localHostInfo = new HostInfo("localhost", 8088);
remoteHostInfo = new HostInfo("localhost", 8089);
localHost = new KsqlHostInfo("localhost", 8088);
remoteHost = new KsqlHostInfo("localhost", 8089);
Builder builder = HeartbeatAgent.builder();
heartbeatAgent = builder.heartbeatSendInterval(1).heartbeatMissedThreshold(2).addHostStatusListener(hostStatusListener).build(ksqlEngine, serviceContext);
heartbeatAgent.setLocalAddress(LOCALHOST_URL);
hostsStatus = ImmutableMap.of(localHost, new HostStatus(true, 0L), remoteHost, new HostStatus(true, 0L));
allMetadata0 = ImmutableList.of(streamsMetadata0);
allMetadata1 = ImmutableList.of(streamsMetadata1);
}
use of io.confluent.ksql.util.HostStatus in project ksql by confluentinc.
the class HeartbeatAgentTest method localhostOnlyShouldMarkServerAsUp.
@Test
public void localhostOnlyShouldMarkServerAsUp() {
// Given:
long windowStart = 0;
long windowEnd = 5;
hostsStatus = ImmutableMap.of(localHost, new HostStatus(true, 0L));
heartbeatAgent.setHostsStatus(hostsStatus);
CheckHeartbeatService processService = heartbeatAgent.new CheckHeartbeatService();
// When:
processService.runWithWindow(windowStart, windowEnd);
// Then:
assertThat(heartbeatAgent.getHostsStatus().entrySet(), hasSize(1));
assertThat(heartbeatAgent.getHostsStatus().get(localHost).isHostAlive(), is(true));
verify(hostStatusListener).onHostStatusUpdated(Mockito.eq(heartbeatAgent.getHostsStatus()));
}
Aggregations