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