code: void onStop(final Throwable exception) {
  
      LOG.log(Level.FINE, "Stop Runtime: RM status {0}", this.resourceManager.getServiceState());
  
      if (this.resourceManager.getServiceState() == Service.STATE.STARTED) {
  
        // invariant: if RM is still running then we declare success.
        try {
  
          this.reefEventHandlers.close();
  
          if (exception == null) {
            this.resourceManager.unregisterApplicationMaster(
                FinalApplicationStatus.SUCCEEDED, "Success!", this.trackingUrl);
          } else {
  
            // Note: We don't allow RM to restart our applications if it's an application level failure.
            // If applications are to be long-running, they should catch Exceptions before the REEF level
            // instead of relying on the RM restart mechanism.
            // For this case, we make a strong assumption that REEF does not allow its own unhandled Exceptions
            // to leak to this stage.
            final String failureMsg = String.format("Application failed due to:%n%s%n" +
                "With stack trace:%n%s", exception.getMessage(), ExceptionUtils.getStackTrace(exception));
  
            this.resourceManager.unregisterApplicationMaster(
                FinalApplicationStatus.FAILED, failureMsg, this.trackingUrl);
          }
  
          this.resourceManager.close();
          LOG.log(Level.FINEST, "Container ResourceManager stopped successfully");
  
        } catch (final Exception e) {
          LOG.log(Level.WARNING, "Error shutting down YARN application", e);
        }
      }
  
      if (this.nodeManager.getServiceState() == Service.STATE.STARTED) {
        try {
          this.nodeManager.close();
          LOG.log(Level.FINEST, "Container NodeManager stopped successfully");
        } catch (final IOException e) {
          LOG.log(Level.WARNING, "Error closing YARN Node Manager", e);
        }
      }
    }
docs: Shut down YARN container manager.
  This method is called from DriverRuntimeStopHandler via YARNRuntimeStopHandler.
  @param exception Exception that caused driver to stop. Can be null if there was no error.