Search in sources :

Example 36 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project sonarqube by SonarSource.

the class IndexCreatorTest method recreate_index_on_definition_changes.

@Test
public void recreate_index_on_definition_changes() throws Exception {
    assertThat(mappings()).isEmpty();
    // v1
    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] { new FakeIndexDefinition() }, new MapSettings());
    registry.start();
    IndexCreator creator = new IndexCreator(es.client(), registry);
    creator.start();
    creator.stop();
    String hashV1 = setting("fakes", "index.sonar_hash");
    assertThat(hashV1).isNotEmpty();
    // v2
    registry = new IndexDefinitions(new IndexDefinition[] { new FakeIndexDefinitionV2() }, new MapSettings());
    registry.start();
    creator = new IndexCreator(es.client(), registry);
    creator.start();
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings();
    MappingMetaData mapping = mappings.get("fakes").get("fake");
    assertThat(countMappingFields(mapping)).isEqualTo(3);
    assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date");
    assertThat(field(mapping, "newField").get("type")).isEqualTo("integer");
    String hashV2 = setting("fakes", "index.sonar_hash");
    assertThat(hashV2).isNotEqualTo(hashV1);
    creator.stop();
}
Also used : MapSettings(org.sonar.api.config.MapSettings) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Test(org.junit.Test)

Example 37 with ImmutableOpenMap

use of org.elasticsearch.common.collect.ImmutableOpenMap in project graylog2-server by Graylog2.

the class IndicesTest method testCreateOverwritesIndexTemplate.

@Test
public void testCreateOverwritesIndexTemplate() throws Exception {
    final ObjectMapper mapper = new ObjectMapperProvider().get();
    final String templateName = indexSetConfig.indexTemplateName();
    final IndicesAdminClient client = this.client.admin().indices();
    final ImmutableMap<String, Object> beforeMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
    assertThat(client.preparePutTemplate(templateName).setTemplate(indexSet.getIndexWildcard()).addMapping(IndexMapping.TYPE_MESSAGE, beforeMapping).get().isAcknowledged()).isTrue();
    final GetIndexTemplatesResponse responseBefore = client.prepareGetTemplates(templateName).get();
    final List<IndexTemplateMetaData> beforeIndexTemplates = responseBefore.getIndexTemplates();
    assertThat(beforeIndexTemplates).hasSize(1);
    final ImmutableOpenMap<String, CompressedXContent> beforeMappings = beforeIndexTemplates.get(0).getMappings();
    final Map<String, Object> actualMapping = mapper.readValue(beforeMappings.get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
    });
    assertThat(actualMapping.get(IndexMapping.TYPE_MESSAGE)).isEqualTo(beforeMapping);
    indices.create("index_template_test", indexSet);
    final GetIndexTemplatesResponse responseAfter = client.prepareGetTemplates(templateName).get();
    assertThat(responseAfter.getIndexTemplates()).hasSize(1);
    final IndexTemplateMetaData templateMetaData = responseAfter.getIndexTemplates().get(0);
    assertThat(templateMetaData.getName()).isEqualTo(templateName);
    assertThat(templateMetaData.getMappings().keysIt()).containsExactly(IndexMapping.TYPE_MESSAGE);
    final Map<String, Object> mapping = mapper.readValue(templateMetaData.getMappings().get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
    });
    final Map<String, Object> expectedTemplate = new IndexMapping().messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer());
    assertThat(mapping).isEqualTo(expectedTemplate.get("mappings"));
    final DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
    final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
    assertThat(deleteResponse.isAcknowledged()).isTrue();
    indices.delete("index_template_test");
}
Also used : DeleteIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) IndexMapping(org.graylog2.indexer.IndexMapping) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)37 Settings (org.elasticsearch.common.settings.Settings)16 ClusterState (org.elasticsearch.cluster.ClusterState)14 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)14 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)13 MetaData (org.elasticsearch.cluster.metadata.MetaData)10 IOException (java.io.IOException)9 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)9 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)9 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)8 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)8 ShardId (org.elasticsearch.index.shard.ShardId)8 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)7 ClusterInfoService (org.elasticsearch.cluster.ClusterInfoService)7 DiskUsage (org.elasticsearch.cluster.DiskUsage)7 DevNullClusterInfo (org.elasticsearch.cluster.MockInternalClusterInfoService.DevNullClusterInfo)7 DiskThresholdSettings (org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)7 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)7 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)7