Search in sources :

Example 1 with HostStatus

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

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());
    }
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) HostStatus(io.confluent.ksql.util.HostStatus)

Example 3 with HostStatus

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);
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Builder(io.confluent.ksql.rest.server.HeartbeatAgent.Builder) HostStatus(io.confluent.ksql.util.HostStatus) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Before(org.junit.Before)

Example 4 with HostStatus

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()));
}
Also used : HostStatus(io.confluent.ksql.util.HostStatus) CheckHeartbeatService(io.confluent.ksql.rest.server.HeartbeatAgent.CheckHeartbeatService) Test(org.junit.Test)

Aggregations

HostStatus (io.confluent.ksql.util.HostStatus)4 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)3 HostInfo (org.apache.kafka.streams.state.HostInfo)2 Builder (io.confluent.ksql.rest.server.HeartbeatAgent.Builder)1 CheckHeartbeatService (io.confluent.ksql.rest.server.HeartbeatAgent.CheckHeartbeatService)1 URL (java.net.URL)1 TimeoutException (java.util.concurrent.TimeoutException)1 Before (org.junit.Before)1 Test (org.junit.Test)1