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

      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);
        }
        BaseOperation operation = runningOperations.get(identity);
        if (operation == null) {
          throw new FileNotFoundException("Operation not found.");
        }
        operation.abort();

        LOG.info("Aborted Operation: " + operation.identity());

        int totalToPerform = operation.totalToPerform();
        int numPerformed = operation.numPerformed();
        double percentageDone = ((double) numPerformed / (double) totalToPerform) * 100.0;
        List<String> lastPerformed = operation.lastPerformed(limit);
        Collections.reverse(lastPerformed);

        String sb =
            "Identity: "
                + operation.identity()
                + '\n'
                + "Owner: "
                + operation.owner()
                + '\n'
                + "Query: "
                + operation.query()
                + '\n'
                + "Total to perform: "
                + totalToPerform
                + '\n'
                + "Total performed: "
                + numPerformed
                + '\n'
                + "Total left to perform: "
                + (totalToPerform - numPerformed)
                + '\n'
                + "Percentage done: "
                + percentageDone
                + '\n'
                + "Up next: "
                + operation.upNext()
                + '\n'
                + "Last ("
                + limit
                + ") performed: "
                + lastPerformed.toString()
                + "\n\n";
        PrintWriter writer = response.getWriter();
        writer.write(sb);
        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();
    }
  }
/**
   * ABORTOPERTATION is a GET only call that only WRITER users can access. It takes a required
   * parameter `?identity=STRING` argument to specify which operation to stop.
   */
ABORTOPERTATION is a GET only call that only WRITER users can access. It takes a required
parameter `?identity=STRING` argument to specify which operation to stop.
ABORTOPERTATION is a GET only call that only WRITER users can access . It takes a required parameter ` ?identity = STRING ` argument to specify which operation to stop .
@GET
  @Path("/abortOperation")
  @Produces({MediaType.TEXT_PLAIN})
  public Response abortOperation() {
    try {
      final NameNodeLoader nnLoader = (NameNodeLoader) context.getAttribute(NNA_NN_LOADER);
      @SuppressWarnings("unchecked")
      final Map<String, BaseOperation> runningOperations =
          (Map<String, BaseOperation>) context.getAttribute(NNA_RUNNING_OPERATIONS);
      final ReentrantReadWriteLock queryLock =
          (ReentrantReadWriteLock) context.getAttribute(NNA_QUERY_LOCK);
      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);
        }
        BaseOperation operation = runningOperations.get(identity);
        if (operation == null) {
          throw new FileNotFoundException("Operation not found.");
        }
        operation.abort();
        LOG.info("Aborted Operation: " + operation.identity());
        int totalToPerform = operation.totalToPerform();
        int numPerformed = operation.numPerformed();
        double percentageDone = ((double) numPerformed / (double) totalToPerform) * 100.0;
        List<String> lastPerformed = operation.lastPerformed(limit);
        Collections.reverse(lastPerformed);
        String sb =
            "Identity: "
                + operation.identity()
                + '\n'
                + "Owner: "
                + operation.owner()
                + '\n'
                + "Query: "
                + operation.query()
                + '\n'
                + "Total to perform: "
                + totalToPerform
                + '\n'
                + "Total performed: "
                + numPerformed
                + '\n'
                + "Total left to perform: "
                + (totalToPerform - numPerformed)
                + '\n'
                + "Percentage done: "
                + percentageDone
                + '\n'
                + "Up next: "
                + operation.upNext()
                + '\n'
                + "Last ("
                + limit
                + ") performed: "
                + lastPerformed.toString()
                + "\n\n";
        PrintWriter writer = response.getWriter();
        writer.write(sb);
        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 ( "/abortOperation" ) @ Produces ( { MediaType . TEXT_PLAIN } ) public Response abortOperation ( ) { try { final NameNodeLoader nnLoader = ( NameNodeLoader ) context . getAttribute ( NNA_NN_LOADER ) ; @ SuppressWarnings ( "unchecked" ) final Map < String , BaseOperation > runningOperations = ( Map < String , BaseOperation > ) context . getAttribute ( NNA_RUNNING_OPERATIONS ) ; final ReentrantReadWriteLock queryLock = ( ReentrantReadWriteLock ) context . getAttribute ( NNA_QUERY_LOCK ) ; 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 ) ; } BaseOperation operation = runningOperations . get ( identity ) ; if ( operation == null ) { throw new FileNotFoundException ( "Operation not found." ) ; } operation . abort ( ) ; LOG . info ( "Aborted Operation: " + operation . identity ( ) ) ; int totalToPerform = operation . totalToPerform ( ) ; int numPerformed = operation . numPerformed ( ) ; double percentageDone = ( ( double ) numPerformed / ( double ) totalToPerform ) * 100.0 ; List < String > lastPerformed = operation . lastPerformed ( limit ) ; Collections . reverse ( lastPerformed ) ; String sb = "Identity: " + operation . identity ( ) + '\n' + "Owner: " + operation . owner ( ) + '\n' + "Query: " + operation . query ( ) + '\n' + "Total to perform: " + totalToPerform + '\n' + "Total performed: " + numPerformed + '\n' + "Total left to perform: " + ( totalToPerform - numPerformed ) + '\n' + "Percentage done: " + percentageDone + '\n' + "Up next: " + operation . upNext ( ) + '\n' + "Last (" + limit + ") performed: " + lastPerformed . toString ( ) + "\n\n" ; PrintWriter writer = response . getWriter ( ) ; writer . write ( sb ) ; 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 ( ) ; } }
ABORTOPERTATION is a GET only call that only WRITER users can access.
ABORTOPERTATION is a GET only call that only WRITER users can access .