Search in sources :

Example 1 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class NodeHealthProviderImpl method get.

@Override
public NodeHealth get() {
    Health nodeHealth = healthChecker.checkNode();
    this.nodeHealthBuilder.clearCauses().setStatus(NodeHealth.Status.valueOf(nodeHealth.getStatus().name()));
    nodeHealth.getCauses().forEach(this.nodeHealthBuilder::addCause);
    return this.nodeHealthBuilder.setDetails(nodeDetails).build();
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth)

Example 2 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class HealthCheckerImpl method checkCluster.

@Override
public ClusterHealth checkCluster() {
    checkState(!webServer.isStandalone(), "Clustering is not enabled");
    checkState(sharedHealthState != null, "HealthState instance can't be null when clustering is enabled");
    Set<NodeHealth> nodeHealths = sharedHealthState.readAll();
    Health health = clusterHealthChecks.stream().map(clusterHealthCheck -> clusterHealthCheck.check(nodeHealths)).reduce(Health.GREEN, HealthReducer.INSTANCE);
    return new ClusterHealth(health, nodeHealths);
}
Also used : List(java.util.List) SharedHealthState(org.sonar.process.cluster.health.SharedHealthState) WebServer(org.sonar.server.platform.WebServer) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableList.copyOf(com.google.common.collect.ImmutableList.copyOf) CheckForNull(javax.annotation.CheckForNull) Nullable(javax.annotation.Nullable) Preconditions.checkState(com.google.common.base.Preconditions.checkState) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth)

Example 3 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class SearchNodeHealthProviderTest method get_returns_name_and_port_from_properties_at_constructor_time.

@Test
public void get_returns_name_and_port_from_properties_at_constructor_time() {
    String name = randomAlphanumeric(3);
    int port = 1 + random.nextInt(4);
    Properties properties = new Properties();
    properties.setProperty(CLUSTER_NODE_NAME.getKey(), name);
    properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(port));
    when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(34));
    when(clock.now()).thenReturn(1L + random.nextInt(87));
    SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
    NodeHealth nodeHealth = underTest.get();
    assertThat(nodeHealth.getDetails().getName()).isEqualTo(name);
    assertThat(nodeHealth.getDetails().getPort()).isEqualTo(port);
    // change values in properties
    properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(6));
    properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(99)));
    NodeHealth newNodeHealth = underTest.get();
    assertThat(newNodeHealth.getDetails().getName()).isEqualTo(name);
    assertThat(newNodeHealth.getDetails().getPort()).isEqualTo(port);
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 4 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class SearchNodeHealthProviderTest method get_returns_host_from_property_if_set_at_constructor_time.

@Test
public void get_returns_host_from_property_if_set_at_constructor_time() {
    String host = randomAlphanumeric(55);
    Properties properties = new Properties();
    properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
    properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4)));
    properties.setProperty(CLUSTER_NODE_HOST.getKey(), host);
    when(clock.now()).thenReturn(1L + random.nextInt(87));
    SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
    NodeHealth nodeHealth = underTest.get();
    assertThat(nodeHealth.getDetails().getHost()).isEqualTo(host);
    // change now
    properties.setProperty(CLUSTER_NODE_HOST.getKey(), randomAlphanumeric(96));
    NodeHealth newNodeHealth = underTest.get();
    assertThat(newNodeHealth.getDetails().getHost()).isEqualTo(host);
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 5 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class SearchNodeHealthProviderTest method get_returns_status_GREEN_if_elasticsearch_process_is_operational_in_ClusterAppState.

@Test
public void get_returns_status_GREEN_if_elasticsearch_process_is_operational_in_ClusterAppState() {
    Properties properties = new Properties();
    setRequiredPropertiesAndMocks(properties);
    when(clusterAppState.isOperational(ProcessId.ELASTICSEARCH, true)).thenReturn(true);
    SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
    NodeHealth nodeHealth = underTest.get();
    assertThat(nodeHealth.getStatus()).isEqualTo(NodeHealth.Status.GREEN);
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Aggregations

NodeHealth (org.sonar.process.cluster.health.NodeHealth)37 Test (org.junit.Test)33 Arrays (java.util.Arrays)6 Properties (java.util.Properties)6 Random (java.util.Random)6 IntStream (java.util.stream.IntStream)6 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)6 Props (org.sonar.process.Props)6 NodeDetails (org.sonar.process.cluster.health.NodeDetails)6 Set (java.util.Set)5 Collectors.toSet (java.util.stream.Collectors.toSet)4 Stream (java.util.stream.Stream)4 Stream.of (java.util.stream.Stream.of)4 GREEN (org.sonar.process.cluster.health.NodeHealth.Status.GREEN)4 RED (org.sonar.process.cluster.health.NodeHealth.Status.RED)4 YELLOW (org.sonar.process.cluster.health.NodeHealth.Status.YELLOW)4 HealthAssert.assertThat (org.sonar.server.health.HealthAssert.assertThat)4 Date (java.util.Date)3 HashSet (java.util.HashSet)2 List (java.util.List)2