From 5b86386e9d32a39e1f4c2877098e854ad237c57b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 29 Nov 2014 11:26:30 +0100 Subject: [PATCH] CI error investigations - add verifications when creating index --- .../java/org/sonar/server/es/IndexCreator.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/IndexCreator.java b/server/sonar-server/src/main/java/org/sonar/server/es/IndexCreator.java index 3a8c980d5df..6f9a01c63f3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/IndexCreator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/IndexCreator.java @@ -20,6 +20,9 @@ package org.sonar.server.es; import org.apache.commons.lang.StringUtils; +import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; +import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.ImmutableSettings; import org.picocontainer.Startable; import org.slf4j.Logger; @@ -75,19 +78,26 @@ public class IndexCreator implements ServerComponent, Startable { ImmutableSettings.Builder settings = ImmutableSettings.builder(); settings.put(index.getSettings()); settings.put(SETTING_HASH, new IndexHash().of(index)); - client + CreateIndexResponse indexResponse = client .prepareCreate(index.getName()) .setSettings(settings) .get(); + if (!indexResponse.isAcknowledged()) { + throw new IllegalStateException("Failed to create index " + index.getName()); + } + client.prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().get(); // create types for (Map.Entry entry : index.getTypes().entrySet()) { LOGGER.info(String.format("Create type %s/%s", index.getName(), entry.getKey())); - client.preparePutMapping(index.getName()) + PutMappingResponse mappingResponse = client.preparePutMapping(index.getName()) .setType(entry.getKey()) .setIgnoreConflicts(false) .setSource(entry.getValue().getAttributes()) .get(); + if (!mappingResponse.isAcknowledged()) { + throw new IllegalStateException("Failed to create type " + entry.getKey()); + } } } -- 2.39.5