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;
}
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;
}
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);
}
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());
}
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);
}
Aggregations