Search in sources :

Example 1 with RetryUtil

use of com.netflix.conductor.common.utils.RetryUtil in project conductor by Netflix.

the class ElasticSearchRestDAOV5 method updateWorkflow.

@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
    if (keys.length != values.length) {
        throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Number of keys and values do not match");
    }
    long startTime = Instant.now().toEpochMilli();
    UpdateRequest request = new UpdateRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId);
    Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
    request.doc(source);
    logger.debug("Updating workflow {} with {}", workflowInstanceId, source);
    new RetryUtil<UpdateResponse>().retryOnException(() -> {
        try {
            return elasticSearchClient.update(request);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }, null, null, RETRY_COUNT, "Updating workflow document: " + workflowInstanceId, "updateWorkflow");
    long endTime = Instant.now().toEpochMilli();
    logger.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
    Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
    Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) GetResponse(org.elasticsearch.action.get.GetResponse) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) Task(com.netflix.conductor.common.metadata.tasks.Task) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) StringUtils(org.apache.commons.lang3.StringUtils) NByteArrayEntity(org.apache.http.nio.entity.NByteArrayEntity) EntityUtils(org.apache.http.util.EntityUtils) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) PreDestroy(javax.annotation.PreDestroy) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) ZoneOffset(java.time.ZoneOffset) NStringEntity(org.apache.http.nio.entity.NStringEntity) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) MapType(com.fasterxml.jackson.databind.type.MapType) SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) GetRequest(org.elasticsearch.action.get.GetRequest) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TimeZone(java.util.TimeZone) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(org.elasticsearch.client.Response) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IntStream(java.util.stream.IntStream) RestClient(org.elasticsearch.client.RestClient) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) XContentType(org.elasticsearch.common.xcontent.XContentType) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SearchRequest(org.elasticsearch.action.search.SearchRequest) Singleton(javax.inject.Singleton) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) IndexResponse(org.elasticsearch.action.index.IndexResponse) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TaskSummary(com.netflix.conductor.common.run.TaskSummary) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) IndexDAO(com.netflix.conductor.dao.IndexDAO) ElasticSearchConfiguration(com.netflix.conductor.elasticsearch.ElasticSearchConfiguration) Collections(java.util.Collections) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) InputStream(java.io.InputStream) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IOException(java.io.IOException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with RetryUtil

use of com.netflix.conductor.common.utils.RetryUtil in project conductor by Netflix.

the class ElasticSearchRestDAOV6 method updateWorkflow.

@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
    if (keys.length != values.length) {
        throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Number of keys and values do not match");
    }
    long startTime = Instant.now().toEpochMilli();
    String docType = StringUtils.isBlank(docTypeOverride) ? WORKFLOW_DOC_TYPE : docTypeOverride;
    UpdateRequest request = new UpdateRequest(workflowIndexName, docType, workflowInstanceId);
    Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
    request.doc(source);
    logger.debug("Updating workflow {} with {}", workflowInstanceId, source);
    new RetryUtil<UpdateResponse>().retryOnException(() -> {
        try {
            return elasticSearchClient.update(request);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }, null, null, RETRY_COUNT, "Updating workflow document: " + workflowInstanceId, "updateWorkflow");
    long endTime = Instant.now().toEpochMilli();
    logger.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
    Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
    Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) GetResponse(org.elasticsearch.action.get.GetResponse) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) Task(com.netflix.conductor.common.metadata.tasks.Task) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) StringUtils(org.apache.commons.lang3.StringUtils) NByteArrayEntity(org.apache.http.nio.entity.NByteArrayEntity) EntityUtils(org.apache.http.util.EntityUtils) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) PreDestroy(javax.annotation.PreDestroy) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) NStringEntity(org.apache.http.nio.entity.NStringEntity) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) MapType(com.fasterxml.jackson.databind.type.MapType) SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) GetRequest(org.elasticsearch.action.get.GetRequest) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TimeZone(java.util.TimeZone) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(org.elasticsearch.client.Response) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IntStream(java.util.stream.IntStream) RestClient(org.elasticsearch.client.RestClient) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) XContentType(org.elasticsearch.common.xcontent.XContentType) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SearchRequest(org.elasticsearch.action.search.SearchRequest) Singleton(javax.inject.Singleton) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) IndexResponse(org.elasticsearch.action.index.IndexResponse) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TaskSummary(com.netflix.conductor.common.run.TaskSummary) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) IndexDAO(com.netflix.conductor.dao.IndexDAO) ElasticSearchConfiguration(com.netflix.conductor.elasticsearch.ElasticSearchConfiguration) Collections(java.util.Collections) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) InputStream(java.io.InputStream) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IOException(java.io.IOException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 3 with RetryUtil

use of com.netflix.conductor.common.utils.RetryUtil in project conductor by Netflix.

the class ElasticSearchRestDAOV7 method updateWorkflow.

@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
    if (keys.length != values.length) {
        throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Number of keys and values do not match");
    }
    long startTime = Instant.now().toEpochMilli();
    UpdateRequest request = new UpdateRequest(workflowIndexName, workflowInstanceId);
    Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
    request.doc(source);
    logger.debug("Updating workflow {} with {}", workflowInstanceId, source);
    new RetryUtil<UpdateResponse>().retryOnException(() -> {
        try {
            return elasticSearchClient.update(request, RequestOptions.DEFAULT);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }, null, null, RETRY_COUNT, "Updating workflow document: " + workflowInstanceId, "updateWorkflow");
    long endTime = Instant.now().toEpochMilli();
    logger.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
    Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
    Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) Task(com.netflix.conductor.common.metadata.tasks.Task) org.elasticsearch.client(org.elasticsearch.client) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) StringUtils(org.apache.commons.lang3.StringUtils) NByteArrayEntity(org.apache.http.nio.entity.NByteArrayEntity) EntityUtils(org.apache.http.util.EntityUtils) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) PreDestroy(javax.annotation.PreDestroy) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) NStringEntity(org.apache.http.nio.entity.NStringEntity) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) MapType(com.fasterxml.jackson.databind.type.MapType) SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) GetRequest(org.elasticsearch.action.get.GetRequest) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TimeZone(java.util.TimeZone) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IntStream(java.util.stream.IntStream) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) XContentType(org.elasticsearch.common.xcontent.XContentType) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SearchRequest(org.elasticsearch.action.search.SearchRequest) Singleton(javax.inject.Singleton) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) IndexResponse(org.elasticsearch.action.index.IndexResponse) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) TaskSummary(com.netflix.conductor.common.run.TaskSummary) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) IndexDAO(com.netflix.conductor.dao.IndexDAO) ElasticSearchConfiguration(com.netflix.conductor.elasticsearch.ElasticSearchConfiguration) Collections(java.util.Collections) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) InputStream(java.io.InputStream) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IOException(java.io.IOException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 4 with RetryUtil

use of com.netflix.conductor.common.utils.RetryUtil in project conductor by Netflix.

the class ElasticSearchDAOV5 method updateWorkflow.

@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
    if (keys.length != values.length) {
        throw new ApplicationException(Code.INVALID_INPUT, "Number of keys and values do not match");
    }
    long startTime = Instant.now().toEpochMilli();
    UpdateRequest request = new UpdateRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId);
    Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
    request.doc(source);
    logger.debug("Updating workflow {} in elasticsearch index: {}", workflowInstanceId, indexName);
    new RetryUtil<>().retryOnException(() -> elasticSearchClient.update(request).actionGet(), null, null, RETRY_COUNT, "Updating index for doc_type workflow", "updateWorkflow");
    long endTime = Instant.now().toEpochMilli();
    logger.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
    Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
    Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
Also used : Arrays(java.util.Arrays) GetResponse(org.elasticsearch.action.get.GetResponse) SortBuilders(org.elasticsearch.search.sort.SortBuilders) SearchHits(org.elasticsearch.search.SearchHits) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) StringUtils(org.apache.commons.lang3.StringUtils) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) PreDestroy(javax.annotation.PreDestroy) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Workflow(com.netflix.conductor.common.run.Workflow) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) ZoneOffset(java.time.ZoneOffset) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) MapType(com.fasterxml.jackson.databind.type.MapType) Code(com.netflix.conductor.core.execution.ApplicationException.Code) SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) GetRequest(org.elasticsearch.action.get.GetRequest) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TimeZone(java.util.TimeZone) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) IntStream(java.util.stream.IntStream) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) XContentType(org.elasticsearch.common.xcontent.XContentType) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Singleton(javax.inject.Singleton) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) ArrayList(java.util.ArrayList) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) Strings(org.elasticsearch.common.Strings) Inject(javax.inject.Inject) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) StreamSupport(java.util.stream.StreamSupport) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TaskSummary(com.netflix.conductor.common.run.TaskSummary) Client(org.elasticsearch.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexDAO(com.netflix.conductor.dao.IndexDAO) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) ElasticSearchConfiguration(com.netflix.conductor.elasticsearch.ElasticSearchConfiguration) InputStream(java.io.InputStream) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 5 with RetryUtil

use of com.netflix.conductor.common.utils.RetryUtil in project conductor by Netflix.

the class ElasticSearchDAOV6 method updateWorkflow.

@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
    if (keys.length != values.length) {
        throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Number of keys and values do not match");
    }
    long startTime = Instant.now().toEpochMilli();
    UpdateRequest request = new UpdateRequest(workflowIndexName, WORKFLOW_DOC_TYPE, workflowInstanceId);
    Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
    request.doc(source);
    LOGGER.debug("Updating workflow {} in elasticsearch index: {}", workflowInstanceId, workflowIndexName);
    new RetryUtil<>().retryOnException(() -> elasticSearchClient.update(request).actionGet(), null, null, RETRY_COUNT, "Updating index for doc_type workflow", "updateWorkflow");
    long endTime = Instant.now().toEpochMilli();
    LOGGER.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
    Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
    Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) SortBuilders(org.elasticsearch.search.sort.SortBuilders) SearchHits(org.elasticsearch.search.SearchHits) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) StringUtils(org.apache.commons.lang3.StringUtils) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) PreDestroy(javax.annotation.PreDestroy) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Workflow(com.netflix.conductor.common.run.Workflow) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) MapType(com.fasterxml.jackson.databind.type.MapType) SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) GetRequest(org.elasticsearch.action.get.GetRequest) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TimeZone(java.util.TimeZone) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) IntStream(java.util.stream.IntStream) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) XContentType(org.elasticsearch.common.xcontent.XContentType) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) Strings(org.elasticsearch.common.Strings) Inject(javax.inject.Inject) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) TaskSummary(com.netflix.conductor.common.run.TaskSummary) Client(org.elasticsearch.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) Monitors(com.netflix.conductor.metrics.Monitors) TimeUnit(java.util.concurrent.TimeUnit) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexDAO(com.netflix.conductor.dao.IndexDAO) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) ElasticSearchConfiguration(com.netflix.conductor.elasticsearch.ElasticSearchConfiguration) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

RetryUtil (com.netflix.conductor.common.utils.RetryUtil)6 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MapType (com.fasterxml.jackson.databind.type.MapType)5 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)5 Trace (com.netflix.conductor.annotations.Trace)5 EventExecution (com.netflix.conductor.common.metadata.events.EventExecution)5 Task (com.netflix.conductor.common.metadata.tasks.Task)5 TaskExecLog (com.netflix.conductor.common.metadata.tasks.TaskExecLog)5 SearchResult (com.netflix.conductor.common.run.SearchResult)5 TaskSummary (com.netflix.conductor.common.run.TaskSummary)5 Workflow (com.netflix.conductor.common.run.Workflow)5 WorkflowSummary (com.netflix.conductor.common.run.WorkflowSummary)5 Message (com.netflix.conductor.core.events.queue.Message)5 IndexDAO (com.netflix.conductor.dao.IndexDAO)5 ElasticSearchConfiguration (com.netflix.conductor.elasticsearch.ElasticSearchConfiguration)5 Monitors (com.netflix.conductor.metrics.Monitors)5 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Instant (java.time.Instant)5