Search in sources :

Example 46 with InvalidOperationException

use of org.apache.hadoop.hive.metastore.api.InvalidOperationException in project hive by apache.

the class ObjectStore method alterResourcePlan.

@Override
public WMFullResourcePlan alterResourcePlan(String name, String ns, WMNullableResourcePlan changes, boolean canActivateDisabled, boolean canDeactivate, boolean isReplace) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
    name = name == null ? null : normalizeIdentifier(name);
    if (isReplace && name == null) {
        throw new InvalidOperationException("Cannot replace without specifying the source plan");
    }
    boolean commited = false;
    Query query = null;
    // This method only returns the result when activating a resource plan.
    // We could also add a boolean flag to be specified by the caller to see
    // when the result might be needed.
    WMFullResourcePlan result = null;
    try {
        openTransaction();
        if (isReplace) {
            result = handleAlterReplace(name, ns, changes);
        } else {
            result = handleSimpleAlter(name, ns, changes, canActivateDisabled, canDeactivate);
        }
        commited = commitTransaction();
        return result;
    } catch (Exception e) {
        checkForConstraintException(e, "Resource plan name should be unique: ");
        throw e;
    } finally {
        rollbackAndCleanup(commited, query);
    }
}
Also used : WMFullResourcePlan(org.apache.hadoop.hive.metastore.api.WMFullResourcePlan) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) 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) 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 47 with InvalidOperationException

use of org.apache.hadoop.hive.metastore.api.InvalidOperationException in project hive by apache.

the class ObjectStore method handleAlterReplace.

private WMFullResourcePlan handleAlterReplace(String name, String ns, 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");
    }
    ns = getNsOrDefault(ns);
    MWMResourcePlan replacedPlan = isReplacingSpecific ? getMWMResourcePlan(changes.getName(), ns, false) : getActiveMWMResourcePlan(ns);
    MWMResourcePlan plan = getMWMResourcePlan(name, ns, false);
    if (replacedPlan.getName().equals(plan.getName())) {
        throw new InvalidOperationException("A plan cannot replace itself");
    }
    String oldNs = getNsOrDefault(replacedPlan.getNs()), newNs = getNsOrDefault(plan.getNs());
    if (!oldNs.equals(newNs)) {
        throw new InvalidOperationException("Cannot change the namespace; replacing " + oldNs + " with " + newNs);
    }
    // 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, ns, 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 48 with InvalidOperationException

use of org.apache.hadoop.hive.metastore.api.InvalidOperationException in project hive by apache.

the class ObjectStore method scheduledQueryProgress.

@Override
public void scheduledQueryProgress(ScheduledQueryProgressInfo info) throws InvalidOperationException, MetaException {
    ensureScheduledQueriesEnabled();
    boolean commited = false;
    try {
        openTransaction();
        MScheduledExecution execution = pm.getObjectById(MScheduledExecution.class, info.getScheduledExecutionId());
        if (!validateStateChange(execution.getState(), info.getState())) {
            throw new InvalidOperationException("Invalid state change: " + execution.getState() + "=>" + info.getState());
        }
        execution.setState(info.getState());
        if (info.isSetExecutorQueryId()) {
            execution.setExecutorQueryId(info.getExecutorQueryId());
        }
        if (info.isSetErrorMessage()) {
            execution.setErrorMessage(abbreviateErrorMessage(info.getErrorMessage(), 1000));
        }
        switch(info.getState()) {
            case INITED:
            case EXECUTING:
                execution.setLastUpdateTime((int) (System.currentTimeMillis() / 1000));
                break;
            case FAILED:
            case FINISHED:
            case TIMED_OUT:
                execution.setEndTime((int) (System.currentTimeMillis() / 1000));
                execution.setLastUpdateTime(null);
                execution.getScheduledQuery().setActiveExecution(null);
                break;
            default:
                throw new InvalidOperationException("invalid state: " + info.getState());
        }
        pm.makePersistent(execution);
        processScheduledQueryPolicies(info);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
}
Also used : MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException)

Example 49 with InvalidOperationException

use of org.apache.hadoop.hive.metastore.api.InvalidOperationException in project hive by apache.

the class ObjectStore method getTriggersForResourcePlan.

@Override
public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName, String ns) throws NoSuchObjectException, MetaException {
    List<WMTrigger> triggers = new ArrayList();
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        MWMResourcePlan resourcePlan;
        try {
            resourcePlan = getMWMResourcePlan(resourcePlanName, ns, 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 : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) 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) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan)

Example 50 with InvalidOperationException

use of org.apache.hadoop.hive.metastore.api.InvalidOperationException 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);
    }
    rp.setNs(resourcePlan.getNs());
    try {
        openTransaction();
        pm.makePersistent(rp);
        if (copyFromName != null) {
            String ns = getNsOrDefault(resourcePlan.getNs());
            MWMResourcePlan copyFrom = getMWMResourcePlan(copyFromName, ns, false);
            if (copyFrom == null) {
                throw new NoSuchObjectException(copyFromName + " in " + ns);
            }
            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) 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

InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)52 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)26 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)23 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)18 Table (org.apache.hadoop.hive.metastore.api.Table)17 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)16 TException (org.apache.thrift.TException)15 Partition (org.apache.hadoop.hive.metastore.api.Partition)14 FileSystem (org.apache.hadoop.fs.FileSystem)12 Path (org.apache.hadoop.fs.Path)12 List (java.util.List)10 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)10 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)10 MWMResourcePlan (org.apache.hadoop.hive.metastore.model.MWMResourcePlan)9 SQLException (java.sql.SQLException)8 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)8 Test (org.junit.Test)8 LinkedList (java.util.LinkedList)7 Database (org.apache.hadoop.hive.metastore.api.Database)7