From: Simon Brandhof Date: Sat, 29 Nov 2014 10:26:30 +0000 (+0100) Subject: CI error investigations - add verifications when creating index X-Git-Tag: 5.0-RC1~150 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b86386e9d32a39e1f4c2877098e854ad237c57b;p=sonarqube.git CI error investigations - add verifications when creating index --- 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()); + } } }