common/src/main/java/bio/terra/cloudres/common/OperationAnnotator.java
/**
   * Executes the CowOperation and allows for checked exceptions.
   *
   * @param cloudOperation: the {@link CloudOperation} to operate.
   * @param cowExecute: how to execute this cloud operation
   * @param cowSerialize: how to serialize request
   * @return the result of executing the {@code cowOperation}
   */
Executes the CowOperation and allows for checked exceptions.
@param cloudOperation: the  CloudOperation to operate.
@param cowExecute: how to execute this cloud operation
@param cowSerialize: how to serialize request
@return the result of executing the  cowOperation
Executes the CowOperation and allows for checked exceptions . @param cloudOperation : the CloudOperation to operate . @param cowExecute : how to execute this cloud operation @param cowSerialize : how to serialize request @return the result of executing the cowOperation
public <R, E extends Exception> R executeCheckedCowOperation(
      CloudOperation cloudOperation, CowCheckedExecute<R, E> cowExecute, CowSerialize cowSerialize)
      throws E {
    Optional<Exception> executionException = Optional.empty();
    OptionalInt httpStatusCode = OptionalInt.empty();
    Span span = tracer.spanBuilder(cloudOperation.name()).startSpan();
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
      R response = cowExecute.execute();
      return response;
    } catch (Exception e) {
      httpStatusCode = getHttpErrorCode(e);
      executionException = Optional.of(e);
      throw e;
    } finally {
      recordOperation(
          OperationData.builder()
              .setCloudOperation(cloudOperation)
              .setDuration(stopwatch.elapsed())
              .setExecutionException(executionException)
              .setHttpStatusCode(httpStatusCode)
              .setRequestData(cowSerialize.serializeRequest())
              .build());
      span.end();
    }
  }
public < R , E extends Exception > R executeCheckedCowOperation ( CloudOperation cloudOperation , CowCheckedExecute < R , E > cowExecute , CowSerialize cowSerialize ) throws E { Optional < Exception > executionException = Optional . empty ( ) ; OptionalInt httpStatusCode = OptionalInt . empty ( ) ; Span span = tracer . spanBuilder ( cloudOperation . name ( ) ) . startSpan ( ) ; Stopwatch stopwatch = Stopwatch . createStarted ( ) ; try { R response = cowExecute . execute ( ) ; return response ; } catch ( Exception e ) { httpStatusCode = getHttpErrorCode ( e ) ; executionException = Optional . of ( e ) ; throw e ; } finally { recordOperation ( OperationData . builder ( ) . setCloudOperation ( cloudOperation ) . setDuration ( stopwatch . elapsed ( ) ) . setExecutionException ( executionException ) . setHttpStatusCode ( httpStatusCode ) . setRequestData ( cowSerialize . serializeRequest ( ) ) . build ( ) ) ; span . end ( ) ; } }
Executes the CowOperation and allows for checked exceptions.
Executes the CowOperation and allows for checked exceptions .
// TODO(yonghao): Add success/error tag for latency for us to track differentiate latency in // different scenarios. // We manually manage the span so that the expected span is still present in catch and // finally. // See warning on SpanBuilder#startScopedSpan.