use of org.apache.hadoop.hive.metastore.model.MWMTrigger in project hive by apache.
the class ObjectStore method createWMTriggerToPoolMapping.
@Override
public void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath) throws AlreadyExistsException, 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().add(trigger);
trigger.getPools().add(pool);
pm.makePersistent(pool);
pm.makePersistent(trigger);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, (Query) null);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMTrigger in project hive by apache.
the class ObjectStore method alterWMTrigger.
@Override
public void alterWMTrigger(WMTrigger trigger) throws NoSuchObjectException, InvalidOperationException, MetaException {
boolean commited = false;
Query query = null;
try {
openTransaction();
MWMResourcePlan resourcePlan = getMWMResourcePlan(trigger.getResourcePlanName(), true);
MWMTrigger mTrigger = getTrigger(resourcePlan, trigger.getTriggerName());
// Update the object.
if (trigger.isSetTriggerExpression()) {
mTrigger.setTriggerExpression(trigger.getTriggerExpression());
}
if (trigger.isSetActionExpression()) {
mTrigger.setActionExpression(trigger.getActionExpression());
}
if (trigger.isSetIsInUnmanaged()) {
mTrigger.setIsInUnmanaged(trigger.isIsInUnmanaged());
}
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.model.MWMTrigger 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.MWMTrigger in project hive by apache.
the class ObjectStore method fromMWMTrigger.
private WMTrigger fromMWMTrigger(MWMTrigger mTrigger, String resourcePlanName) {
WMTrigger trigger = new WMTrigger();
trigger.setResourcePlanName(resourcePlanName);
trigger.setTriggerName(mTrigger.getName());
trigger.setTriggerExpression(mTrigger.getTriggerExpression());
trigger.setActionExpression(mTrigger.getActionExpression());
trigger.setIsInUnmanaged(mTrigger.getIsInUnmanaged());
return trigger;
}
use of org.apache.hadoop.hive.metastore.model.MWMTrigger 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