Search in sources :

Example 1 with IndexTemplate

use of org.apache.skywalking.library.elasticsearch.response.IndexTemplate in project incubator-skywalking by apache.

the class StorageEsInstaller method isExists.

@Override
protected boolean isExists(Model model) {
    ElasticSearchClient esClient = (ElasticSearchClient) client;
    String tableName = IndexController.INSTANCE.getTableName(model);
    IndexController.LogicIndicesRegister.registerRelation(model.getName(), tableName);
    if (!model.isTimeSeries()) {
        boolean exist = esClient.isExistsIndex(tableName);
        if (exist) {
            Mappings historyMapping = esClient.getIndex(tableName).map(Index::getMappings).orElseGet(Mappings::new);
            structures.putStructure(tableName, historyMapping);
            exist = structures.containsStructure(tableName, createMapping(model));
        }
        return exist;
    }
    boolean templateExists = esClient.isExistsTemplate(tableName);
    final Optional<IndexTemplate> template = esClient.getTemplate(tableName);
    boolean lastIndexExists = esClient.isExistsIndex(TimeSeriesUtils.latestWriteIndexName(model));
    if ((templateExists && !template.isPresent()) || (!templateExists && template.isPresent())) {
        throw new Error("[Bug warning] ElasticSearch client query template result is not consistent. " + "Please file an issue to Apache SkyWalking.(https://github.com/apache/skywalking/issues)");
    }
    boolean exist = templateExists && lastIndexExists;
    if (exist) {
        structures.putStructure(tableName, template.get().getMappings());
        exist = structures.containsStructure(tableName, createMapping(model));
    }
    return exist;
}
Also used : Mappings(org.apache.skywalking.library.elasticsearch.response.Mappings) IndexTemplate(org.apache.skywalking.library.elasticsearch.response.IndexTemplate) ElasticSearchClient(org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient)

Example 2 with IndexTemplate

use of org.apache.skywalking.library.elasticsearch.response.IndexTemplate in project skywalking by apache.

the class StorageEsInstaller method isExists.

@Override
protected boolean isExists(Model model) {
    ElasticSearchClient esClient = (ElasticSearchClient) client;
    String tableName = IndexController.INSTANCE.getTableName(model);
    IndexController.LogicIndicesRegister.registerRelation(model.getName(), tableName);
    if (!model.isTimeSeries()) {
        boolean exist = esClient.isExistsIndex(tableName);
        if (exist) {
            Mappings historyMapping = esClient.getIndex(tableName).map(Index::getMappings).orElseGet(Mappings::new);
            structures.putStructure(tableName, historyMapping);
            exist = structures.containsStructure(tableName, createMapping(model));
        }
        return exist;
    }
    boolean templateExists = esClient.isExistsTemplate(tableName);
    final Optional<IndexTemplate> template = esClient.getTemplate(tableName);
    boolean lastIndexExists = esClient.isExistsIndex(TimeSeriesUtils.latestWriteIndexName(model));
    if ((templateExists && !template.isPresent()) || (!templateExists && template.isPresent())) {
        throw new Error("[Bug warning] ElasticSearch client query template result is not consistent. " + "Please file an issue to Apache SkyWalking.(https://github.com/apache/skywalking/issues)");
    }
    boolean exist = templateExists && lastIndexExists;
    if (exist) {
        structures.putStructure(tableName, template.get().getMappings());
        exist = structures.containsStructure(tableName, createMapping(model));
    }
    return exist;
}
Also used : Mappings(org.apache.skywalking.library.elasticsearch.response.Mappings) IndexTemplate(org.apache.skywalking.library.elasticsearch.response.IndexTemplate) ElasticSearchClient(org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient)

Example 3 with IndexTemplate

use of org.apache.skywalking.library.elasticsearch.response.IndexTemplate in project skywalking by apache.

the class V78IndexTemplatesDeserializer method deserialize.

@Override
public IndexTemplates deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    while (!p.nextFieldName(new SerializedString("index_templates"))) {
        if (p.currentName() == null) {
            return new IndexTemplates(Collections.emptyMap());
        }
        p.skipChildren();
    }
    if (p.nextToken() != JsonToken.START_ARRAY) {
        throw new UnsupportedOperationException("this might be a new ElasticSearch version and we don't support yet");
    }
    final JsonNode array = p.getCodec().readTree(p);
    final List<IndexTemplate> templates = new ArrayList<>(array.size());
    for (final JsonNode node : array) {
        final String name = node.get("name").asText();
        if (Strings.isNullOrEmpty(name)) {
            log.error("index template without a name: {}", node);
            continue;
        }
        final JsonNode indexTemplateNode = node.get("index_template");
        if (indexTemplateNode == null) {
            log.error("index template without index_template: {}", node);
            continue;
        }
        final IndexTemplateWrapper wrapper = p.getCodec().treeToValue(indexTemplateNode, IndexTemplateWrapper.class);
        wrapper.getTemplate().setName(name);
        wrapper.getTemplate().setIndexPatterns(wrapper.getIndexPatterns());
        templates.add(wrapper.getTemplate());
    }
    final Map<String, IndexTemplate> templateMap = templates.stream().collect(toMap(IndexTemplate::getName, Function.identity()));
    return new IndexTemplates(templateMap);
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) IndexTemplate(org.apache.skywalking.library.elasticsearch.response.IndexTemplate) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) SerializedString(com.fasterxml.jackson.core.io.SerializedString) IndexTemplates(org.apache.skywalking.library.elasticsearch.response.IndexTemplates)

Example 4 with IndexTemplate

use of org.apache.skywalking.library.elasticsearch.response.IndexTemplate in project skywalking by apache.

the class ITElasticSearchTest method testTemplate.

@Test
public void testTemplate() {
    final String name = "test-template";
    final TemplateClient templateClient = client.templates();
    final ImmutableMap<String, Object> properties = ImmutableMap.of("metric_table", ImmutableMap.of("type", "keyword"), "service_id", ImmutableMap.of("type", "keyword"));
    final Mappings.Source sourceConf = new Mappings.Source();
    sourceConf.getExcludes().add("test");
    final Mappings mappings = Mappings.builder().type("_doc").properties(properties).source(sourceConf).build();
    assertThat(templateClient.createOrUpdate(name, ImmutableMap.of(), mappings, 0)).isTrue();
    assertThat(templateClient.exists(name)).isTrue();
    assertThat(templateClient.get(name)).isPresent().map(IndexTemplate::getMappings).map(Mappings::getProperties).hasValue(mappings.getProperties());
    assertThat(templateClient.get(name)).isPresent().map(IndexTemplate::getMappings).map(Mappings::getSource).map(Mappings.Source::getExcludes).hasValue(mappings.getSource().getExcludes());
}
Also used : Mappings(org.apache.skywalking.library.elasticsearch.response.Mappings) IndexTemplate(org.apache.skywalking.library.elasticsearch.response.IndexTemplate) TemplateClient(org.apache.skywalking.library.elasticsearch.client.TemplateClient) Test(org.junit.Test)

Example 5 with IndexTemplate

use of org.apache.skywalking.library.elasticsearch.response.IndexTemplate in project incubator-skywalking by apache.

the class V78IndexTemplatesDeserializer method deserialize.

@Override
public IndexTemplates deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    while (!p.nextFieldName(new SerializedString("index_templates"))) {
        if (p.currentName() == null) {
            return new IndexTemplates(Collections.emptyMap());
        }
        p.skipChildren();
    }
    if (p.nextToken() != JsonToken.START_ARRAY) {
        throw new UnsupportedOperationException("this might be a new ElasticSearch version and we don't support yet");
    }
    final JsonNode array = p.getCodec().readTree(p);
    final List<IndexTemplate> templates = new ArrayList<>(array.size());
    for (final JsonNode node : array) {
        final String name = node.get("name").asText();
        if (Strings.isNullOrEmpty(name)) {
            log.error("index template without a name: {}", node);
            continue;
        }
        final JsonNode indexTemplateNode = node.get("index_template");
        if (indexTemplateNode == null) {
            log.error("index template without index_template: {}", node);
            continue;
        }
        final IndexTemplateWrapper wrapper = p.getCodec().treeToValue(indexTemplateNode, IndexTemplateWrapper.class);
        wrapper.getTemplate().setName(name);
        wrapper.getTemplate().setIndexPatterns(wrapper.getIndexPatterns());
        templates.add(wrapper.getTemplate());
    }
    final Map<String, IndexTemplate> templateMap = templates.stream().collect(toMap(IndexTemplate::getName, Function.identity()));
    return new IndexTemplates(templateMap);
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) IndexTemplate(org.apache.skywalking.library.elasticsearch.response.IndexTemplate) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) SerializedString(com.fasterxml.jackson.core.io.SerializedString) IndexTemplates(org.apache.skywalking.library.elasticsearch.response.IndexTemplates)

Aggregations

IndexTemplate (org.apache.skywalking.library.elasticsearch.response.IndexTemplate)6 Mappings (org.apache.skywalking.library.elasticsearch.response.Mappings)4 SerializedString (com.fasterxml.jackson.core.io.SerializedString)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 TemplateClient (org.apache.skywalking.library.elasticsearch.client.TemplateClient)2 IndexTemplates (org.apache.skywalking.library.elasticsearch.response.IndexTemplates)2 ElasticSearchClient (org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient)2 Test (org.junit.Test)2