Search in sources :

Example 6 with CoordActionInsertJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor in project oozie by apache.

the class XDataTestCase method addRecordToCoordActionTable.

/**
 * Insert coord action for testing.
 *
 * @param jobId coord job id
 * @param actionNum action number
 * @param status coord action status
 * @param resourceXmlName xml file name
 * @param pending pending counter
 * @param actionNominalTime
 * @return coord action bean
 * @throws Exception thrown if unable to create coord action bean
 */
protected CoordinatorActionBean addRecordToCoordActionTable(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName, int pending, Date actionNominalTime) throws Exception {
    CoordinatorActionBean action = createCoordAction(jobId, actionNum, status, resourceXmlName, pending, actionNominalTime);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordActionInsertJPAExecutor coordActionInsertCmd = new CoordActionInsertJPAExecutor(action);
        jpaService.execute(coordActionInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test coord action record to table");
        throw je;
    }
    return action;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService)

Example 7 with CoordActionInsertJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor in project oozie by apache.

the class XDataTestCase method insertRecordCoordAction.

/**
 * Inserts a record to coord action table
 *
 * @param action the record to be inserted
 * @throws Exception
 */
protected void insertRecordCoordAction(CoordinatorActionBean action) throws Exception {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordActionInsertJPAExecutor coordActionInsertCmd = new CoordActionInsertJPAExecutor(action);
        jpaService.execute(coordActionInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test coord action record to table");
        throw je;
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 8 with CoordActionInsertJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor in project oozie by apache.

the class TestCoordRerunXCommand method addRecordToWithLazyAction.

private CoordinatorActionBean addRecordToWithLazyAction(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName) throws IOException {
    Path appPath = new Path(getFsTestCaseDir(), "coord");
    String actionXml = getCoordActionXml(appPath, resourceXmlName);
    String actionNomialTime = getActionNomialTime(actionXml);
    CoordinatorActionBean action = new CoordinatorActionBean();
    action.setJobId(jobId);
    action.setId(Services.get().get(UUIDService.class).generateChildId(jobId, actionNum + ""));
    action.setActionNumber(actionNum);
    try {
        action.setNominalTime(DateUtils.parseDateOozieTZ(actionNomialTime));
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unable to get action nominal time");
        throw new IOException(e);
    }
    action.setLastModifiedTime(new Date());
    action.setStatus(status);
    action.setActionXml(actionXml);
    Properties conf = getLazyWorkflowProp(appPath);
    String createdConf = XmlUtils.writePropToString(conf);
    action.setCreatedConf(createdConf);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordActionInsertJPAExecutor coordActionInsertCmd = new CoordActionInsertJPAExecutor(action);
    try {
        jpaService.execute(coordActionInsertCmd);
    } catch (JPAExecutorException e) {
        e.printStackTrace();
        fail("Unable to insert the test coord action record to table");
    }
    return action;
}
Also used : Path(org.apache.hadoop.fs.Path) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) IOException(java.io.IOException) Properties(java.util.Properties) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JDOMException(org.jdom.JDOMException) CommandException(org.apache.oozie.command.CommandException) StoreException(org.apache.oozie.store.StoreException) IOException(java.io.IOException) Date(java.util.Date)

Example 9 with CoordActionInsertJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor in project oozie by apache.

the class TestBulkMonitorWebServiceAPI method testDefaultStatus.

public void testDefaultStatus() throws Exception {
    // adding coordinator action #4 to Coord#3
    CoordinatorActionBean action4 = new CoordinatorActionBean();
    action4.setId("Coord3@1");
    action4.setStatus(CoordinatorAction.Status.FAILED);
    action4.setCreatedTime(DateUtils.parseDateUTC(CREATE_TIME));
    action4.setJobId("Coord3");
    Calendar cal = Calendar.getInstance();
    cal.setTime(DateUtils.parseDateUTC(CREATE_TIME));
    cal.add(Calendar.DATE, -1);
    action4.setNominalTime(cal.getTime());
    CoordActionInsertJPAExecutor actionInsert = new CoordActionInsertJPAExecutor(action4);
    jpaService.execute(actionInsert);
    runTest("/v1/jobs", V1JobsServlet.class, false, new Callable<Void>() {

        public Void call() throws Exception {
            String bulkRequest = "bundle=" + bundleName;
            JSONArray array = _requestToServer(bulkRequest);
            assertEquals(4, array.size());
            return null;
        }
    });
}
Also used : CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Calendar(java.util.Calendar) JSONArray(org.json.simple.JSONArray)

Example 10 with CoordActionInsertJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor in project oozie by apache.

the class TestSLACalculatorMemory method testEventMissOnRestart.

@Test
public void testEventMissOnRestart() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    coordAction.setId("coordActionId-C@1");
    coordAction.setStatus(CoordinatorAction.Status.RUNNING);
    coordAction.setLastModifiedTime(sdf.parse("2013-02-07"));
    CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(coordAction);
    jpaService.execute(caInsertCmd);
    CoordinatorActionBean coordAction2 = new CoordinatorActionBean();
    coordAction2.setId("coordActionId-C@2");
    coordAction2.setStatus(CoordinatorAction.Status.RUNNING);
    coordAction2.setLastModifiedTime(sdf.parse("2013-02-07"));
    caInsertCmd = new CoordActionInsertJPAExecutor(coordAction2);
    jpaService.execute(caInsertCmd);
    SLARegistrationBean slaRegBean1 = _createSLARegistration("coordActionId-C@1", AppType.COORDINATOR_ACTION);
    String jobId1 = slaRegBean1.getId();
    slaRegBean1.setExpectedEnd(sdf.parse("2013-03-07"));
    slaRegBean1.setExpectedStart(sdf.parse("2012-03-07"));
    // long duration;
    slaRegBean1.setExpectedDuration(100000);
    slaCalcMemory.addRegistration(jobId1, slaRegBean1);
    slaCalcMemory.updateAllSlaStatus();
    SLARegistrationBean slaRegBean2 = _createSLARegistration("coordActionId-C@2", AppType.COORDINATOR_ACTION);
    String jobId2 = slaRegBean2.getId();
    // 1 hour
    slaRegBean2.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000));
    // 2 hour
    slaRegBean2.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 1 * 3600 * 1000));
    // long duration;
    slaRegBean2.setExpectedDuration(100000);
    slaCalcMemory.addRegistration(jobId2, slaRegBean2);
    slaCalcMemory.updateAllSlaStatus();
    assertEquals(2, slaCalcMemory.size());
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
    SLASummaryBean slaSummary2 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId2);
    assertEquals("coordActionId-C@1", slaSummary.getId());
    assertEquals(5, slaSummary.getEventProcessed());
    assertEquals(-1, slaSummary.getActualDuration());
    assertEquals("coordActionId-C@2", slaSummary2.getId());
    assertEquals(0, slaSummary2.getEventProcessed());
    assertEquals(-1, slaSummary2.getActualDuration());
    coordAction.setStatusStr("FAILED");
    coordAction2.setStatusStr("FAILED");
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_FOR_START, coordAction);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_FOR_START, coordAction2);
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    slaCalcMemory.updateAllSlaStatus();
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
    slaSummary2 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId2);
    assertEquals("coordActionId-C@1", slaSummary.getId());
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals("coordActionId-C@2", slaSummary2.getId());
    assertEquals(8, slaSummary2.getEventProcessed());
}
Also used : CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) FailingDBHelperForTest(org.apache.oozie.util.db.FailingDBHelperForTest) Test(org.junit.Test)

Aggregations

CoordActionInsertJPAExecutor (org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor)14 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)12 JPAService (org.apache.oozie.service.JPAService)9 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)8 Date (java.util.Date)5 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Calendar (java.util.Calendar)2 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)2 FailingDBHelperForTest (org.apache.oozie.util.db.FailingDBHelperForTest)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 Path (org.apache.hadoop.fs.Path)1 CommandException (org.apache.oozie.command.CommandException)1 StoreException (org.apache.oozie.store.StoreException)1 JDOMException (org.jdom.JDOMException)1 JSONArray (org.json.simple.JSONArray)1