Skip to content

Commit

Permalink
Await GREEN status in IndexCreatingDatabaseOperation (#2890)
Browse files Browse the repository at this point in the history
The IndexCreatingDatabaseOperation now waits for the ES cluster health state
to be green (for max. 15 seconds) before it runs any operation.

Closes #2888

* Ensure to have only 1 shard and 0 replicas in SearchesTest
  • Loading branch information
joschi authored and bernd committed Sep 26, 2016
1 parent 0fab9b1 commit 430518c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.common.unit.TimeValue;
import org.graylog2.audit.NullAuditEventSender;
import org.graylog2.configuration.ElasticsearchConfiguration;
import org.graylog2.indexer.IndexMapping;
Expand Down Expand Up @@ -49,6 +50,7 @@ public IndexCreatingDatabaseOperation(DatabaseOperation<Client> databaseOperatio

@Override
public void insert(InputStream dataScript) {
waitForGreenStatus();
final IndicesAdminClient indicesAdminClient = client.admin().indices();
for (String index : indexes) {
final IndicesExistsResponse indicesExistsResponse = indicesAdminClient.prepareExists(index)
Expand All @@ -72,9 +74,17 @@ public void insert(InputStream dataScript) {

@Override
public void deleteAll() {
waitForGreenStatus();
databaseOperation.deleteAll();
}

private void waitForGreenStatus() {
client.admin().cluster().prepareHealth()
.setTimeout(TimeValue.timeValueSeconds(15L))
.setWaitForGreenStatus()
.get();
}

@Override
public boolean databaseIs(InputStream expectedData) {
return databaseOperation.databaseIs(expectedData);
Expand Down
Expand Up @@ -106,6 +106,16 @@ public DateTime begin() {
public String getIndexPrefix() {
return "graylog";
}

@Override
public int getShards() {
return 1;
}

@Override
public int getReplicas() {
return 0;
}
};

@Mock
Expand Down

0 comments on commit 430518c

Please sign in to comment.