Search in sources :

Example 1 with IntIdentity

use of javax.jdo.identity.IntIdentity in project hive by apache.

the class ObjectStore method addMasterKey.

@Override
public int addMasterKey(String key) throws MetaException {
    LOG.debug("Begin executing addMasterKey");
    boolean committed = false;
    MMasterKey masterKey = new MMasterKey(key);
    try {
        openTransaction();
        pm.makePersistent(masterKey);
        committed = commitTransaction();
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
    }
    LOG.debug("Done executing addMasterKey with status : {}", committed);
    if (committed) {
        return ((IntIdentity) pm.getObjectId(masterKey)).getKey();
    } else {
        throw new MetaException("Failed to add master key.");
    }
}
Also used : MMasterKey(org.apache.hadoop.hive.metastore.model.MMasterKey) IntIdentity(javax.jdo.identity.IntIdentity) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 2 with IntIdentity

use of javax.jdo.identity.IntIdentity in project hive by apache.

the class ObjectStore method scheduledQueryPoll.

@Override
public ScheduledQueryPollResponse scheduledQueryPoll(ScheduledQueryPollRequest request) throws MetaException {
    ensureScheduledQueriesEnabled();
    boolean commited = false;
    ScheduledQueryPollResponse ret = new ScheduledQueryPollResponse();
    Query q = null;
    try {
        openTransaction();
        q = pm.newQuery(MScheduledQuery.class, "nextExecution <= now && enabled && clusterNamespace == ns && activeExecution == null");
        q.setSerializeRead(true);
        q.declareParameters("java.lang.Integer now, java.lang.String ns");
        q.setOrdering("nextExecution");
        int now = (int) (System.currentTimeMillis() / 1000);
        List<MScheduledQuery> results = (List<MScheduledQuery>) q.execute(now, request.getClusterNamespace());
        if (results == null || results.isEmpty()) {
            return new ScheduledQueryPollResponse();
        }
        MScheduledQuery schq = results.get(0);
        schq.setNextExecution(computeNextExecutionTime(schq.getSchedule()));
        MScheduledExecution execution = new MScheduledExecution();
        execution.setScheduledQuery(schq);
        execution.setState(QueryState.INITED);
        execution.setStartTime(now);
        execution.setLastUpdateTime(now);
        schq.setActiveExecution(execution);
        pm.makePersistent(execution);
        pm.makePersistent(schq);
        ObjectStoreTestHook.onScheduledQueryPoll();
        commited = commitTransaction();
        ret.setScheduleKey(schq.getScheduleKey());
        ret.setQuery("/* schedule: " + schq.getScheduleName() + " */" + schq.getQuery());
        ret.setUser(schq.getUser());
        int executionId = ((IntIdentity) pm.getObjectId(execution)).getKey();
        ret.setExecutionId(executionId);
    } catch (JDOException e) {
        LOG.debug("Caught jdo exception; exclusive", e);
        commited = false;
    } finally {
        rollbackAndCleanup(commited, q);
        return commited ? ret : new ScheduledQueryPollResponse();
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) IntIdentity(javax.jdo.identity.IntIdentity) 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) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) 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) JDOException(javax.jdo.JDOException)

Aggregations

IntIdentity (javax.jdo.identity.IntIdentity)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JDOException (javax.jdo.JDOException)1 Query (javax.jdo.Query)1 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)1 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 ReplicationMetricList (org.apache.hadoop.hive.metastore.api.ReplicationMetricList)1 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)1 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)1 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)1 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)1 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)1 ScheduledQueryPollResponse (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse)1 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)1 MMasterKey (org.apache.hadoop.hive.metastore.model.MMasterKey)1 MScheduledExecution (org.apache.hadoop.hive.metastore.model.MScheduledExecution)1 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)1