private int handleWMServiceChange(WorkloadManager wm, boolean isActivate,
      WMFullResourcePlan appliedResourcePlan) throws HiveException {
    String name = null;
    if (isActivate) {
      name = appliedResourcePlan.getPlan().getName();
      LOG.info("Activating a new resource plan " + name + ": " + appliedResourcePlan);
    } else {
      LOG.info("Disabling workload management");
    }

    if (wm != null) {
      // Note: as per our current constraints, the behavior of two parallel activates is
      //       undefined; although only one will succeed and the other will receive exception.
      //       We need proper (semi-)transactional modifications to support this without hacks.
      ListenableFuture<Boolean> future = wm.updateResourcePlanAsync(appliedResourcePlan);
      boolean isOk = false;
      try {
        // Note: we may add an async option in future. For now, let the task fail for the user.
        future.get();
        isOk = true;
        if (isActivate) {
          LOG.info("Successfully activated resource plan " + name);
        } else {
          LOG.info("Successfully disabled workload management");
        }
      } catch (InterruptedException | ExecutionException e) {
        throw new HiveException(e);
      } finally {
        if (!isOk) {
          if (isActivate) {
            LOG.error("Failed to activate resource plan " + name);
          } else {
            LOG.error("Failed to disable workload management");
          }
          // TODO: shut down HS2?
        }
      }
    }

    TezSessionPoolManager pm = TezSessionPoolManager.getInstance();
    if (pm != null) {
      Collection<String> appliedTriggers = pm.updateTriggers(appliedResourcePlan);
      LOG.info("Updated tez session pool manager with active resource plan: {} appliedTriggers: {}", name,
          appliedTriggers);
    }

    return 0;
  }
Abstract ancestor of the enable / disable Resource Plan operations.
ql/src/java/org/apache/hadoop/hive/ql/ddl/workloadmanagement/resourceplan/alter/AbstractAlterResourcePlanStatusOperation.java