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