use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan.Status in project hive by apache.
the class ObjectStore method switchStatus.
private WMFullResourcePlan switchStatus(String name, MWMResourcePlan mResourcePlan, String status, boolean canActivateDisabled, boolean canDeactivate) throws InvalidOperationException {
Status currentStatus = mResourcePlan.getStatus();
Status newStatus = null;
try {
newStatus = Status.valueOf(status);
} catch (IllegalArgumentException e) {
throw new InvalidOperationException("Invalid status: " + status);
}
if (newStatus == currentStatus) {
return null;
}
boolean doActivate = false, doValidate = false;
switch(currentStatus) {
case // No status change for active resource plan, first activate another plan.
ACTIVE:
if (!canDeactivate) {
throw new InvalidOperationException("Resource plan " + name + " is active; activate another plan first, or disable workload management.");
}
break;
case DISABLED:
assert newStatus == Status.ACTIVE || newStatus == Status.ENABLED;
doValidate = true;
doActivate = (newStatus == Status.ACTIVE);
if (doActivate && !canActivateDisabled) {
throw new InvalidOperationException("Resource plan " + name + " is disabled and should be enabled before activation (or in the same command)");
}
break;
case ENABLED:
if (newStatus == Status.DISABLED) {
mResourcePlan.setStatus(newStatus);
// A simple case.
return null;
}
assert newStatus == Status.ACTIVE;
doActivate = true;
break;
default:
throw new AssertionError("Unexpected status " + currentStatus);
}
if (doValidate) {
// Note: this may use additional inputs from the caller, e.g. maximum query
// parallelism in the cluster based on physical constraints.
WMValidateResourcePlanResponse response = getResourcePlanErrors(mResourcePlan);
if (!response.getErrors().isEmpty()) {
throw new InvalidOperationException("ResourcePlan: " + name + " is invalid: " + response.getErrors());
}
}
if (doActivate) {
// Deactivate currently active resource plan.
deactivateActiveResourcePlan(mResourcePlan.getNs());
mResourcePlan.setStatus(newStatus);
return fullFromMResourcePlan(mResourcePlan);
} else {
mResourcePlan.setStatus(newStatus);
}
return null;
}
Aggregations