@Override public CompletableFuture<BulkResult> execute(ElasticsearchWorkExecutionContext context) { return Futures.create( () -> context.getClient().submit( request ) ) .thenApply( this::generateResult ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ); }
@Override public CompletableFuture<BulkResult> execute(ElasticsearchWorkExecutionContext context) { return Futures.create( () -> context.getClient().submit( request ) ) .thenApply( this::generateResult ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ); }
@Override public final CompletableFuture<R> execute(ElasticsearchWorkExecutionContext executionContext) { return Futures.create( () -> beforeExecute( executionContext, request ) ) .thenCompose( ignored -> executionContext.getClient().submit( request ) ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ) .thenCompose( response -> handleResult( executionContext, response ) ); }
@Override public final CompletableFuture<R> execute(ElasticsearchWorkExecutionContext executionContext) { return Futures.create( () -> beforeExecute( executionContext, request ) ) .thenCompose( ignored -> executionContext.getClient().submit( request ) ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ) .thenCompose( response -> handleResult( executionContext, response ) ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, ElasticsearchResponse response) { R result; try { resultAssessor.checkSuccess( response ); result = generateResult( executionContext, response ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchRequestFailed( request, response, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, response, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, ElasticsearchResponse response) { R result; try { resultAssessor.checkSuccess( response ); result = generateResult( executionContext, response ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchRequestFailed( request, response, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, response, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, JsonObject bulkResponseItem) { R result; try { resultAssessor.checkSuccess( bulkResponseItem ); result = generateResult( executionContext, bulkResponseItem ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, JsonObject bulkResponseItem) { R result; try { resultAssessor.checkSuccess( bulkResponseItem ); result = generateResult( executionContext, bulkResponseItem ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }