use of org.apache.hadoop.hive.metastore.model.MWMPool in project hive by apache.
the class ObjectStore method fromMPool.
private WMPool fromMPool(MWMPool mPool, String rpName) {
WMPool result = new WMPool(rpName, mPool.getPath());
assert mPool.getAllocFraction() != null;
result.setAllocFraction(mPool.getAllocFraction());
assert mPool.getQueryParallelism() != null;
result.setQueryParallelism(mPool.getQueryParallelism());
result.setSchedulingPolicy(mPool.getSchedulingPolicy());
return result;
}
use of org.apache.hadoop.hive.metastore.model.MWMPool in project hive by apache.
the class ObjectStore method copyRpContents.
private void copyRpContents(MWMResourcePlan dest, MWMResourcePlan src) {
dest.setQueryParallelism(src.getQueryParallelism());
Map<String, MWMPool> pools = new HashMap<>();
Map<String, Set<MWMPool>> triggersToPools = new HashMap<>();
for (MWMPool copyPool : src.getPools()) {
MWMPool pool = new MWMPool(dest, copyPool.getPath(), copyPool.getAllocFraction(), copyPool.getQueryParallelism(), copyPool.getSchedulingPolicy());
pm.makePersistent(pool);
pools.put(copyPool.getPath(), pool);
if (copyPool.getTriggers() != null) {
for (MWMTrigger trigger : copyPool.getTriggers()) {
Set<MWMPool> p2t = triggersToPools.get(trigger.getName());
if (p2t == null) {
p2t = new HashSet<>();
triggersToPools.put(trigger.getName(), p2t);
}
p2t.add(pool);
pool.setTriggers(new HashSet<>());
}
}
}
dest.setPools(new HashSet<>(pools.values()));
if (src.getDefaultPool() != null) {
dest.setDefaultPool(pools.get(src.getDefaultPool().getPath()));
}
Set<MWMMapping> mappings = new HashSet<>();
for (MWMMapping copyMapping : src.getMappings()) {
MWMPool pool = null;
if (copyMapping.getPool() != null) {
pool = pools.get(copyMapping.getPool().getPath());
}
MWMMapping mapping = new MWMMapping(dest, copyMapping.getEntityType(), copyMapping.getEntityName(), pool, copyMapping.getOrdering());
pm.makePersistent(mapping);
mappings.add(mapping);
}
dest.setMappings(mappings);
Set<MWMTrigger> triggers = new HashSet<>();
for (MWMTrigger copyTrigger : src.getTriggers()) {
Set<MWMPool> p2t = triggersToPools.get(copyTrigger.getName());
if (p2t == null) {
p2t = new HashSet<>();
}
MWMTrigger trigger = new MWMTrigger(dest, copyTrigger.getName(), copyTrigger.getTriggerExpression(), copyTrigger.getActionExpression(), p2t, copyTrigger.getIsInUnmanaged());
pm.makePersistent(trigger);
for (MWMPool pool : p2t) {
pool.getTriggers().add(trigger);
}
triggers.add(trigger);
}
dest.setTriggers(triggers);
}
use of org.apache.hadoop.hive.metastore.model.MWMPool in project hive by apache.
the class ObjectStore method getPool.
private MWMPool getPool(MWMResourcePlan resourcePlan, String poolPath) throws NoSuchObjectException {
poolPath = normalizeIdentifier(poolPath);
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path == poolPath");
query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
query.setUnique(true);
MWMPool mPool = (MWMPool) query.execute(resourcePlan, poolPath);
commited = commitTransaction();
if (mPool == null) {
throw new NoSuchObjectException("Cannot find pool: " + poolPath);
}
pm.retrieve(mPool);
return mPool;
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMPool 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.MWMPool in project hive by apache.
the class ObjectStore method fullFromMResourcePlan.
private WMFullResourcePlan fullFromMResourcePlan(MWMResourcePlan mplan) {
if (mplan == null) {
return null;
}
WMFullResourcePlan rp = new WMFullResourcePlan();
rp.setPlan(fromMResourcePlan(mplan));
for (MWMPool mPool : mplan.getPools()) {
rp.addToPools(fromMPool(mPool, mplan.getName()));
for (MWMTrigger mTrigger : mPool.getTriggers()) {
rp.addToPoolTriggers(new WMPoolTrigger(mPool.getPath(), mTrigger.getName()));
}
}
for (MWMTrigger mTrigger : mplan.getTriggers()) {
rp.addToTriggers(fromMWMTrigger(mTrigger, mplan.getName()));
}
for (MWMMapping mMapping : mplan.getMappings()) {
rp.addToMappings(fromMMapping(mMapping, mplan.getName()));
}
return rp;
}
Aggregations