use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method handleAlterReplace.
private WMFullResourcePlan handleAlterReplace(String name, WMNullableResourcePlan changes) throws InvalidOperationException, NoSuchObjectException, MetaException {
// Verify that field changes are consistent with what Hive does. Note: we could handle this.
if (changes.isSetQueryParallelism() || changes.isSetDefaultPoolPath()) {
throw new InvalidOperationException("Cannot change values during replace.");
}
boolean isReplacingSpecific = changes.isSetName();
boolean isReplacingActive = (changes.isSetStatus() && changes.getStatus() == WMResourcePlanStatus.ACTIVE);
if (isReplacingActive == isReplacingSpecific) {
throw new InvalidOperationException("Must specify a name, or the active plan; received " + changes.getName() + ", " + (changes.isSetStatus() ? changes.getStatus() : null));
}
if (name == null) {
throw new InvalidOperationException("Invalid replace - no name specified");
}
MWMResourcePlan replacedPlan = isReplacingSpecific ? getMWMResourcePlan(changes.getName(), false) : getActiveMWMResourcePlan();
MWMResourcePlan plan = getMWMResourcePlan(name, false);
if (replacedPlan.getName().equals(plan.getName())) {
throw new InvalidOperationException("A plan cannot replace itself");
}
// We will inherit the name and status from the plan we are replacing.
String newName = replacedPlan.getName();
int i = 0;
String copyName = generateOldPlanName(newName, i);
while (true) {
MWMResourcePlan dup = getMWMResourcePlan(copyName, false, false);
if (dup == null) {
break;
}
// Note: this can still conflict with parallel transactions. We do not currently handle
// parallel changes from two admins (by design :().
copyName = generateOldPlanName(newName, ++i);
}
replacedPlan.setName(copyName);
plan.setName(newName);
plan.setStatus(replacedPlan.getStatus());
replacedPlan.setStatus(MWMResourcePlan.Status.DISABLED);
// TODO: add a configurable option to skip the history and just drop it?
return plan.getStatus() == Status.ACTIVE ? fullFromMResourcePlan(plan) : null;
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method dropResourcePlan.
@Override
public void dropResourcePlan(String name) throws NoSuchObjectException, MetaException {
name = normalizeIdentifier(name);
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MWMResourcePlan.class, "name == rpname");
query.declareParameters("java.lang.String rpname");
query.setUnique(true);
MWMResourcePlan resourcePlan = (MWMResourcePlan) query.execute(name);
pm.retrieve(resourcePlan);
if (resourcePlan == null) {
throw new NoSuchObjectException("There is no resource plan named: " + name);
}
if (resourcePlan.getStatus() == Status.ACTIVE) {
throw new MetaException("Cannot drop an active resource plan");
}
// First, drop all the dependencies.
resourcePlan.setDefaultPool(null);
pm.deletePersistentAll(resourcePlan.getTriggers());
pm.deletePersistentAll(resourcePlan.getMappings());
pm.deletePersistentAll(resourcePlan.getPools());
pm.deletePersistent(resourcePlan);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method getAllResourcePlans.
@Override
public List<WMResourcePlan> getAllResourcePlans() throws MetaException {
List<WMResourcePlan> resourcePlans = new ArrayList();
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MWMResourcePlan.class);
List<MWMResourcePlan> mplans = (List<MWMResourcePlan>) query.execute();
pm.retrieveAll(mplans);
commited = commitTransaction();
if (mplans != null) {
for (MWMResourcePlan mplan : mplans) {
resourcePlans.add(fromMResourcePlan(mplan));
}
}
} finally {
rollbackAndCleanup(commited, query);
}
return resourcePlans;
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method deactivateActiveResourcePlan.
private void deactivateActiveResourcePlan() {
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MWMResourcePlan.class, "status == \"ACTIVE\"");
query.setUnique(true);
MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute();
// We may not have an active resource plan in the start.
if (mResourcePlan != null) {
mResourcePlan.setStatus(Status.ENABLED);
}
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method createWMTrigger.
@Override
public void createWMTrigger(WMTrigger trigger) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
boolean commited = false;
try {
openTransaction();
MWMResourcePlan resourcePlan = getMWMResourcePlan(trigger.getResourcePlanName(), true);
MWMTrigger mTrigger = new MWMTrigger(resourcePlan, normalizeIdentifier(trigger.getTriggerName()), trigger.getTriggerExpression(), trigger.getActionExpression(), null, trigger.isSetIsInUnmanaged() && trigger.isIsInUnmanaged());
pm.makePersistent(mTrigger);
commited = commitTransaction();
} catch (Exception e) {
checkForConstraintException(e, "Trigger already exists, use alter: ");
throw e;
} finally {
rollbackAndCleanup(commited, (Query) null);
}
}
Aggregations