Search in sources :

Example 76 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestSLAJobEventListener method createCoordAction.

private CoordinatorActionBean createCoordAction(String id, String parentId) throws Exception {
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    CoordinatorActionBean action = new CoordinatorActionBean();
    action.setId(id);
    action.setJobId(parentId);
    insertList.add(action);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    return action;
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList)

Example 77 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean 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 78 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class XDataTestCase method setCoordActionStatus.

protected void setCoordActionStatus(String actionId, CoordinatorAction.Status status) throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    action.setStatus(status);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 79 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class XDataTestCase method createCoordAction.

/**
 * Create coord action bean
 *
 * @param jobId coord job id
 * @param actionNum action number
 * @param status coord action status
 * @param resourceXmlName xml file name
 * @param pending pending counter
 * @return coord action bean
 * @throws Exception thrown if unable to create coord action bean
 */
protected CoordinatorActionBean createCoordAction(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName, int pending, String oozieTimeZoneMask, Date actionNominalTime) throws Exception {
    String actionId = Services.get().get(UUIDService.class).generateChildId(jobId, actionNum + "");
    Path appPath = new Path(getFsTestCaseDir(), "coord");
    String actionXml = getCoordActionXml(appPath, resourceXmlName);
    actionXml = actionXml.replace("${TZ}", oozieTimeZoneMask);
    CoordinatorActionBean action = new CoordinatorActionBean();
    action.setId(actionId);
    if (status != CoordinatorAction.Status.SUBMITTED && status != CoordinatorAction.Status.READY) {
        action.setExternalId(actionId + "_E");
    }
    action.setJobId(jobId);
    action.setActionNumber(actionNum);
    action.setPending(pending);
    try {
        if (actionNominalTime == null) {
            String nominalTime = getActionNominalTime(actionXml);
            action.setNominalTime(DateUtils.parseDateOozieTZ(nominalTime));
        } else {
            action.setNominalTime(actionNominalTime);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unable to get action nominal time");
        throw new IOException(e);
    }
    action.setLastModifiedTime(new Date());
    action.setCreatedTime(new Date());
    action.setStatus(status);
    action.setActionXml(actionXml);
    action.setTimeOut(10);
    Configuration conf = getCoordConf(appPath);
    action.setCreatedConf(XmlUtils.prettyPrint(conf).toString());
    action.setRunConf(XmlUtils.prettyPrint(conf).toString());
    return action;
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) UUIDService(org.apache.oozie.service.UUIDService) IOException(java.io.IOException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JDOMException(org.jdom.JDOMException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Date(java.util.Date)

Example 80 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordActionsInDateRange method testCoordActionsInDateRange.

/**
 * This is unit test case for the 'getCoordActionsFromDates()' method. The method is supposed to retrieve the list of
 * coordinator actions running between a range of start and end date. The following test case tests its accuracy and fails
 * otherwise.
 */
public void testCoordActionsInDateRange() {
    try {
        int actionNum = 1;
        CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
        CoordinatorActionBean actionId1 = addRecordToCoordActionTable(job.getId(), actionNum, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
        Date nominalTime = actionId1.getNominalTime();
        long nominalTimeMilliseconds = nominalTime.getTime();
        long noOfMillisecondsinOneHour = 3600000;
        String date1 = DateUtils.formatDateOozieTZ(new Date(nominalTimeMilliseconds - (noOfMillisecondsinOneHour / 2)));
        String date2 = DateUtils.formatDateOozieTZ(new Date(nominalTimeMilliseconds + noOfMillisecondsinOneHour));
        // Test a bad date format.
        try {
            String badDate = "bad" + date1;
            CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), badDate + "::" + date2);
            fail("Accepted badly formatted date: " + badDate);
        } catch (XException e) {
            // Pass
            assertEquals(ErrorCode.E0308, e.getErrorCode());
        }
        // Test a bad scope.
        try {
            String badScope = date1 + "0xbad5c09e" + date2;
            CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), badScope);
            fail("Accepted bad range scope: " + badScope);
        } catch (XException e) {
            // Pass
            assertEquals(ErrorCode.E0308, e.getErrorCode());
        }
        // Test inverted start and end dates.
        try {
            CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date2 + "::" + date1);
            fail("Accepted inverted dates: [Start::End] = " + date2 + "::" + date1);
        } catch (XException e) {
            // Pass
            assertEquals(ErrorCode.E0308, e.getErrorCode());
        }
        // Test a lenient date
        try {
            // Like date2 but with the 50th day of the month
            String lenientDate = date2.replaceAll("[^-]*T", "50T");
            CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + lenientDate);
            fail("Accepted lenient date: " + lenientDate);
        } catch (XException e) {
            // Pass
            assertEquals(ErrorCode.E0308, e.getErrorCode());
        }
        // Testing for the number of coordinator actions in a date range that spans from half an hour prior to the nominal
        // time to 1 hour after the nominal time
        int noOfActions = CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + date2).size();
        assertEquals(1, noOfActions);
        // Testing for the number of coordinator actions in a date range that spans from half an hour after the nominal
        // time to 1 hour after the nominal time
        date1 = DateUtils.formatDateOozieTZ(new Date(nominalTimeMilliseconds + (noOfMillisecondsinOneHour / 2)));
        noOfActions = CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + date2).size();
        assertEquals(0, noOfActions);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) XException(org.apache.oozie.XException) Date(java.util.Date) XException(org.apache.oozie.XException)

Aggregations

CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)307 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)148 Date (java.util.Date)117 JPAService (org.apache.oozie.service.JPAService)113 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)102 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)60 CommandException (org.apache.oozie.command.CommandException)55 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 IOException (java.io.IOException)49 XConfiguration (org.apache.oozie.util.XConfiguration)44 Configuration (org.apache.hadoop.conf.Configuration)43 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)42 ArrayList (java.util.ArrayList)40 JDOMException (org.jdom.JDOMException)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 StringReader (java.io.StringReader)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)29 StoreException (org.apache.oozie.store.StoreException)24 Test (org.junit.Test)24 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)22