src/main/java/org/apache/hadoop/hdfs/server/namenode/analytics/web/NamenodeAnalyticsMethods.java
@GET
  @Path("/listOperations")
  @Produces({MediaType.TEXT_PLAIN})
  public Response listOperations() {
    try {
      final NameNodeLoader nnLoader = (NameNodeLoader) context.getAttribute(NNA_NN_LOADER);
      final ReentrantReadWriteLock queryLock =
          (ReentrantReadWriteLock) context.getAttribute(NNA_QUERY_LOCK);
      @SuppressWarnings("unchecked")
      final Map<String, BaseOperation> runningOperations =
          (Map<String, BaseOperation>) context.getAttribute(NNA_RUNNING_OPERATIONS);

      before();

      if (!nnLoader.isInit()) {
        response.setHeader("Content-Type", "application/json");
        PrintWriter writer = response.getWriter();
        writer.write("");
        writer.flush();
        writer.close();
        return Response.ok().build();
      }

      queryLock.writeLock().lock();
      try {
        String identity = request.getParameter("identity");
        String limitStr = request.getParameter("limit");
        Integer limit;
        if (limitStr == null) {
          limit = 1;
        } else {
          limit = Integer.parseInt(limitStr);
        }

        PrintWriter writer;
        if (identity == null || identity.length() == 0) {
          Set<Entry<String, BaseOperation>> entries = runningOperations.entrySet();
          StringBuilder sb = new StringBuilder();
          sb.append("Total Operations: ").append(entries.size()).append('\n');
          for (Entry<String, BaseOperation> entry : entries) {
            BaseOperation operation = entry.getValue();
            sb.append("ID: ");
            sb.append(entry.getKey());
            sb.append(", total: ");
            sb.append(operation.totalToPerform());
            sb.append(", operated: ");
            sb.append(operation.numPerformed());
            sb.append(" || owner: ");
            sb.append(operation.owner());
            sb.append(" || type: ");
            sb.append(operation.type());
            sb.append(" || query: ");
            sb.append(operation.query());
            sb.append('\n');
          }
          writer = response.getWriter();
          writer.write(sb.toString());
          writer.flush();
          writer.close();
        } else {
          BaseOperation operation = runningOperations.get(identity);
          if (operation == null) {
            throw new FileNotFoundException("Operation not found.");
          }
          StringBuilder sb = new StringBuilder();
          sb.append("Identity: ");
          sb.append(operation.identity());
          sb.append('\n');
          sb.append("Owner: ");
          sb.append(operation.owner());
          sb.append('\n');
          sb.append("Type: ");
          sb.append(operation.type());
          sb.append('\n');
          sb.append("Query: ");
          sb.append(operation.query());
          sb.append('\n');
          sb.append("Total to perform: ");
          int totalToPerform = operation.totalToPerform();
          sb.append(totalToPerform);
          sb.append('\n');
          sb.append("Total performed: ");
          int numPerformed = operation.numPerformed();
          sb.append(numPerformed);
          sb.append('\n');
          sb.append("Total left to perform: ");
          sb.append(totalToPerform - numPerformed);
          sb.append('\n');
          sb.append("Percentage done: ");
          double percentageDone = ((double) numPerformed / (double) totalToPerform) * 100.0;
          sb.append(percentageDone);
          sb.append('\n');
          sb.append("Up next: ");
          sb.append(operation.upNext());
          sb.append('\n');
          sb.append("Last (");
          sb.append(limit);
          sb.append(") performed: ");
          List<String> lastDeleted = operation.lastPerformed(limit);
          Collections.reverse(lastDeleted);
          sb.append(lastDeleted.toString());
          sb.append('\n');
          writer = response.getWriter();
          writer.write(sb.toString());
          writer.flush();
          writer.close();
        }
      } finally {
        queryLock.writeLock().unlock();
      }
      return Response.ok().build();
    } catch (RuntimeException rtex) {
      return handleException(rtex);
    } catch (Exception ex) {
      return handleException(ex);
    } finally {
      after();
    }
  }
/**
   * LISTOPERATIONS is a GET only call that only WRITER users can access. It takes an optional
   * `?identity=STRING&limit=INT` argument to see a specific operation.
   */
LISTOPERATIONS is a GET only call that only WRITER users can access. It takes an optional
`?identity=STRING&limit=INT` argument to see a specific operation.
LISTOPERATIONS is a GET only call that only WRITER users can access . It takes an optional ` ?identity = STRING&limit = INT ` argument to see a specific operation .
@GET
  @Path("/listOperations")
  @Produces({MediaType.TEXT_PLAIN})
  public Response listOperations() {
    try {
      final NameNodeLoader nnLoader = (NameNodeLoader) context.getAttribute(NNA_NN_LOADER);
      final ReentrantReadWriteLock queryLock =
          (ReentrantReadWriteLock) context.getAttribute(NNA_QUERY_LOCK);
      @SuppressWarnings("unchecked")
      final Map<String, BaseOperation> runningOperations =
          (Map<String, BaseOperation>) context.getAttribute(NNA_RUNNING_OPERATIONS);
      before();
      if (!nnLoader.isInit()) {
        response.setHeader("Content-Type", "application/json");
        PrintWriter writer = response.getWriter();
        writer.write("");
        writer.flush();
        writer.close();
        return Response.ok().build();
      }
      queryLock.writeLock().lock();
      try {
        String identity = request.getParameter("identity");
        String limitStr = request.getParameter("limit");
        Integer limit;
        if (limitStr == null) {
          limit = 1;
        } else {
          limit = Integer.parseInt(limitStr);
        }
        PrintWriter writer;
        if (identity == null || identity.length() == 0) {
          Set<Entry<String, BaseOperation>> entries = runningOperations.entrySet();
          StringBuilder sb = new StringBuilder();
          sb.append("Total Operations: ").append(entries.size()).append('\n');
          for (Entry<String, BaseOperation> entry : entries) {
            BaseOperation operation = entry.getValue();
            sb.append("ID: ");
            sb.append(entry.getKey());
            sb.append(", total: ");
            sb.append(operation.totalToPerform());
            sb.append(", operated: ");
            sb.append(operation.numPerformed());
            sb.append(" || owner: ");
            sb.append(operation.owner());
            sb.append(" || type: ");
            sb.append(operation.type());
            sb.append(" || query: ");
            sb.append(operation.query());
            sb.append('\n');
          }
          writer = response.getWriter();
          writer.write(sb.toString());
          writer.flush();
          writer.close();
        } else {
          BaseOperation operation = runningOperations.get(identity);
          if (operation == null) {
            throw new FileNotFoundException("Operation not found.");
          }
          StringBuilder sb = new StringBuilder();
          sb.append("Identity: ");
          sb.append(operation.identity());
          sb.append('\n');
          sb.append("Owner: ");
          sb.append(operation.owner());
          sb.append('\n');
          sb.append("Type: ");
          sb.append(operation.type());
          sb.append('\n');
          sb.append("Query: ");
          sb.append(operation.query());
          sb.append('\n');
          sb.append("Total to perform: ");
          int totalToPerform = operation.totalToPerform();
          sb.append(totalToPerform);
          sb.append('\n');
          sb.append("Total performed: ");
          int numPerformed = operation.numPerformed();
          sb.append(numPerformed);
          sb.append('\n');
          sb.append("Total left to perform: ");
          sb.append(totalToPerform - numPerformed);
          sb.append('\n');
          sb.append("Percentage done: ");
          double percentageDone = ((double) numPerformed / (double) totalToPerform) * 100.0;
          sb.append(percentageDone);
          sb.append('\n');
          sb.append("Up next: ");
          sb.append(operation.upNext());
          sb.append('\n');
          sb.append("Last (");
          sb.append(limit);
          sb.append(") performed: ");
          List<String> lastDeleted = operation.lastPerformed(limit);
          Collections.reverse(lastDeleted);
          sb.append(lastDeleted.toString());
          sb.append('\n');
          writer = response.getWriter();
          writer.write(sb.toString());
          writer.flush();
          writer.close();
        }
      } finally {
        queryLock.writeLock().unlock();
      }
      return Response.ok().build();
    } catch (RuntimeException rtex) {
      return handleException(rtex);
    } catch (Exception ex) {
      return handleException(ex);
    } finally {
      after();
    }
  }
@ GET @ Path ( "/listOperations" ) @ Produces ( { MediaType . TEXT_PLAIN } ) public Response listOperations ( ) { try { final NameNodeLoader nnLoader = ( NameNodeLoader ) context . getAttribute ( NNA_NN_LOADER ) ; final ReentrantReadWriteLock queryLock = ( ReentrantReadWriteLock ) context . getAttribute ( NNA_QUERY_LOCK ) ; @ SuppressWarnings ( "unchecked" ) final Map < String , BaseOperation > runningOperations = ( Map < String , BaseOperation > ) context . getAttribute ( NNA_RUNNING_OPERATIONS ) ; before ( ) ; if ( ! nnLoader . isInit ( ) ) { response . setHeader ( "Content-Type" , "application/json" ) ; PrintWriter writer = response . getWriter ( ) ; writer . write ( "" ) ; writer . flush ( ) ; writer . close ( ) ; return Response . ok ( ) . build ( ) ; } queryLock . writeLock ( ) . lock ( ) ; try { String identity = request . getParameter ( "identity" ) ; String limitStr = request . getParameter ( "limit" ) ; Integer limit ; if ( limitStr == null ) { limit = 1 ; } else { limit = Integer . parseInt ( limitStr ) ; } PrintWriter writer ; if ( identity == null || identity . length ( ) == 0 ) { Set < Entry < String , BaseOperation > > entries = runningOperations . entrySet ( ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Total Operations: " ) . append ( entries . size ( ) ) . append ( '\n' ) ; for ( Entry < String , BaseOperation > entry : entries ) { BaseOperation operation = entry . getValue ( ) ; sb . append ( "ID: " ) ; sb . append ( entry . getKey ( ) ) ; sb . append ( ", total: " ) ; sb . append ( operation . totalToPerform ( ) ) ; sb . append ( ", operated: " ) ; sb . append ( operation . numPerformed ( ) ) ; sb . append ( " || owner: " ) ; sb . append ( operation . owner ( ) ) ; sb . append ( " || type: " ) ; sb . append ( operation . type ( ) ) ; sb . append ( " || query: " ) ; sb . append ( operation . query ( ) ) ; sb . append ( '\n' ) ; } writer = response . getWriter ( ) ; writer . write ( sb . toString ( ) ) ; writer . flush ( ) ; writer . close ( ) ; } else { BaseOperation operation = runningOperations . get ( identity ) ; if ( operation == null ) { throw new FileNotFoundException ( "Operation not found." ) ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Identity: " ) ; sb . append ( operation . identity ( ) ) ; sb . append ( '\n' ) ; sb . append ( "Owner: " ) ; sb . append ( operation . owner ( ) ) ; sb . append ( '\n' ) ; sb . append ( "Type: " ) ; sb . append ( operation . type ( ) ) ; sb . append ( '\n' ) ; sb . append ( "Query: " ) ; sb . append ( operation . query ( ) ) ; sb . append ( '\n' ) ; sb . append ( "Total to perform: " ) ; int totalToPerform = operation . totalToPerform ( ) ; sb . append ( totalToPerform ) ; sb . append ( '\n' ) ; sb . append ( "Total performed: " ) ; int numPerformed = operation . numPerformed ( ) ; sb . append ( numPerformed ) ; sb . append ( '\n' ) ; sb . append ( "Total left to perform: " ) ; sb . append ( totalToPerform - numPerformed ) ; sb . append ( '\n' ) ; sb . append ( "Percentage done: " ) ; double percentageDone = ( ( double ) numPerformed / ( double ) totalToPerform ) * 100.0 ; sb . append ( percentageDone ) ; sb . append ( '\n' ) ; sb . append ( "Up next: " ) ; sb . append ( operation . upNext ( ) ) ; sb . append ( '\n' ) ; sb . append ( "Last (" ) ; sb . append ( limit ) ; sb . append ( ") performed: " ) ; List < String > lastDeleted = operation . lastPerformed ( limit ) ; Collections . reverse ( lastDeleted ) ; sb . append ( lastDeleted . toString ( ) ) ; sb . append ( '\n' ) ; writer = response . getWriter ( ) ; writer . write ( sb . toString ( ) ) ; writer . flush ( ) ; writer . close ( ) ; } } finally { queryLock . writeLock ( ) . unlock ( ) ; } return Response . ok ( ) . build ( ) ; } catch ( RuntimeException rtex ) { return handleException ( rtex ) ; } catch ( Exception ex ) { return handleException ( ex ) ; } finally { after ( ) ; } }
LISTOPERATIONS is a GET only call that only WRITER users can access.
LISTOPERATIONS is a GET only call that only WRITER users can access .