Search in sources :

Example 6 with ScheduledQueryPollRequest

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

the class TestMetastoreScheduledQueries method testDisableInternal.

/**
 * Simulates some schq failure scenario.
 *
 * Q1 is executed correctly 1 time; but every further executions are end with failures
 * Q2 should be executed without without issues even thru Q1 will be disabled at some point
 */
public void testDisableInternal(int q1NumberOfExecutions, int seconds, String testNamespace) throws Exception {
    int q2NumberOfExecutions = seconds - 1;
    ScheduledQueryKey schqKey1 = new ScheduledQueryKey("q1", testNamespace);
    ScheduledQueryKey schqKey2 = new ScheduledQueryKey("q2", testNamespace);
    createEverySecondSchq(schqKey1);
    createEverySecondSchq(schqKey2);
    // do some polls and report failure each time
    ScheduledQueryPollRequest request = new ScheduledQueryPollRequest();
    request.setClusterNamespace(testNamespace);
    ScheduledQueryPollResponse pollResult = null;
    int idx1 = 0;
    int idx2 = 0;
    for (int i = 0; i < seconds * 10 + 9; i++) {
        pollResult = client.scheduledQueryPoll(request);
        if (pollResult.isSetQuery()) {
            if (pollResult.getScheduleKey().equals(schqKey1)) {
                idx1++;
                if (idx1 == 1) {
                    ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FINISHED, "executor-query-id");
                    client.scheduledQueryProgress(info);
                } else {
                    ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FAILED, "executor-query-id");
                    info.setErrorMessage("some issue happened");
                    client.scheduledQueryProgress(info);
                }
                ScheduledQuery schq = client.getScheduledQuery(pollResult.getScheduleKey());
                if (idx1 > q1NumberOfExecutions) {
                    fail("unexpected execution of q1 happened");
                }
                if (idx1 == q1NumberOfExecutions) {
                    assertFalse("Scheduled query q1 must be disabled at this point", schq.isEnabled());
                } else {
                    assertTrue("Scheduled query q1 must be enabled at this point", schq.isEnabled());
                }
            }
            if (pollResult.getScheduleKey().equals(schqKey2)) {
                idx2++;
                ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FINISHED, "executor-query-id");
                client.scheduledQueryProgress(info);
                ScheduledQuery schq = client.getScheduledQuery(pollResult.getScheduleKey());
                assertTrue("Scheduled query q2 must be enabled", schq.isEnabled());
            }
        }
        Thread.sleep(100);
    }
    if (idx1 != q1NumberOfExecutions) {
        fail("expected " + q1NumberOfExecutions + " execution of q1; only " + idx1 + " happened");
    }
    if (idx2 < q2NumberOfExecutions) {
        fail("at least " + q2NumberOfExecutions + " expected for q2");
    }
}
Also used : ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryProgressInfo(org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery)

Example 7 with ScheduledQueryPollRequest

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

the class TestMetastoreScheduledQueries method testDisabledPoll.

@Test
public void testDisabledPoll() throws MetaException, TException {
    try {
        MetastoreConf.setBoolVar(metaStore.getConf(), ConfVars.SCHEDULED_QUERIES_ENABLED, false);
        ObjectStore objStore = new ObjectStore();
        objStore.setConf(metaStore.getConf());
        thrown.expect(MetaException.class);
        thrown.expectMessage(Matchers.contains(ConfVars.SCHEDULED_QUERIES_ENABLED.getVarname()));
        objStore.scheduledQueryPoll(new ScheduledQueryPollRequest());
    } finally {
        MetastoreConf.setBoolVar(metaStore.getConf(), ConfVars.SCHEDULED_QUERIES_ENABLED, true);
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) 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