public string GetStatus() { // Use the cluster health API to verify that the Best Bets index is functioning. // Maps to https://ncias-d1592-v.nci.nih.gov:9299/_cluster/health/bestbets?pretty (or other server) // // References: // https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html // https://github.com/elastic/elasticsearch/blob/master/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.health.json#L20 IClusterHealthResponse response = _elasticClient.ClusterHealth(hd => { hd = hd .Index("autosg"); return(hd); }); if (!response.IsValid) { _logger.LogError("Error checking ElasticSearch health."); _logger.LogError("Returned debug info: {0}.", response.DebugInformation); throw new APIErrorException(500, "Errors Occurred."); } if (response.Status != "green" && response.Status != "yellow") { _logger.LogError("Elasticsearch not healthy. Index status is '{0}'.", response.Status); throw new APIErrorException(500, "Service not healthy."); } return(HEALTHY_STATUS); }
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) { foreach (var index in values.Values) client.CreateIndex(index, this.CreateIndexSettings).ShouldBeValid(); var indices = Infer.Indices(values.Values.Select(i => (IndexName)i)); client.ClusterHealth(f => f.WaitForStatus(WaitForStatus.Yellow).Index(indices)) .ShouldBeValid(); }
private static bool IsServerInitialized(IElasticClient client) { var pingResponse = client.Ping(); if (pingResponse.IsValid) { Log.Information("Elasticsearch cluster responded to PING. Checking cluster health..."); var clusterHealthResponse = client.ClusterHealth(); if (clusterHealthResponse.IsValid) { switch (clusterHealthResponse.Status) { case Health.Red: Log.Warning("Elasticsearch cluster health is RED. Will back off and wait for cluster to recover"); return(false); case Health.Yellow: Log.Warning("Elasticsearch cluster health is YELLOW."); return(true); case Health.Green: Log.Information("Elasticsearch cluster health is GREEN"); return(true); default: throw new ArgumentOutOfRangeException(); } } } return(false); }
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) { foreach (var index in values.Values) { client.CreateIndex(index); } client.ClusterHealth(f => f.WaitForStatus(WaitForStatus.Yellow)); }
protected override void BeforeAllCalls(IElasticClient client, IDictionary <ClientMethod, string> values) { foreach (var index in values.Values) { client.CreateIndex(index); } client.ClusterHealth(f => f.WaitForStatus(WaitForStatus.Yellow)); }
public override void Validate(IElasticClient client, NodeConfiguration configuration) { var healthyCluster = client.ClusterHealth(g => g .WaitForStatus(WaitForStatus.Yellow) .Timeout(ClusterHealthTimeout) ); if (!healthyCluster.IsValid) { throw new Exception($"Did not see a healhty cluster before calling onNodeStarted handler." + healthyCluster.DebugInformation); } }
private void WaitForClusterBootstrap(IElasticClient client, XplatManualResetEvent handle, bool alreadyRunningInstance) { var healthyCluster = client.ClusterHealth(g => g.WaitForStatus(WaitForStatus.Yellow).Timeout(ClusterHealthTimeout)); if (healthyCluster.IsValid) { this.Started = true; this._blockingSubject.OnNext(handle); if (alreadyRunningInstance && !handle.WaitOne(HandleTimeout, true)) { throw new Exception($"Could not launch tests on already running elasticsearch within {HandleTimeout}"); } } else { this.Fatal(handle, new Exception("Did not see a healthy cluster after the node started for 30 seconds")); } }