use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.
the class TestSLARegistrationGetJPAExecutor method _addRecordToSLARegistrationTable.
private void _addRecordToSLARegistrationTable(String jobId, AppType appType, Date start, Date end, String alertEvent, String alertContact) throws Exception {
SLARegistrationBean reg = new SLARegistrationBean();
reg.setId(jobId);
reg.setAppType(appType);
reg.setExpectedStart(start);
reg.setExpectedEnd(end);
reg.setAlertEvents(alertEvent);
reg.setAlertContact(alertContact);
try {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
List<JsonBean> insert = new ArrayList<JsonBean>();
insert.add(reg);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insert, null, null);
} catch (JPAExecutorException je) {
fail("Unable to insert the test sla registration record to table");
throw je;
}
}
use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.
the class TestSLASummaryGetOnRestartJPAExecutor method testSLARegistrationGet.
public void testSLARegistrationGet() throws Exception {
JPAService jpaService = Services.get().get(JPAService.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SLASummaryBean sla1 = new SLASummaryBean();
sla1.setId("jobId");
sla1.setAppName("appName");
sla1.setUser("user");
sla1.setParentId("parent");
sla1.setEventProcessed(7);
// set to 5 days back from now
sla1.setLastModifiedTime(new Date(System.currentTimeMillis() - 5 * 24 * 60 * 60 * 1000));
SLASummaryBean sla2 = new SLASummaryBean();
sla2.setId("jobId2");
sla2.setEventProcessed(6);
// set to long time back
sla2.setLastModifiedTime(sdf.parse("2009-06-03"));
List<JsonBean> insert = new ArrayList<JsonBean>();
insert.add(sla1);
insert.add(sla2);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insert, null, null);
// get all records modified in last 7 days
SLASummaryGetRecordsOnRestartJPAExecutor slaGetOnRestart = new SLASummaryGetRecordsOnRestartJPAExecutor(7);
List<SLASummaryBean> beans = jpaService.execute(slaGetOnRestart);
assertEquals(1, beans.size());
assertEquals("jobId", beans.get(0).getId());
assertEquals("appName", beans.get(0).getAppName());
assertEquals("user", beans.get(0).getUser());
assertEquals("parent", beans.get(0).getParentId());
assertEquals(7, beans.get(0).getEventProcessed());
}
use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.
the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDeleteRollBack.
public void testExecuteBatchUpdateInsertDeleteRollBack() throws Exception {
BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
job.setStatus(WorkflowJob.Status.RUNNING);
Collection<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(action1);
insertList.add(action2);
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
// Add two actions to insert list
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, job));
// set fault injection to true, so transaction is roll backed
setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
try {
executor.executeBatchInsertUpdateDelete(insertList, updateList, null);
fail("Expected exception due to commit failure but didn't get any");
} catch (Exception e) {
}
FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
// Check whether transactions are rolled back or not
WorkflowJobBean wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, job.getId());
// status should not be RUNNING
assertEquals("PREP", wfBean.getStatusStr());
WorkflowActionBean waBean;
try {
waBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action1.getId());
fail("Expected exception but didnt get any");
} catch (JPAExecutorException jpaee) {
assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
}
try {
waBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action2.getId());
fail("Expected exception but didnt get any");
} catch (JPAExecutorException jpaee) {
assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
}
}
use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.
the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDelete.
public void testExecuteBatchUpdateInsertDelete() throws Exception {
BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
// for update
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
// for insert
CoordinatorActionBean coordAction = new CoordinatorActionBean();
coordAction.setId("testCoordAction1");
JPAService jpaService = Services.get().get(JPAService.class);
// update the status
coordJob.setStatus(CoordinatorJob.Status.RUNNING);
wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
// update the list for doing bulk writes
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_MODTIME, coordJob));
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wfJob));
// insert beans
Collection<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(coordAction);
// delete beans
Collection<JsonBean> deleteList = new ArrayList<JsonBean>();
deleteList.add(wfAction);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, deleteList);
// check update after running ExecuteBatchUpdateInsertDelete
coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coordJob.getId());
assertEquals("RUNNING", coordJob.getStatusStr());
wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, wfJob.getId());
assertEquals("SUCCEEDED", wfJob.getStatusStr());
coordAction = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordAction.getId());
assertEquals("testCoordAction1", coordAction.getId());
try {
wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfJob.getId());
fail();
} catch (JPAExecutorException ex) {
assertEquals(ex.getErrorCode().toString(), "E0605");
}
}
use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.
the class SchemaCheckXCommand method execute.
@Override
protected Void execute() throws CommandException {
Connection conn = null;
LOG.info("About to check database schema");
Date startTime = new Date();
boolean problem = false;
try {
conn = DriverManager.getConnection(url, user, pass);
String catalog = conn.getCatalog();
DatabaseMetaData metaData = conn.getMetaData();
Map<String, Class<? extends JsonBean>> tableClasses = new HashMap<String, Class<? extends JsonBean>>();
tableClasses.put(getTableName(BundleActionBean.class), BundleActionBean.class);
tableClasses.put(getTableName(BundleJobBean.class), BundleJobBean.class);
tableClasses.put(getTableName(CoordinatorActionBean.class), CoordinatorActionBean.class);
tableClasses.put(getTableName(CoordinatorJobBean.class), CoordinatorJobBean.class);
tableClasses.put(getTableName(JsonSLAEvent.class), JsonSLAEvent.class);
tableClasses.put(getTableName(SLARegistrationBean.class), SLARegistrationBean.class);
tableClasses.put(getTableName(SLASummaryBean.class), SLASummaryBean.class);
tableClasses.put(getTableName(WorkflowActionBean.class), WorkflowActionBean.class);
tableClasses.put(getTableName(WorkflowJobBean.class), WorkflowJobBean.class);
boolean tableProblem = checkTables(metaData, catalog, tableClasses.keySet());
problem = problem | tableProblem;
if (!tableProblem) {
for (Map.Entry<String, Class<? extends JsonBean>> table : tableClasses.entrySet()) {
TableInfo ti = new TableInfo(table.getValue(), dbType);
boolean columnProblem = checkColumns(metaData, catalog, table.getKey(), ti.columnTypes);
problem = problem | columnProblem;
if (!columnProblem) {
boolean primaryKeyProblem = checkPrimaryKey(metaData, catalog, table.getKey(), ti.primaryKeyColumn);
problem = problem | primaryKeyProblem;
boolean indexProblem = checkIndexes(metaData, catalog, table.getKey(), ti.indexedColumns);
problem = problem | indexProblem;
}
}
}
if (problem) {
LOG.error("Database schema is BAD! Check previous error log messages for details");
} else {
LOG.info("Database schema is GOOD");
}
} catch (SQLException sqle) {
LOG.error("An Exception occurred while talking to the database: " + sqle.getMessage(), sqle);
problem = true;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
LOG.error("An Exception occurred while disconnecting from the database: " + e.getMessage(), e);
}
}
Services.get().get(SchemaCheckerService.class).updateInstrumentation(problem, startTime);
}
return null;
}
Aggregations