Search in sources :

Example 1 with SLASummaryQuery

use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.

the class SLACalculatorMemory method updateDBSlaExpectedValues.

@SuppressWarnings("rawtypes")
private void updateDBSlaExpectedValues(SLACalcStatus slaCalc, List<UpdateEntry> updateList) throws JPAExecutorException {
    slaCalc.setLastModifiedTime(new Date());
    updateList.add(new UpdateEntry<SLARegQuery>(SLARegQuery.UPDATE_SLA_EXPECTED_VALUE, slaCalc.getSLARegistrationBean()));
    updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_EXPECTED_TIMES, new SLASummaryBean(slaCalc)));
}
Also used : SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) Date(java.util.Date) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery)

Example 2 with SLASummaryQuery

use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.

the class SLACalculatorMemory method updateDBSlaConfig.

@SuppressWarnings("rawtypes")
private void updateDBSlaConfig(SLACalcStatus slaCalc, List<UpdateEntry> updateList) throws JPAExecutorException {
    updateList.add(new UpdateEntry<SLARegQuery>(SLARegQuery.UPDATE_SLA_CONFIG, slaCalc.getSLARegistrationBean()));
    slaCalc.setLastModifiedTime(new Date());
    updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_LAST_MODIFIED_TIME, new SLASummaryBean(slaCalc)));
}
Also used : SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) Date(java.util.Date) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery)

Example 3 with SLASummaryQuery

use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.

the class TestSLACalculationJPAExecutor method testRollback.

/**
 * Test inserts and updates rollback
 *
 * @throws Exception
 */
@Test
public void testRollback() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    String wfId1 = "workflow-1";
    String wfId2 = "workflow-2";
    // initial insert
    SLASummaryBean bean1 = _createSLASummaryBean(wfId1, "RUNNING", EventStatus.START_MISS, new Date(), new Date(), 1000, null, null, 2000, 0, null);
    List<JsonBean> list = new ArrayList<JsonBean>();
    list.add(bean1);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(list, null, null);
    // update existing record and insert another
    Date newDate = new Date();
    bean1 = new SLASummaryBean();
    bean1.setId(wfId1);
    bean1.setActualEnd(newDate);
    List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
    updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, bean1));
    SLASummaryBean bean2 = _createSLASummaryBean(wfId2, "RUNNING", EventStatus.END_MISS, new Date(), new Date(), 1000, null, null, 2000, 0, null);
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(bean2);
    // set fault injection to true, so transaction is roll backed
    setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
    try {
        BatchQueryExecutor.getInstance().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
    SLASummaryBean sBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, wfId1);
    // isSlaProcessed should NOT be changed to 1
    // actualEnd should be null as before
    assertNull(sBean.getActualEnd());
    sBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, wfId2);
    // new bean should not have been inserted due to rollback
    assertNull(sBean);
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Test(org.junit.Test)

Example 4 with SLASummaryQuery

use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.

the class BatchQueryExecutor method executeBatchInsertUpdateDelete.

@SuppressWarnings("rawtypes")
public void executeBatchInsertUpdateDelete(Collection<JsonBean> insertList, Collection<UpdateEntry> updateList, Collection<JsonBean> deleteList) throws JPAExecutorException {
    List<QueryEntry> queryList = new ArrayList<QueryEntry>();
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    if (updateList != null) {
        for (UpdateEntry entry : updateList) {
            Query query = null;
            JsonBean bean = entry.getBean();
            if (bean instanceof WorkflowJobBean) {
                query = WorkflowJobQueryExecutor.getInstance().getUpdateQuery((WorkflowJobQuery) entry.getQueryName(), (WorkflowJobBean) entry.getBean(), em);
            } else if (bean instanceof WorkflowActionBean) {
                query = WorkflowActionQueryExecutor.getInstance().getUpdateQuery((WorkflowActionQuery) entry.getQueryName(), (WorkflowActionBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorJobBean) {
                query = CoordJobQueryExecutor.getInstance().getUpdateQuery((CoordJobQuery) entry.getQueryName(), (CoordinatorJobBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorActionBean) {
                query = CoordActionQueryExecutor.getInstance().getUpdateQuery((CoordActionQuery) entry.getQueryName(), (CoordinatorActionBean) entry.getBean(), em);
            } else if (bean instanceof BundleJobBean) {
                query = BundleJobQueryExecutor.getInstance().getUpdateQuery((BundleJobQuery) entry.getQueryName(), (BundleJobBean) entry.getBean(), em);
            } else if (bean instanceof BundleActionBean) {
                query = BundleActionQueryExecutor.getInstance().getUpdateQuery((BundleActionQuery) entry.getQueryName(), (BundleActionBean) entry.getBean(), em);
            } else if (bean instanceof SLARegistrationBean) {
                query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery((SLARegQuery) entry.getQueryName(), (SLARegistrationBean) entry.getBean(), em);
            } else if (bean instanceof SLASummaryBean) {
                query = SLASummaryQueryExecutor.getInstance().getUpdateQuery((SLASummaryQuery) entry.getQueryName(), (SLASummaryBean) entry.getBean(), em);
            } else {
                throw new JPAExecutorException(ErrorCode.E0603, "BatchQueryExecutor failed to construct a query");
            }
            queryList.add(new QueryEntry(entry.getQueryName(), query));
        }
    }
    jpaService.executeBatchInsertUpdateDelete(insertList, queryList, deleteList, em);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Query(javax.persistence.Query) WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) BundleActionQuery(org.apache.oozie.executor.jpa.BundleActionQueryExecutor.BundleActionQuery) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) QueryEntry(org.apache.oozie.service.JPAService.QueryEntry) EntityManager(javax.persistence.EntityManager) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleActionBean(org.apache.oozie.BundleActionBean) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 5 with SLASummaryQuery

use of org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery in project oozie by apache.

the class TestSLACalculatorMemory method testLoadOnRestart.

@Test
public void testLoadOnRestart() throws Exception {
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    SLARegistrationBean slaRegBean1 = _createSLARegistration("job-1-W", AppType.WORKFLOW_JOB);
    String jobId1 = slaRegBean1.getId();
    SLARegistrationBean slaRegBean2 = _createSLARegistration("job-2-W", AppType.WORKFLOW_JOB);
    String jobId2 = slaRegBean2.getId();
    SLARegistrationBean slaRegBean3 = _createSLARegistration("job-3-W", AppType.WORKFLOW_JOB);
    String jobId3 = slaRegBean3.getId();
    List<String> idList = new ArrayList<String>();
    idList.add(slaRegBean1.getId());
    idList.add(slaRegBean2.getId());
    idList.add(slaRegBean3.getId());
    createWorkflow(idList);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    slaRegBean1.setAppName("app-name");
    slaRegBean1.setExpectedDuration(123);
    slaRegBean1.setExpectedEnd(sdf.parse("2012-02-07"));
    slaRegBean1.setExpectedStart(sdf.parse("2011-02-07"));
    slaRegBean1.setNominalTime(sdf.parse("2012-01-06"));
    slaRegBean1.setUser("user");
    slaRegBean1.setParentId("parentId");
    slaRegBean1.setUpstreamApps("upstreamApps");
    slaRegBean1.setNotificationMsg("notificationMsg");
    slaRegBean1.setAlertContact("a@abc.com");
    slaRegBean1.setAlertEvents("MISS");
    slaRegBean1.setJobData("jobData");
    // 1 hour back
    Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000);
    // 1 hour back
    Date endTime = new Date(System.currentTimeMillis() + 2 * 1 * 3600 * 1000);
    slaRegBean3.setExpectedStart(startTime);
    slaRegBean3.setExpectedEnd(endTime);
    slaCalcMemory.addRegistration(jobId1, slaRegBean1);
    slaCalcMemory.addRegistration(jobId2, slaRegBean2);
    slaCalcMemory.addRegistration(jobId3, slaRegBean3);
    slaCalcMemory.updateAllSlaStatus();
    SLACalcStatus calc1 = slaCalcMemory.get(jobId1);
    SLACalcStatus calc2 = slaCalcMemory.get(jobId2);
    SLACalcStatus calc3 = slaCalcMemory.get(jobId3);
    calc1.setEventStatus(SLAEvent.EventStatus.END_MISS);
    calc1.setSLAStatus(SLAEvent.SLAStatus.MISS);
    calc1.setJobStatus(WorkflowJob.Status.FAILED.toString());
    // set last modified time 5 days back
    Date lastModifiedTime = new Date(System.currentTimeMillis() - 5 * 24 * 60 * 60 * 1000);
    calc1.setLastModifiedTime(lastModifiedTime);
    List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
    WorkflowJobBean wf1 = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId1);
    wf1.setId(jobId1);
    wf1.setStatus(WorkflowJob.Status.SUCCEEDED);
    wf1.setStartTime(sdf.parse("2011-03-09"));
    wf1.setEndTime(sdf.parse("2011-03-10"));
    wf1.setLastModifiedTime(new Date());
    WorkflowJobBean wf2 = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId2);
    wf2.setId(jobId2);
    wf2.setStatus(WorkflowJob.Status.RUNNING);
    wf2.setStartTime(sdf.parse("2011-03-09"));
    wf2.setEndTime(null);
    wf2.setLastModifiedTime(new Date());
    WorkflowJobBean wf3 = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId3);
    wf3.setId(jobId3);
    wf3.setStatus(WorkflowJob.Status.RUNNING);
    wf3.setStartTime(startTime);
    wf3.setEndTime(null);
    wf3.setLastModifiedTime(new Date());
    updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wf1));
    updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wf2));
    updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wf3));
    updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, new SLASummaryBean(calc2)));
    updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, new SLASummaryBean(calc3)));
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, null);
    slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    slaCalcMemory.updateAllSlaStatus();
    SLACalcStatus calc = new SLACalcStatus(SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1), SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ON_RESTART, jobId1));
    assertEquals("job-1-W", calc.getId());
    assertEquals(AppType.WORKFLOW_JOB, calc.getAppType());
    assertEquals("app-name", calc.getAppName());
    assertEquals(123, calc.getExpectedDuration());
    assertEquals(sdf.parse("2012-02-07"), calc.getExpectedEnd());
    assertEquals(sdf.parse("2011-02-07"), calc.getExpectedStart());
    assertEquals(sdf.parse("2012-01-06"), calc.getNominalTime());
    assertEquals("user", calc.getUser());
    assertEquals("parentId", calc.getParentId());
    assertEquals("upstreamApps", calc.getUpstreamApps());
    assertEquals("notificationMsg", calc.getNotificationMsg());
    assertEquals("a@abc.com", calc.getAlertContact());
    assertEquals("MISS", calc.getAlertEvents());
    assertEquals("jobData", calc.getJobData());
    assertEquals(sdf.parse("2011-03-09"), calc.getActualStart());
    assertEquals(sdf.parse("2011-03-10"), calc.getActualEnd());
    assertEquals(SLAEvent.EventStatus.END_MISS, calc1.getEventStatus());
    assertEquals(SLAEvent.SLAStatus.MISS, calc1.getSLAStatus());
    assertEquals(WorkflowJob.Status.FAILED.toString(), calc1.getJobStatus());
    assertEquals(lastModifiedTime, calc1.getLastModifiedTime());
    calc2 = new SLACalcStatus(SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId2), SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ON_RESTART, jobId2));
    assertEquals(8, calc.getEventProcessed());
    assertEquals(7, calc2.getEventProcessed());
    // jobId2 should be in history set as eventprocessed is 7 (111)
    // job3 will be in slamap
    // 1 out of 3 jobs in map
    assertEquals(1, slaCalcMemory.size());
    WorkflowJobBean wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId3);
    wf.setId(jobId3);
    wf.setStatus(WorkflowJob.Status.SUCCEEDED);
    wf.setEndTime(endTime);
    wf.setStartTime(startTime);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wf);
    slaCalcMemory.addJobStatus(jobId3, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, startTime, endTime);
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId3);
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(startTime, slaSummary.getActualStart());
    assertEquals(endTime, slaSummary.getActualEnd());
    assertEquals(WorkflowJob.Status.SUCCEEDED.toString(), slaSummary.getJobStatus());
}
Also used : UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) SimpleDateFormat(java.text.SimpleDateFormat) FailingDBHelperForTest(org.apache.oozie.util.db.FailingDBHelperForTest) Test(org.junit.Test)

Aggregations

SLASummaryQuery (org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 SLARegQuery (org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)3 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 JsonBean (org.apache.oozie.client.rest.JsonBean)2 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)2 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)2 JPAService (org.apache.oozie.service.JPAService)2 Test (org.junit.Test)2 SimpleDateFormat (java.text.SimpleDateFormat)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 BundleActionBean (org.apache.oozie.BundleActionBean)1 BundleJobBean (org.apache.oozie.BundleJobBean)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)1 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)1 BundleActionQuery (org.apache.oozie.executor.jpa.BundleActionQueryExecutor.BundleActionQuery)1 BundleJobQuery (org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery)1