Search in sources :

Example 11 with MWMResourcePlan

use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.

the class ObjectStore method handleAlterReplace.

private WMFullResourcePlan handleAlterReplace(String name, WMNullableResourcePlan changes) throws InvalidOperationException, NoSuchObjectException, MetaException {
    // Verify that field changes are consistent with what Hive does. Note: we could handle this.
    if (changes.isSetQueryParallelism() || changes.isSetDefaultPoolPath()) {
        throw new InvalidOperationException("Cannot change values during replace.");
    }
    boolean isReplacingSpecific = changes.isSetName();
    boolean isReplacingActive = (changes.isSetStatus() && changes.getStatus() == WMResourcePlanStatus.ACTIVE);
    if (isReplacingActive == isReplacingSpecific) {
        throw new InvalidOperationException("Must specify a name, or the active plan; received " + changes.getName() + ", " + (changes.isSetStatus() ? changes.getStatus() : null));
    }
    if (name == null) {
        throw new InvalidOperationException("Invalid replace - no name specified");
    }
    MWMResourcePlan replacedPlan = isReplacingSpecific ? getMWMResourcePlan(changes.getName(), false) : getActiveMWMResourcePlan();
    MWMResourcePlan plan = getMWMResourcePlan(name, false);
    if (replacedPlan.getName().equals(plan.getName())) {
        throw new InvalidOperationException("A plan cannot replace itself");
    }
    // We will inherit the name and status from the plan we are replacing.
    String newName = replacedPlan.getName();
    int i = 0;
    String copyName = generateOldPlanName(newName, i);
    while (true) {
        MWMResourcePlan dup = getMWMResourcePlan(copyName, false, false);
        if (dup == null) {
            break;
        }
        // Note: this can still conflict with parallel transactions. We do not currently handle
        // parallel changes from two admins (by design :().
        copyName = generateOldPlanName(newName, ++i);
    }
    replacedPlan.setName(copyName);
    plan.setName(newName);
    plan.setStatus(replacedPlan.getStatus());
    replacedPlan.setStatus(MWMResourcePlan.Status.DISABLED);
    // TODO: add a configurable option to skip the history and just drop it?
    return plan.getStatus() == Status.ACTIVE ? fullFromMResourcePlan(plan) : null;
}
Also used : InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)

Example 12 with MWMResourcePlan

use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.

the class ObjectStore method dropResourcePlan.

@Override
public void dropResourcePlan(String name) throws NoSuchObjectException, MetaException {
    name = normalizeIdentifier(name);
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MWMResourcePlan.class, "name == rpname");
        query.declareParameters("java.lang.String rpname");
        query.setUnique(true);
        MWMResourcePlan resourcePlan = (MWMResourcePlan) query.execute(name);
        pm.retrieve(resourcePlan);
        if (resourcePlan == null) {
            throw new NoSuchObjectException("There is no resource plan named: " + name);
        }
        if (resourcePlan.getStatus() == Status.ACTIVE) {
            throw new MetaException("Cannot drop an active resource plan");
        }
        // First, drop all the dependencies.
        resourcePlan.setDefaultPool(null);
        pm.deletePersistentAll(resourcePlan.getTriggers());
        pm.deletePersistentAll(resourcePlan.getMappings());
        pm.deletePersistentAll(resourcePlan.getPools());
        pm.deletePersistent(resourcePlan);
        commited = commitTransaction();
    } finally {
        rollbackAndCleanup(commited, query);
    }
}
Also used : Query(javax.jdo.Query) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 13 with MWMResourcePlan

use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.

the class ObjectStore method getAllResourcePlans.

@Override
public List<WMResourcePlan> getAllResourcePlans() throws MetaException {
    List<WMResourcePlan> resourcePlans = new ArrayList();
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MWMResourcePlan.class);
        List<MWMResourcePlan> mplans = (List<MWMResourcePlan>) query.execute();
        pm.retrieveAll(mplans);
        commited = commitTransaction();
        if (mplans != null) {
            for (MWMResourcePlan mplan : mplans) {
                resourcePlans.add(fromMResourcePlan(mplan));
            }
        }
    } finally {
        rollbackAndCleanup(commited, query);
    }
    return resourcePlans;
}
Also used : Query(javax.jdo.Query) WMResourcePlan(org.apache.hadoop.hive.metastore.api.WMResourcePlan) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) ArrayList(java.util.ArrayList) 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)

Example 14 with MWMResourcePlan

use of org.apache.hadoop.hive.metastore.model.MWMResourcePlan in project hive by apache.

the class ObjectStore method deactivateActiveResourcePlan.

private void deactivateActiveResourcePlan() {
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MWMResourcePlan.class, "status == \"ACTIVE\"");
        query.setUnique(true);
        MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute();
        // We may not have an active resource plan in the start.
        if (mResourcePlan != null) {
            mResourcePlan.setStatus(Status.ENABLED);
        }
        commited = commitTransaction();
    } finally {
        rollbackAndCleanup(commited, query);
    }
}
Also used : Query(javax.jdo.Query) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan)

Example 15 with MWMResourcePlan

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

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