System.HealthResponse checkClusterHealth() { ClusterHealth check = healthChecker.checkCluster(); return toResponse(check); }
@Test public void request_succeeds_with_SystemPasscode_enabled_and_passcode() { when(systemPasscode.isValid(any())).thenReturn(true); when(healthChecker.checkCluster()).thenReturn(randomStatusMinimalClusterHealth()); TestRequest request = underTest.newRequest(); request.execute(); }
@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())); }
@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); }
@Test public void request_succeeds_with_SystemPasscode_incorrect_and_user_is_system_administrator() { when(systemPasscode.isValid(any())).thenReturn(false); userSessionRule.logIn().setSystemAdministrator(); when(healthChecker.checkCluster()).thenReturn(randomStatusMinimalClusterHealth()); TestRequest request = underTest.newRequest(); request.execute(); }
@Test public void request_fails_with_SystemPasscode_enabled_but_no_passcode_and_user_is_not_system_administrator() { when(systemPasscode.isValid(any())).thenReturn(false); userSessionRule.logIn(); when(healthChecker.checkCluster()).thenReturn(randomStatusMinimalClusterHealth()); TestRequest request = underTest.newRequest(); expectForbiddenException(); request.execute(); }
@Test public void response_contains_status_and_causes_from_HealthChecker_checkCluster_when_standalone() { authenticateWithRandomMethod(); Health.Status randomStatus = Health.Status.values()[random.nextInt(Health.Status.values().length)]; String[] causes = IntStream.range(0, random.nextInt(33)).mapToObj(i -> randomAlphanumeric(4)).toArray(String[]::new); Health.Builder healthBuilder = newHealthCheckBuilder() .setStatus(randomStatus); Arrays.stream(causes).forEach(healthBuilder::addCause); when(webServer.isStandalone()).thenReturn(false); when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(healthBuilder.build(), emptySet())); System.HealthResponse clusterHealthResponse = underTest.newRequest().executeProtobuf(System.HealthResponse.class); assertThat(clusterHealthResponse.getHealth().name()).isEqualTo(randomStatus.name()); assertThat(clusterHealthResponse.getCausesList()) .extracting(System.Cause::getMessage) .containsOnly(causes); }
@Test public void response_contains_information_of_nodes_when_clustered() { authenticateWithRandomMethod(); NodeHealth nodeHealth = randomNodeHealth(); when(webServer.isStandalone()).thenReturn(false); when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(GREEN, singleton(nodeHealth))); System.HealthResponse response = underTest.newRequest().executeProtobuf(System.HealthResponse.class); assertThat(response.getNodes().getNodesList()) .hasSize(1); System.Node node = response.getNodes().getNodesList().iterator().next(); assertThat(node.getHealth().name()).isEqualTo(nodeHealth.getStatus().name()); assertThat(node.getCausesList()) .extracting(System.Cause::getMessage) .containsOnly(nodeHealth.getCauses().stream().toArray(String[]::new)); assertThat(node.getName()).isEqualTo(nodeHealth.getDetails().getName()); assertThat(node.getHost()).isEqualTo(nodeHealth.getDetails().getHost()); assertThat(node.getPort()).isEqualTo(nodeHealth.getDetails().getPort()); assertThat(node.getStartedAt()).isEqualTo(formatDateTime(nodeHealth.getDetails().getStartedAt())); assertThat(node.getType().name()).isEqualTo(nodeHealth.getDetails().getType().name()); }
@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); }
when(webServer.isStandalone()).thenReturn(false); long time = parseDateTime("2015-08-13T23:34:59+0200").getTime(); when(healthChecker.checkCluster()) .thenReturn( new ClusterHealth(newHealthCheckBuilder()
System.HealthResponse checkClusterHealth() { ClusterHealth check = healthChecker.checkCluster(); return toResponse(check); }
@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); }