use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.
the class QTestScheduledQueryCleaner method clearScheduledQueries.
private void clearScheduledQueries(HiveConf conf) {
if (System.getenv(QTestUtil.QTEST_LEAVE_FILES) != null) {
return;
}
Set<String> scheduledQueries = ScheduledQueryCreationRegistryHook.getSchedules();
for (String name : scheduledQueries) {
ScheduledQueryMaintenanceRequest request = new ScheduledQueryMaintenanceRequest();
request.setType(ScheduledQueryMaintenanceRequestType.DROP);
ScheduledQuery schq = new ScheduledQuery();
schq.setScheduleKey(new ScheduledQueryKey(name, conf.getVar(ConfVars.HIVE_SCHEDULED_QUERIES_NAMESPACE)));
request.setScheduledQuery(schq);
try {
// propagate new conf to meta store
Hive db = Hive.get(conf);
db.getMSC().scheduledQueryMaintenance(request);
db.close(false);
} catch (Exception e) {
LOG.error("Can't remove scheduled query: " + name + " " + e.getMessage());
}
}
scheduledQueries.clear();
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.
the class ScheduledQueryAnalyzer method interpretAstNode.
private ScheduledQuery interpretAstNode(ASTNode ast) throws SemanticException {
// child0 is the schedule name
String scheduleName = ast.getChild(0).getText();
String clusterNamespace = conf.getVar(ConfVars.HIVE_SCHEDULED_QUERIES_NAMESPACE);
LOG.info("scheduled query namespace:" + clusterNamespace);
ScheduledQueryKey key = new ScheduledQueryKey(scheduleName, clusterNamespace);
ScheduledQuery ret = new ScheduledQuery(key);
// child 1..n are arguments/options/etc
for (int i = 1; i < ast.getChildCount(); i++) {
processScheduledQueryAstNode(ret, (ASTNode) ast.getChild(i));
}
return ret;
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.
the class TestScheduledQueryStatements method testExecuteImmediate.
@Test
public void testExecuteImmediate() throws ParseException, Exception {
// use a different namespace because the schq executor might be able to
// catch the new schq execution immediately
env_setup.getTestCtx().hiveConf.setVar(ConfVars.HIVE_SCHEDULED_QUERIES_NAMESPACE, "immed");
IDriver driver = createDriver();
driver.run("set role admin");
driver.run("create scheduled query immed cron '0 0 7 * * ? *' as select 1");
int cnt0 = ScheduledQueryExecutionService.getForcedScheduleCheckCount();
driver.run("alter scheduled query immed execute");
try (CloseableObjectStore os = new CloseableObjectStore(env_setup.getTestCtx().hiveConf)) {
Optional<MScheduledQuery> sq = os.getMScheduledQuery(new ScheduledQueryKey("immed", "immed"));
assertTrue(sq.isPresent());
assertThat(sq.get().getNextExecution(), Matchers.lessThanOrEqualTo((int) (System.currentTimeMillis() / 1000)));
int cnt1 = ScheduledQueryExecutionService.getForcedScheduleCheckCount();
assertNotEquals(cnt1, cnt0);
}
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.
the class TestScheduledQueryStatements method checkScheduleCreation.
private void checkScheduleCreation(String schqName, String schedule, String expectedSchedule) throws CommandProcessorException, Exception {
IDriver driver = createDriver();
driver.run("set role admin");
driver.run("create scheduled query " + schqName + " " + schedule + " as select 1 from tu");
try (CloseableObjectStore os = new CloseableObjectStore(env_setup.getTestCtx().hiveConf)) {
Optional<MScheduledQuery> sq = os.getMScheduledQuery(new ScheduledQueryKey(schqName, "hive"));
assertTrue(sq.isPresent());
assertEquals(expectedSchedule, sq.get().getSchedule());
}
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey 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
}
}
}
Aggregations