Search in sources :

Example 1 with ScheduledQueryPollRequest

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

the class TestMetastoreScheduledQueries method testCleanup.

@Test
public void testCleanup() throws Exception {
    String namespace = "cleanup";
    ObjectStore objStore = new ObjectStore();
    objStore.setConf(metaStore.getConf());
    objStore.deleteScheduledExecutions(0);
    ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", namespace));
    ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
    r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
    r.setScheduledQuery(schq);
    objStore.scheduledQueryMaintenance(r);
    Thread.sleep(1000);
    ScheduledQueryPollRequest request = new ScheduledQueryPollRequest(namespace);
    ScheduledQueryPollResponse pollResult = objStore.scheduledQueryPoll(request);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
        assertEquals(QueryState.INITED, q.getState());
    }
    Thread.sleep(1000);
    objStore.deleteScheduledExecutions(0);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        try {
            pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
            fail("The execution is expected to be deleted at this point...");
        } catch (JDOObjectNotFoundException e) {
        // expected
        }
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) PersistenceManager(javax.jdo.PersistenceManager) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 2 with ScheduledQueryPollRequest

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

the class TestMetastoreScheduledQueries method testNormalDeleteWithExec.

@Test
public void testNormalDeleteWithExec() throws Exception {
    String testCaseNS = "delwithexec";
    // insert
    ScheduledQuery schq = createScheduledQuery(createKey("del2", testCaseNS));
    ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
    r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
    r.setScheduledQuery(schq);
    client.scheduledQueryMaintenance(r);
    // wait 2 sec to have the query exection
    Thread.sleep(2000);
    // invoke poll to create a dependent execution
    ScheduledQueryPollRequest pollRequest = new ScheduledQueryPollRequest(testCaseNS);
    client.scheduledQueryPoll(pollRequest);
    // delete scheduled query
    r.setType(ScheduledQueryMaintenanceRequestType.DROP);
    client.scheduledQueryMaintenance(r);
}
Also used : ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 3 with ScheduledQueryPollRequest

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

the class TestMetastoreScheduledQueries method testOutdatedCleanup.

@Test
public void testOutdatedCleanup() throws Exception {
    String namespace = "outdatedcleanup";
    ObjectStore objStore = new ObjectStore();
    objStore.setConf(metaStore.getConf());
    objStore.deleteScheduledExecutions(0);
    ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", namespace));
    ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
    r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
    r.setScheduledQuery(schq);
    objStore.scheduledQueryMaintenance(r);
    Thread.sleep(1000);
    ScheduledQueryPollRequest request = new ScheduledQueryPollRequest(namespace);
    ScheduledQueryPollResponse pollResult = objStore.scheduledQueryPoll(request);
    // will add q1 as a query being executed
    Thread.sleep(1000);
    objStore.markScheduledExecutionsTimedOut(0);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        MScheduledExecution execution = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
        assertEquals(QueryState.TIMED_OUT, execution.getState());
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) PersistenceManager(javax.jdo.PersistenceManager) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 4 with ScheduledQueryPollRequest

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

the class MetastoreBasedScheduledQueryService method scheduledQueryPoll.

@Override
public ScheduledQueryPollResponse scheduledQueryPoll() {
    try {
        ScheduledQueryPollRequest request = new ScheduledQueryPollRequest();
        request.setClusterNamespace(getClusterNamespace());
        ScheduledQueryPollResponse resp = getMSC().scheduledQueryPoll(request);
        return resp;
    } catch (Exception e) {
        LOG.error("Exception while polling scheduled queries", e);
        return null;
    }
}
Also used : ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 5 with ScheduledQueryPollRequest

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

the class TestMetastoreScheduledQueries method testPoll.

@Test
public void testPoll() throws Exception {
    ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", "polltest"));
    ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
    r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
    r.setScheduledQuery(schq);
    client.scheduledQueryMaintenance(r);
    schq.setScheduleKey(new ScheduledQueryKey("q1", "polltestOther"));
    client.scheduledQueryMaintenance(r);
    // disabled queries are not considered
    schq.setScheduleKey(new ScheduledQueryKey("q2disabled", "polltest"));
    schq.setEnabled(false);
    client.scheduledQueryMaintenance(r);
    // do some poll requests; and wait for q1's execution
    ScheduledQueryPollRequest request = new ScheduledQueryPollRequest();
    request.setClusterNamespace("polltest");
    ScheduledQueryPollResponse pollResult = null;
    // wait for poll to hit
    for (int i = 0; i < 30; i++) {
        pollResult = client.scheduledQueryPoll(request);
        if (pollResult.isSetQuery()) {
            break;
        }
        Thread.sleep(100);
    }
    assertTrue(pollResult.isSetQuery());
    assertTrue(pollResult.isSetScheduleKey());
    assertTrue(pollResult.isSetExecutionId());
    // after reading the only scheduled query; there are no more queries to run (for 1 sec)
    ScheduledQueryPollResponse pollResult2 = client.scheduledQueryPoll(request);
    assertTrue(!pollResult2.isSetQuery());
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
        assertNotNull(q);
        assertEquals(QueryState.INITED, q.getState());
        assertTrue(q.getStartTime() <= getEpochSeconds());
        assertTrue(q.getStartTime() >= getEpochSeconds() - 1);
        assertTrue(q.getEndTime() == null);
        assertTrue(q.getLastUpdateTime() <= getEpochSeconds());
        assertTrue(q.getLastUpdateTime() >= getEpochSeconds() - 1);
    }
    // wait 1 sec
    Thread.sleep(1000);
    ScheduledQueryProgressInfo info;
    info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.EXECUTING, "executor-query-id");
    client.scheduledQueryProgress(info);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
        assertEquals(QueryState.EXECUTING, q.getState());
        assertEquals("executor-query-id", q.getExecutorQueryId());
        assertTrue(q.getLastUpdateTime() <= getEpochSeconds());
        assertTrue(q.getLastUpdateTime() >= getEpochSeconds() - 1);
    }
    // wait 1 sec
    Thread.sleep(1000);
    info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FAILED, "executor-query-id");
    info.setErrorMessage(generateLongErrorMessage());
    // info.set
    client.scheduledQueryProgress(info);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
        assertEquals(QueryState.FAILED, q.getState());
        assertEquals("executor-query-id", q.getExecutorQueryId());
        assertNull(q.getLastUpdateTime());
        assertTrue(q.getEndTime() <= getEpochSeconds());
        assertTrue(q.getEndTime() >= getEpochSeconds() - 1);
        assertTrue(q.getErrorMessage().length() < 2000);
        assertFalse(q.getErrorMessage().contains("x"));
    }
    // clustername is taken into account; this should be empty
    request.setClusterNamespace("polltestSomethingElse");
    pollResult = client.scheduledQueryPoll(request);
    assertFalse(pollResult.isSetQuery());
}
Also used : ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) PersistenceManager(javax.jdo.PersistenceManager) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryProgressInfo(org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Aggregations

ScheduledQueryPollRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest)7 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)5 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)5 ScheduledQueryPollResponse (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse)5 Test (org.junit.Test)5 ScheduledQueryKey (org.apache.hadoop.hive.metastore.api.ScheduledQueryKey)4 ScheduledQueryMaintenanceRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest)4 PersistenceManager (javax.jdo.PersistenceManager)3 ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)3 MScheduledExecution (org.apache.hadoop.hive.metastore.model.MScheduledExecution)3 ScheduledQueryProgressInfo (org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo)2 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1