use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method createResourcePlan.
@Override
public void createResourcePlan(WMResourcePlan resourcePlan, String copyFromName, int defaultPoolSize) throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException {
boolean commited = false;
String rpName = normalizeIdentifier(resourcePlan.getName());
if (rpName.isEmpty()) {
throw new InvalidObjectException("Resource name cannot be empty.");
}
MWMResourcePlan rp = null;
if (copyFromName == null) {
Integer queryParallelism = null;
if (resourcePlan.isSetQueryParallelism()) {
queryParallelism = resourcePlan.getQueryParallelism();
if (queryParallelism <= 0) {
throw new InvalidObjectException("Query parallelism should be positive.");
}
}
rp = new MWMResourcePlan(rpName, queryParallelism, Status.DISABLED);
} else {
rp = new MWMResourcePlan(rpName, null, Status.DISABLED);
}
try {
openTransaction();
pm.makePersistent(rp);
if (copyFromName != null) {
MWMResourcePlan copyFrom = getMWMResourcePlan(copyFromName, false);
if (copyFrom == null) {
throw new NoSuchObjectException(copyFromName);
}
copyRpContents(rp, copyFrom);
} else {
// all the RawStore-s. Right now there's no method to create a pool.
if (defaultPoolSize > 0) {
MWMPool defaultPool = new MWMPool(rp, "default", 1.0, defaultPoolSize, null);
pm.makePersistent(defaultPool);
rp.setPools(Sets.newHashSet(defaultPool));
rp.setDefaultPool(defaultPool);
}
}
commited = commitTransaction();
} catch (InvalidOperationException e) {
throw new RuntimeException(e);
} catch (Exception e) {
checkForConstraintException(e, "Resource plan already exists: ");
throw e;
} finally {
if (!commited) {
rollbackTransaction();
}
}
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method getActiveMWMResourcePlan.
private MWMResourcePlan getActiveMWMResourcePlan() throws MetaException {
boolean commited = false;
Query query = null;
MWMResourcePlan result = null;
try {
openTransaction();
query = pm.newQuery(MWMResourcePlan.class, "status == activeStatus");
query.declareParameters("java.lang.String activeStatus");
query.setUnique(true);
result = (MWMResourcePlan) query.execute(Status.ACTIVE.toString());
pm.retrieve(result);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return result;
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method dropWMPool.
@Override
public void dropWMPool(String resourcePlanName, String poolPath) throws NoSuchObjectException, InvalidOperationException, MetaException {
poolPath = normalizeIdentifier(poolPath);
boolean commited = false;
Query query = null;
try {
openTransaction();
MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, true);
if (resourcePlan.getDefaultPool() != null && resourcePlan.getDefaultPool().getPath().equals(poolPath)) {
throw new InvalidOperationException("Cannot drop default pool of a resource plan");
}
if (poolHasChildren(resourcePlan, poolPath)) {
throw new InvalidOperationException("Pool has children cannot drop.");
}
query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)");
query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
if (query.deletePersistentAll(resourcePlan, poolPath) != 1) {
throw new NoSuchObjectException("Cannot delete pool: " + poolPath);
}
commited = commitTransaction();
} catch (Exception e) {
if (getConstraintException(e) != null) {
throw new InvalidOperationException("Please remove all mappings for this pool.");
}
throw e;
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method dropWMTriggerToPoolMapping.
@Override
public void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath) throws NoSuchObjectException, InvalidOperationException, MetaException {
boolean commited = false;
try {
openTransaction();
MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, true);
MWMPool pool = getPool(resourcePlan, poolPath);
MWMTrigger trigger = getTrigger(resourcePlan, triggerName);
pool.getTriggers().remove(trigger);
trigger.getPools().remove(pool);
pm.makePersistent(pool);
pm.makePersistent(trigger);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, (Query) null);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.
the class ObjectStore method getTriggersForResourcePlan.
@Override
public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName) throws NoSuchObjectException, MetaException {
List<WMTrigger> triggers = new ArrayList();
boolean commited = false;
Query query = null;
try {
openTransaction();
MWMResourcePlan resourcePlan;
try {
resourcePlan = getMWMResourcePlan(resourcePlanName, false);
} catch (InvalidOperationException e) {
// Should not happen, edit check is false.
throw new RuntimeException(e);
}
query = pm.newQuery(MWMTrigger.class, "resourcePlan == rp");
query.declareParameters("MWMResourcePlan rp");
List<MWMTrigger> mTriggers = (List<MWMTrigger>) query.execute(resourcePlan);
pm.retrieveAll(mTriggers);
commited = commitTransaction();
if (mTriggers != null) {
for (MWMTrigger trigger : mTriggers) {
triggers.add(fromMWMTrigger(trigger, resourcePlanName));
}
}
} finally {
rollbackAndCleanup(commited, query);
}
return triggers;
}
Aggregations