static <T> CosmosItemResponse<T> executeCosmosAction(Callable<? extends CosmosItemResponse<T>> action, Timer timer)
      throws CosmosException {
    CosmosItemResponse<T> cosmosItemResponse;
    Timer.Context operationTimer = null;
    try {
      if (timer != null) {
        operationTimer = timer.time();
      }
      cosmosItemResponse = action.call();
    } catch (Exception ex) {
      if (ex instanceof CosmosException) {
        throw (CosmosException) ex;
      }
      throw new RuntimeException("Exception calling action " + action, ex);
    } finally {
      if (operationTimer != null) {
        operationTimer.stop();
      }
    }
    return cosmosItemResponse;
  }
Utility method to call a Cosmos method.
@param action the action to call.
@param timer the {@link Timer} to use to time the action.  May be null.
@return the result of the action.
@throws CosmosException in case of any error while executing the Cosmos method.
ambry-cloud/src/main/java/com/github/ambry/cloud/azure/CosmosDataAccessor.java