Search in sources :

Example 16 with MWMResourcePlan

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();
        }
    }
}
Also used : MWMPool(org.apache.hadoop.hive.metastore.model.MWMPool) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException)

Example 17 with MWMResourcePlan

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;
}
Also used : Query(javax.jdo.Query) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan)

Example 18 with MWMResourcePlan

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);
    }
}
Also used : Query(javax.jdo.Query) MWMPool(org.apache.hadoop.hive.metastore.model.MWMPool) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException)

Example 19 with MWMResourcePlan

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);
    }
}
Also used : MWMPool(org.apache.hadoop.hive.metastore.model.MWMPool) MWMTrigger(org.apache.hadoop.hive.metastore.model.MWMTrigger) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan)

Example 20 with MWMResourcePlan

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;
}
Also used : Query(javax.jdo.Query) ArrayList(java.util.ArrayList) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) MWMTrigger(org.apache.hadoop.hive.metastore.model.MWMTrigger) WMTrigger(org.apache.hadoop.hive.metastore.api.WMTrigger) MWMTrigger(org.apache.hadoop.hive.metastore.model.MWMTrigger) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan)

Aggregations

MWMResourcePlan (org.apache.hadoop.hive.metastore.model.MWMResourcePlan)22 Query (javax.jdo.Query)13 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)9 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)9 MWMPool (org.apache.hadoop.hive.metastore.model.MWMPool)8 MWMTrigger (org.apache.hadoop.hive.metastore.model.MWMTrigger)6 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4 JDOCanRetryException (javax.jdo.JDOCanRetryException)4 JDODataStoreException (javax.jdo.JDODataStoreException)4 JDOException (javax.jdo.JDOException)4 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)4 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)4 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)4 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)4 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)4 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)4 UnknownPartitionException (org.apache.hadoop.hive.metastore.api.UnknownPartitionException)4