use of org.sonar.server.es.newindex.BuiltIndex in project sonarqube by SonarSource.
the class EsTester method createIndices.
private static List<BuiltIndex> createIndices(IndexDefinition... definitions) {
IndexDefinitionContext context = new IndexDefinitionContext();
Stream.of(definitions).forEach(d -> d.define(context));
List<BuiltIndex> result = new ArrayList<>();
for (NewIndex newIndex : context.getIndices().values()) {
BuiltIndex index = newIndex.build();
String indexName = index.getMainType().getIndex().getName();
deleteIndexIfExists(indexName);
// create index
Settings.Builder settings = Settings.builder();
settings.put(index.getSettings());
CreateIndexResponse indexResponse = createIndex(indexName, settings);
if (!indexResponse.isAcknowledged()) {
throw new IllegalStateException("Failed to create index " + indexName);
}
waitForClusterYellowStatus(indexName);
// create types
String typeName = index.getMainType().getType();
putIndexMapping(index, indexName, typeName);
waitForClusterYellowStatus(indexName);
result.add(index);
}
return result;
}
use of org.sonar.server.es.newindex.BuiltIndex in project sonarqube by SonarSource.
the class IndexCreator method createIndex.
private void createIndex(BuiltIndex<?> builtIndex, boolean useMetadata) {
Index index = builtIndex.getMainType().getIndex();
LOGGER.info(String.format("Create index [%s]", index.getName()));
Settings.Builder settings = Settings.builder();
settings.put(builtIndex.getSettings());
if (useMetadata) {
metadataIndex.setHash(index, IndexDefinitionHash.of(builtIndex));
metadataIndex.setInitialized(builtIndex.getMainType(), false);
builtIndex.getRelationTypes().forEach(relationType -> metadataIndex.setInitialized(relationType, false));
}
CreateIndexResponse indexResponse = client.create(new CreateIndexRequest(index.getName()).settings((settings)));
if (!indexResponse.isAcknowledged()) {
throw new IllegalStateException("Failed to create index [" + index.getName() + "]");
}
client.waitForStatus(ClusterHealthStatus.YELLOW);
// create types
LOGGER.info("Create type {}", builtIndex.getMainType().format());
AcknowledgedResponse mappingResponse = client.putMapping(new PutMappingRequest(builtIndex.getMainType().getIndex().getName()).type(builtIndex.getMainType().getType()).source(builtIndex.getAttributes()));
if (!mappingResponse.isAcknowledged()) {
throw new IllegalStateException("Failed to create type " + builtIndex.getMainType().getType());
}
client.waitForStatus(ClusterHealthStatus.YELLOW);
}
Aggregations