Search in sources :

Example 1 with ClusterHealth

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

the class ClusterSystemInfoWriter method write.

@Override
public void write(JsonWriter json) throws InterruptedException {
    ClusterHealth clusterHealth = healthChecker.checkCluster();
    writeHealth(clusterHealth.getHealth(), json);
    writeGlobalSections(json);
    writeApplicationNodes(json, clusterHealth);
    writeSearchNodes(json, clusterHealth);
    writeTelemetry(json);
}
Also used : ClusterHealth(org.sonar.server.health.ClusterHealth)

Example 2 with ClusterHealth

use of org.sonar.server.health.ClusterHealth 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 ClusterHealth

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

the class HealthActionTest method response_sort_nodes_by_type_name_host_then_port_when_clustered.

@Test
public void response_sort_nodes_by_type_name_host_then_port_when_clustered() {
    authenticateWithRandomMethod();
    // using created field as a unique identifier. pseudo random value to ensure sorting is not based on created field
    List<NodeHealth> nodeHealths = new ArrayList<>(Arrays.asList(randomNodeHealth(NodeDetails.Type.APPLICATION, "1_name", "1_host", 1, 99), randomNodeHealth(NodeDetails.Type.APPLICATION, "1_name", "2_host", 1, 85), randomNodeHealth(NodeDetails.Type.APPLICATION, "1_name", "2_host", 2, 12), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "1_host", 1, 6), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "1_host", 2, 30), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "2_host", 1, 75), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "2_host", 2, 258), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "1_host", 1, 963), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "1_host", 2, 1), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "2_host", 1, 35), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "2_host", 2, 45), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "1_host", 1, 39), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "1_host", 2, 28), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "2_host", 1, 66), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "2_host", 2, 77)));
    String[] expected = nodeHealths.stream().map(s -> formatDateTime(new Date(s.getDetails().getStartedAt()))).toArray(String[]::new);
    Collections.shuffle(nodeHealths);
    when(webServer.isStandalone()).thenReturn(false);
    when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(GREEN, new HashSet<>(nodeHealths)));
    System.HealthResponse response = underTest.newRequest().executeProtobuf(System.HealthResponse.class);
    assertThat(response.getNodes().getNodesList()).extracting(System.Node::getStartedAt).containsExactly(expected);
}
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) Date(java.util.Date) WebServer(org.sonar.server.platform.WebServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GREEN(org.sonar.server.health.Health.GREEN) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NodeHealth.newNodeHealthBuilder(org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder) Health.newHealthCheckBuilder(org.sonar.server.health.Health.newHealthCheckBuilder) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) WebService(org.sonar.api.server.ws.WebService) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) 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) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) UserSessionRule(org.sonar.server.tester.UserSessionRule) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptySet(java.util.Collections.emptySet) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) System(org.sonarqube.ws.System) ClusterHealth(org.sonar.server.health.ClusterHealth) NodeDetails.newNodeDetailsBuilder(org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder) List(java.util.List) Rule(org.junit.Rule) SystemPasscode(org.sonar.server.user.SystemPasscode) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Collections(java.util.Collections) TestResponse(org.sonar.server.ws.TestResponse) Mockito.mock(org.mockito.Mockito.mock) ArrayList(java.util.ArrayList) Date(java.util.Date) System(org.sonarqube.ws.System) NodeHealth(org.sonar.process.cluster.health.NodeHealth) ClusterHealth(org.sonar.server.health.ClusterHealth) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ClusterHealth

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

the class HealthActionTest method verify_response_example.

@Test
public void verify_response_example() {
    authenticateWithRandomMethod();
    when(webServer.isStandalone()).thenReturn(false);
    long time = parseDateTime("2015-08-13T23:34:59+0200").getTime();
    when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(newHealthCheckBuilder().setStatus(Health.Status.RED).addCause("Application node app-1 is RED").build(), ImmutableSet.of(newNodeHealthBuilder().setStatus(NodeHealth.Status.RED).addCause("foo").setDetails(newNodeDetailsBuilder().setName("app-1").setType(NodeDetails.Type.APPLICATION).setHost("192.168.1.1").setPort(999).setStartedAt(time).build()).build(), newNodeHealthBuilder().setStatus(NodeHealth.Status.YELLOW).addCause("bar").setDetails(newNodeDetailsBuilder().setName("app-2").setType(NodeDetails.Type.APPLICATION).setHost("192.168.1.2").setPort(999).setStartedAt(time).build()).build(), newNodeHealthBuilder().setStatus(NodeHealth.Status.GREEN).setDetails(newNodeDetailsBuilder().setName("es-1").setType(NodeDetails.Type.SEARCH).setHost("192.168.1.3").setPort(999).setStartedAt(time).build()).build(), newNodeHealthBuilder().setStatus(NodeHealth.Status.GREEN).setDetails(newNodeDetailsBuilder().setName("es-2").setType(NodeDetails.Type.SEARCH).setHost("192.168.1.4").setPort(999).setStartedAt(time).build()).build(), newNodeHealthBuilder().setStatus(NodeHealth.Status.GREEN).setDetails(newNodeDetailsBuilder().setName("es-3").setType(NodeDetails.Type.SEARCH).setHost("192.168.1.5").setPort(999).setStartedAt(time).build()).build())));
    TestResponse response = underTest.newRequest().execute();
    assertJson(response.getInput()).isSimilarTo(underTest.getDef().responseExampleAsString());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ClusterHealth(org.sonar.server.health.ClusterHealth) Test(org.junit.Test)

Example 5 with ClusterHealth

use of org.sonar.server.health.ClusterHealth 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)

Aggregations

ClusterHealth (org.sonar.server.health.ClusterHealth)7 Test (org.junit.Test)4 NodeHealth (org.sonar.process.cluster.health.NodeHealth)4 Health (org.sonar.server.health.Health)4 System (org.sonarqube.ws.System)4 WebService (org.sonar.api.server.ws.WebService)3 DateUtils.formatDateTime (org.sonar.api.utils.DateUtils.formatDateTime)3 NodeDetails (org.sonar.process.cluster.health.NodeDetails)3 HealthChecker (org.sonar.server.health.HealthChecker)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Collections.emptySet (java.util.Collections.emptySet)2 Collections.singleton (java.util.Collections.singleton)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Random (java.util.Random)2 IntStream (java.util.stream.IntStream)2