io.camunda.exporter.tasks.incident.ElasticsearchIncidentUpdateRepository Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.exporter.tasks.incident;
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
import co.elastic.clients.elasticsearch._types.ErrorCause;
import co.elastic.clients.elasticsearch._types.Refresh;
import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import co.elastic.clients.elasticsearch.core.BulkRequest;
import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
import co.elastic.clients.elasticsearch.core.bulk.UpdateOperation;
import co.elastic.clients.elasticsearch.core.search.SourceFilter;
import co.elastic.clients.json.JsonData;
import io.camunda.exporter.tasks.incident.IncidentUpdateRepository.NoopIncidentUpdateRepository;
import io.camunda.webapps.schema.descriptors.operate.template.IncidentTemplate;
import io.camunda.webapps.schema.descriptors.operate.template.PostImporterQueueTemplate;
import io.camunda.webapps.schema.entities.operate.IncidentEntity;
import io.camunda.webapps.schema.entities.operate.IncidentState;
import io.camunda.webapps.schema.entities.operate.post.PostImporterActionType;
import io.camunda.zeebe.exporter.api.ExporterException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
public final class ElasticsearchIncidentUpdateRepository extends NoopIncidentUpdateRepository {
private static final int RETRY_COUNT = 3;
private final int partitionId;
private final String pendingUpdateAlias;
private final String incidentAlias;
private final String listViewAlias;
private final String flowNodeAlias;
private final ElasticsearchAsyncClient client;
private final Executor executor;
public ElasticsearchIncidentUpdateRepository(
final int partitionId,
final String pendingUpdateAlias,
final String incidentAlias,
final String listViewAlias,
final String flowNodeAlias,
final ElasticsearchAsyncClient client,
final Executor executor) {
this.partitionId = partitionId;
this.pendingUpdateAlias = pendingUpdateAlias;
this.incidentAlias = incidentAlias;
this.listViewAlias = listViewAlias;
this.flowNodeAlias = flowNodeAlias;
this.client = client;
this.executor = executor;
}
@Override
public CompletionStage getPendingIncidentsBatch(
final long fromPosition, final int size) {
final var query = createPendingIncidentsBatchQuery(fromPosition);
final var request = createPendingIncidentsBatchRequest(size, query);
return client
.search(request, PendingIncidentUpdate.class)
.thenApplyAsync(this::createPendingIncidentBatch, executor);
}
@Override
public CompletionStage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy