Search in sources :

Example 11 with Status

use of io.pravega.shared.health.Status in project pravega by pravega.

the class HealthImpl method getStatus.

private void getStatus(String id, SecurityContext securityContext, AsyncResponse asyncResponse, String method) {
    long traceId = LoggerHelpers.traceEnter(log, method);
    processRequest(() -> {
        Status status = endpoint.getStatus(id);
        asyncResponse.resume(Response.status(Response.Status.OK).entity(adapter(status)).build());
    }, asyncResponse, method, traceId, id);
}
Also used : HealthStatus(io.pravega.shared.health.bindings.generated.model.HealthStatus) Status(io.pravega.shared.health.Status)

Example 12 with Status

use of io.pravega.shared.health.Status in project pravega by pravega.

the class AbstractHealthContributor method getHealthSnapshot.

/**
 * Recursively build (in post-order fashion) the {@link Health} result for a given {@link HealthContributor}.
 *
 * @return The {@link Health} result of the {@link HealthContributor}.
 */
@Override
public final synchronized Health getHealthSnapshot() {
    Exceptions.checkNotClosed(isClosed(), this);
    Health.HealthBuilder builder = Health.builder().name(getName());
    Collection<Status> statuses = new ArrayList<>();
    Map<String, Health> children = new HashMap<>();
    for (val entry : contributors.entrySet()) {
        HealthContributor contributor = entry.getValue();
        synchronized (contributor) {
            if (!contributor.isClosed()) {
                Health health = contributor.getHealthSnapshot();
                children.put(entry.getKey(), health);
                statuses.add(health.getStatus());
            } else {
                contributors.remove(name);
            }
        }
    }
    Status status = Status.DOWN;
    // Perform own health check logic.
    try {
        status = doHealthCheck(builder);
    } catch (Exception ex) {
        log.warn("HealthCheck for {} has failed.", this.name, ex);
        builder.status(Status.FAILED);
    }
    // If there are no child statuses, return the Status from its own health check, else
    // return the least 'healthy' status between the child aggregate and its own.
    status = statuses.isEmpty() ? status : Status.min(StatusAggregator.aggregate(aggregator, statuses), status);
    this.status = status;
    return builder.name(name).status(status).children(children).build();
}
Also used : Status(io.pravega.shared.health.Status) lombok.val(lombok.val) Health(io.pravega.shared.health.Health) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HealthContributor(io.pravega.shared.health.HealthContributor)

Example 13 with Status

use of io.pravega.shared.health.Status in project pravega by pravega.

the class CacheManagerTests method testCacheHealth.

/**
 * Tests the health contributor made with cache manager
 */
@Test
public void testCacheHealth() {
    final CachePolicy policy = new CachePolicy(Integer.MAX_VALUE, Duration.ofHours(10000), Duration.ofHours(1));
    @Cleanup val cache = new TestCache(policy.getMaxSize());
    // The Cache Manager won't do anything if there's no stored data.
    cache.setStoredBytes(1);
    @Cleanup TestCacheManager cm = new TestCacheManager(policy, cache, executorService());
    CacheManagerHealthContributor cacheManagerHealthContributor = new CacheManagerHealthContributor(cm);
    Health.HealthBuilder builder = Health.builder().name(cacheManagerHealthContributor.getName());
    Status status = cacheManagerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'UP' Status.", Status.UP, status);
    cm.close();
    status = cacheManagerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'DOWN' Status.", Status.DOWN, status);
}
Also used : lombok.val(lombok.val) Status(io.pravega.shared.health.Status) Health(io.pravega.shared.health.Health) CacheManagerHealthContributor(io.pravega.segmentstore.server.CacheManager.CacheManagerHealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 14 with Status

use of io.pravega.shared.health.Status in project pravega by pravega.

the class SegmentContainerHealthContributorTest method testSegmentContainerHealth.

/**
 * Check health of SegmentContainer with different states.
 */
@Test
public void testSegmentContainerHealth() {
    when(segmentContainer.state()).thenReturn(Service.State.NEW);
    Health.HealthBuilder builder = Health.builder().name(segmentContainerHealthContributor.getName());
    Status status = segmentContainerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'NEW' Status.", Status.NEW, status);
    when(segmentContainer.state()).thenReturn(Service.State.STARTING);
    status = segmentContainerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'STARTING' Status.", Status.STARTING, status);
    when(segmentContainer.state()).thenReturn(Service.State.RUNNING);
    status = segmentContainerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'UP' Status.", Status.UP, status);
    when(segmentContainer.state()).thenReturn(Service.State.TERMINATED);
    status = segmentContainerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'DOWN' Status.", Status.DOWN, status);
}
Also used : Status(io.pravega.shared.health.Status) Health(io.pravega.shared.health.Health) Test(org.junit.Test)

Example 15 with Status

use of io.pravega.shared.health.Status in project pravega by pravega.

the class ServiceStarterTest method testSegmentContainerRegistryHealth.

/**
 * Check health of SegmentContainerRegistry
 */
@Test
public void testSegmentContainerRegistryHealth() {
    @Cleanup SegmentContainerRegistryHealthContributor segmentContainerRegistryHealthContributor = new SegmentContainerRegistryHealthContributor(serviceStarter.getServiceBuilder().getSegmentContainerRegistry());
    Health.HealthBuilder builder = Health.builder().name(segmentContainerRegistryHealthContributor.getName());
    Status status = segmentContainerRegistryHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'UP' Status.", Status.UP, status);
}
Also used : Status(io.pravega.shared.health.Status) Health(io.pravega.shared.health.Health) SegmentContainerRegistryHealthContributor(io.pravega.segmentstore.server.host.health.SegmentContainerRegistryHealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

Status (io.pravega.shared.health.Status)16 Test (org.junit.Test)11 Health (io.pravega.shared.health.Health)6 Cleanup (lombok.Cleanup)3 lombok.val (lombok.val)2 CacheManagerHealthContributor (io.pravega.segmentstore.server.CacheManager.CacheManagerHealthContributor)1 SegmentContainer (io.pravega.segmentstore.server.SegmentContainer)1 SegmentContainerRegistryHealthContributor (io.pravega.segmentstore.server.host.health.SegmentContainerRegistryHealthContributor)1 ZKHealthContributor (io.pravega.segmentstore.server.host.health.ZKHealthContributor)1 HealthContributor (io.pravega.shared.health.HealthContributor)1 HealthStatus (io.pravega.shared.health.bindings.generated.model.HealthStatus)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1