public <T> T execute(PrivilegedExceptionAction<T> action, boolean alwaysRetry)
      throws IOException, InterruptedException {
    T result = null;

    // Retry strategy applied here due to HDFS-1058. HDFS can throw random
    // IOException about retrieving block from DN if concurrent read/write
    // on specific file is performed (see details on HDFS-1058).
    int tryNumber = 0;
    boolean succeeded = false;
    do {
      tryNumber += 1;
      try {
        result = ugi.doAs(action);
        succeeded = true;
      } catch (IOException ex) {
        if (!Strings.isNullOrEmpty(ex.getMessage()) && !ex.getMessage().contains("Cannot obtain block length for")) {
          throw ex;
        }
        if (tryNumber >= 3) {
          throw ex;
        }
        LOG.info("HDFS threw 'IOException: Cannot obtain block length' exception. " +
            "Retrying... Try #" + (tryNumber + 1));
        LOG.error("Retrying: " + ex.getMessage(),ex);
        Thread.sleep(1000);  //retry after 1 second
      }
    } while (!succeeded);
    return result;
  }
Executes action on HDFS using doAs
@param action strategy object
@param <T> result type
@return result of operation
@throws IOException
@throws InterruptedException
contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java