Search in sources :

Example 1 with Health

use of org.sonar.server.health.Health in project sonarqube by SonarSource.

the class StandaloneSystemInfoWriter method writeHealth.

private void writeHealth(JsonWriter json) {
    Health health = healthChecker.checkNode();
    writeHealth(health, json);
}
Also used : Health(org.sonar.server.health.Health)

Example 2 with Health

use of org.sonar.server.health.Health in project sonarqube by SonarSource.

the class HealthActionSupport method toResponse.

private static System.HealthResponse toResponse(ClusterHealth check) {
    System.HealthResponse.Builder responseBuilder = System.HealthResponse.newBuilder();
    System.Node.Builder nodeBuilder = System.Node.newBuilder();
    System.Cause.Builder causeBuilder = System.Cause.newBuilder();
    Health health = check.getHealth();
    responseBuilder.setHealth(System.Health.valueOf(health.getStatus().name()));
    health.getCauses().forEach(str -> responseBuilder.addCauses(toCause(str, causeBuilder)));
    System.Nodes.Builder nodesBuilder = System.Nodes.newBuilder();
    check.getNodes().stream().sorted(NODE_HEALTH_COMPARATOR).map(node -> toNode(node, nodeBuilder, causeBuilder)).forEach(nodesBuilder::addNodes);
    responseBuilder.setNodes(nodesBuilder.build());
    return responseBuilder.build();
}
Also used : WebService(org.sonar.api.server.ws.WebService) Resources(com.google.common.io.Resources) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeDetails(org.sonar.process.cluster.health.NodeDetails) HealthChecker(org.sonar.server.health.HealthChecker) Health(org.sonar.server.health.Health) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) Comparator(java.util.Comparator) System(org.sonarqube.ws.System) ClusterHealth(org.sonar.server.health.ClusterHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Health(org.sonar.server.health.Health) ClusterHealth(org.sonar.server.health.ClusterHealth)

Example 3 with Health

use of org.sonar.server.health.Health in project sonarqube by SonarSource.

the class SafeModeHealthActionTest method request_returns_status_and_causes_from_HealthChecker_checkNode_method.

@Test
public void request_returns_status_and_causes_from_HealthChecker_checkNode_method() {
    authenticateWithPasscode();
    Health.Status randomStatus = Health.Status.values()[new Random().nextInt(Health.Status.values().length)];
    Health.Builder builder = newHealthCheckBuilder().setStatus(randomStatus);
    IntStream.range(0, new Random().nextInt(5)).mapToObj(i -> RandomStringUtils.randomAlphanumeric(3)).forEach(builder::addCause);
    Health health = builder.build();
    when(healthChecker.checkNode()).thenReturn(health);
    TestRequest request = underTest.newRequest();
    System.HealthResponse healthResponse = request.executeProtobuf(System.HealthResponse.class);
    assertThat(healthResponse.getHealth().name()).isEqualTo(randomStatus.name());
    assertThat(health.getCauses()).isEqualTo(health.getCauses());
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) System(org.sonarqube.ws.System) Health.newHealthCheckBuilder(org.sonar.server.health.Health.newHealthCheckBuilder) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SystemPasscode(org.sonar.server.user.SystemPasscode) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) HealthChecker(org.sonar.server.health.HealthChecker) Health(org.sonar.server.health.Health) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) TestResponse(org.sonar.server.ws.TestResponse) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Health(org.sonar.server.health.Health) System(org.sonarqube.ws.System) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 4 with Health

use of org.sonar.server.health.Health in project sonarqube by SonarSource.

the class ClusterSystemInfoWriterTest method before.

@Before
public void before() throws InterruptedException {
    when(globalInfoLoader.load()).thenReturn(Collections.singletonList(createSection("globalInfo")));
    when(appNodesInfoLoader.load()).thenReturn(Collections.singletonList(createNodeInfo("appNodes")));
    when(searchNodesInfoLoader.load()).thenReturn(Collections.singletonList(createNodeInfo("searchNodes")));
    Health health = Health.newHealthCheckBuilder().setStatus(Health.Status.GREEN).build();
    when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(health, Collections.emptySet()));
}
Also used : ClusterHealth(org.sonar.server.health.ClusterHealth) Health(org.sonar.server.health.Health) ClusterHealth(org.sonar.server.health.ClusterHealth) Before(org.junit.Before)

Example 5 with Health

use of org.sonar.server.health.Health in project sonarqube by SonarSource.

the class HealthActionSupport method checkNodeHealth.

System.HealthResponse checkNodeHealth() {
    Health check = healthChecker.checkNode();
    System.HealthResponse.Builder responseBuilder = System.HealthResponse.newBuilder().setHealth(System.Health.valueOf(check.getStatus().name()));
    System.Cause.Builder causeBuilder = System.Cause.newBuilder();
    check.getCauses().forEach(str -> responseBuilder.addCauses(causeBuilder.clear().setMessage(str).build()));
    return responseBuilder.build();
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) Health(org.sonar.server.health.Health) ClusterHealth(org.sonar.server.health.ClusterHealth)

Aggregations

Health (org.sonar.server.health.Health)6 ClusterHealth (org.sonar.server.health.ClusterHealth)4 WebService (org.sonar.api.server.ws.WebService)3 NodeHealth (org.sonar.process.cluster.health.NodeHealth)3 HealthChecker (org.sonar.server.health.HealthChecker)3 Arrays (java.util.Arrays)2 Random (java.util.Random)2 IntStream (java.util.stream.IntStream)2 RandomStringUtils (org.apache.commons.lang.RandomStringUtils)2 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 ThrowingCallable (org.assertj.core.api.ThrowableAssert.ThrowingCallable)2 Test (org.junit.Test)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2 DateUtils.formatDateTime (org.sonar.api.utils.DateUtils.formatDateTime)2 NodeDetails (org.sonar.process.cluster.health.NodeDetails)2 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)2