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) { pool.setTriggers(new HashSet<>()); dest.setDefaultPool(pools.get(src.getDefaultPool().getPath())); MWMPool pool = null; if (copyMapping.getPool() != null) { pool = pools.get(copyMapping.getPool().getPath()); pm.makePersistent(trigger); for (MWMPool pool : p2t) { pool.getTriggers().add(trigger);
pm.retrieve(mPool); if (pool.isSetAllocFraction()) { mPool.setAllocFraction(pool.getAllocFraction()); mPool.setQueryParallelism(pool.getQueryParallelism()); throw new InvalidOperationException("Invalid scheduling policy " + policy); mPool.setSchedulingPolicy(pool.getSchedulingPolicy()); } else { mPool.setSchedulingPolicy(null); if (pool.isSetPoolPath() && !pool.getPoolPath().equals(mPool.getPath())) { moveDescendents(resourcePlan, mPool.getPath(), pool.getPoolPath()); mPool.setPath(pool.getPoolPath());
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()); result.setNs(mPool.getResourcePlan().getNs()); return result; }
private void moveDescendents(MWMResourcePlan resourcePlan, String path, String newPoolPath) throws NoSuchObjectException { if (!poolParentExists(resourcePlan, newPoolPath)) { throw new NoSuchObjectException("Pool path is invalid, the parent does not exist"); } boolean commited = false; Query query = null; openTransaction(); try { query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)"); query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath"); List<MWMPool> descPools = (List<MWMPool>) query.execute(resourcePlan, path + "."); pm.retrieveAll(descPools); for (MWMPool pool : descPools) { pool.setPath(newPoolPath + pool.getPath().substring(path.length())); } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } }
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; }
private WMMapping fromMMapping(MWMMapping mMapping, String rpName) { WMMapping result = new WMMapping(rpName, mMapping.getEntityType().toString(), mMapping.getEntityName()); if (mMapping.getPool() != null) { result.setPoolPath(mMapping.getPool().getPath()); } if (mMapping.getOrdering() != null) { result.setOrdering(mMapping.getOrdering()); } result.setNs(mMapping.getResourcePlan().getNs()); return result; }
@Override public void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath, String ns) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException { boolean commited = false; try { openTransaction(); MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, 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); } }
MWMPool defaultPool = new MWMPool(rp, "default", 1.0, defaultPoolSize, null); pm.makePersistent(defaultPool); rp.setPools(Sets.newHashSet(defaultPool));
Map<String, PoolData> poolInfo = new HashMap<>(); for (MWMPool pool : mResourcePlan.getPools()) { PoolData currentPoolData = getPoolData(poolInfo, pool.getPath()); currentPoolData.found = true; String parent = getParentPath(pool.getPath(), ""); PoolData parentPoolData = getPoolData(poolInfo, parent); parentPoolData.hasChildren = true; parentPoolData.totalChildrenAllocFraction += pool.getAllocFraction(); if (pool.getQueryParallelism() != null && pool.getQueryParallelism() < 1) { response.addToErrors("Invalid query parallelism for pool: " + pool.getPath()); } else { totalQueryParallelism += pool.getQueryParallelism(); if (!MetaStoreUtils.isValidSchedulingPolicy(pool.getSchedulingPolicy())) { response.addToErrors("Invalid scheduling policy " + pool.getSchedulingPolicy() + " for pool: " + pool.getPath());
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; }
private void moveDescendents(MWMResourcePlan resourcePlan, String path, String newPoolPath) throws NoSuchObjectException { if (!poolParentExists(resourcePlan, newPoolPath)) { throw new NoSuchObjectException("Pool path is invalid, the parent does not exist"); } boolean commited = false; Query query = null; openTransaction(); try { query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)"); query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath"); List<MWMPool> descPools = (List<MWMPool>) query.execute(resourcePlan, path + "."); pm.retrieveAll(descPools); for (MWMPool pool : descPools) { pool.setPath(newPoolPath + pool.getPath().substring(path.length())); } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } }
private WMResourcePlan fromMResourcePlan(MWMResourcePlan mplan) { if (mplan == null) { return null; } WMResourcePlan rp = new WMResourcePlan(); rp.setName(mplan.getName()); rp.setNs(mplan.getNs()); rp.setStatus(WMResourcePlanStatus.valueOf(mplan.getStatus().name())); if (mplan.getQueryParallelism() != null) { rp.setQueryParallelism(mplan.getQueryParallelism()); } if (mplan.getDefaultPool() != null) { rp.setDefaultPoolPath(mplan.getDefaultPool().getPath()); } return rp; }
@Override public void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath, String ns) throws NoSuchObjectException, InvalidOperationException, MetaException { boolean commited = false; try { openTransaction(); MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, 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); } }
@Override public void createPool(WMPool pool) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException { boolean commited = false; try { openTransaction(); MWMResourcePlan resourcePlan = getMWMResourcePlan( pool.getResourcePlanName(), pool.getNs(), true); if (!poolParentExists(resourcePlan, pool.getPoolPath())) { throw new NoSuchObjectException("Pool path is invalid, the parent does not exist"); } String policy = pool.getSchedulingPolicy(); if (!MetaStoreUtils.isValidSchedulingPolicy(policy)) { throw new InvalidOperationException("Invalid scheduling policy " + policy); } MWMPool mPool = new MWMPool(resourcePlan, pool.getPoolPath(), pool.getAllocFraction(), pool.getQueryParallelism(), policy); pm.makePersistent(mPool); commited = commitTransaction(); } catch (Exception e) { checkForConstraintException(e, "Pool already exists: "); throw e; } finally { rollbackAndCleanup(commited, (Query)null); } }
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) { pool.setTriggers(new HashSet<>()); dest.setDefaultPool(pools.get(src.getDefaultPool().getPath())); MWMPool pool = null; if (copyMapping.getPool() != null) { pool = pools.get(copyMapping.getPool().getPath()); pm.makePersistent(trigger); for (MWMPool pool : p2t) { pool.getTriggers().add(trigger);
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; }
pm.retrieve(mPool); if (pool.isSetAllocFraction()) { mPool.setAllocFraction(pool.getAllocFraction()); mPool.setQueryParallelism(pool.getQueryParallelism()); throw new InvalidOperationException("Invalid scheduling policy " + policy); mPool.setSchedulingPolicy(pool.getSchedulingPolicy()); } else { mPool.setSchedulingPolicy(null); if (pool.isSetPoolPath() && !pool.getPoolPath().equals(mPool.getPath())) { moveDescendents(resourcePlan, mPool.getPath(), pool.getPoolPath()); mPool.setPath(pool.getPoolPath());
MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, true); if (resourcePlan.getDefaultPool() != null && resourcePlan.getDefaultPool().getPath().equals(poolPath)) { throw new InvalidOperationException("Cannot drop default pool of a resource plan");
@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); } }
MWMPool defaultPool = new MWMPool(rp, "default", 1.0, defaultPoolSize, null); pm.makePersistent(defaultPool); rp.setPools(Sets.newHashSet(defaultPool));