Search in sources :

Example 11 with JsonBean

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;
    }
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JsonBean(org.apache.oozie.client.rest.JsonBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService)

Example 12 with JsonBean

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());
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) SLASummaryGetRecordsOnRestartJPAExecutor(org.apache.oozie.executor.jpa.sla.SLASummaryGetRecordsOnRestartJPAExecutor) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 13 with JsonBean

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());
    }
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 14 with JsonBean

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");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)

Example 15 with JsonBean

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;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) SchemaCheckerService(org.apache.oozie.service.SchemaCheckerService) HashMap(java.util.HashMap) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JsonSLAEvent(org.apache.oozie.client.rest.JsonSLAEvent) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) SQLException(java.sql.SQLException) BundleJobBean(org.apache.oozie.BundleJobBean) BundleActionBean(org.apache.oozie.BundleActionBean) HashMap(java.util.HashMap) Map(java.util.Map) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Aggregations

JsonBean (org.apache.oozie.client.rest.JsonBean)28 ArrayList (java.util.ArrayList)20 Date (java.util.Date)15 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)10 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)9 JPAService (org.apache.oozie.service.JPAService)9 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)7 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)7 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)6 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)5 BundleActionBean (org.apache.oozie.BundleActionBean)3 CommandException (org.apache.oozie.command.CommandException)3 IOException (java.io.IOException)2 BundleJobBean (org.apache.oozie.BundleJobBean)2 DagEngine (org.apache.oozie.DagEngine)2 DagEngineException (org.apache.oozie.DagEngineException)2 PreconditionException (org.apache.oozie.command.PreconditionException)2