Search in sources :

Example 36 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordActionStartXCommand method testActionStartWithErrorReported.

/**
 * Coord action XML contains non-supported parameterized action name and
 * test that CoordActionStartXCommand stores error code and error message in
 * action's table during error handling
 *
 * @throws IOException
 * @throws JPAExecutorException
 * @throws CommandException
 */
public void testActionStartWithErrorReported() throws IOException, JPAExecutorException, CommandException {
    String actionId = new Date().getTime() + "-COORD-ActionStartCommand-C@1";
    String wfApp = "<start to='${someParam}' />";
    addRecordToActionTable(actionId, 1, wfApp);
    new CoordActionStartXCommand(actionId, "me", "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    CoordinatorActionBean action = jpaService.execute(new CoordActionGetForStartJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("Expected status was FAILED due to incorrect XML element");
    }
    assertEquals(action.getErrorCode(), ErrorCode.E0701.toString());
    assertTrue(action.getErrorMessage().contains("XML schema error, cvc-pattern-valid: Value '${someParam}' " + "is not facet-valid with respect to pattern"));
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService) CoordActionGetForStartJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForStartJPAExecutor) Date(java.util.Date)

Example 37 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordActionStartXCommand method addRecordToActionTable.

private void addRecordToActionTable(String actionId, int actionNum, String wfParam) throws IOException, JPAExecutorException {
    final JPAService jpaService = Services.get().get(JPAService.class);
    CoordinatorActionBean action = new CoordinatorActionBean();
    action.setJobId(actionId);
    action.setId(actionId);
    action.setActionNumber(actionNum);
    action.setNominalTime(new Date());
    action.setStatus(Status.SUBMITTED);
    File appPath = new File(getTestCaseDir(), "coord/no-op/");
    String actionXml = "<coordinator-app xmlns='uri:oozie:coordinator:0.2' xmlns:sla='uri:oozie:sla:0.1' name='NAME' " + "frequency=\"1\" start='2009-02-01T01:00Z' end='2009-02-03T23:59Z' timezone='UTC' freq_timeunit='DAY' " + "end_of_duration='NONE'  instance-number=\"1\" action-nominal-time=\"2009-02-01T01:00Z\">";
    actionXml += "<controls>";
    actionXml += "<timeout>10</timeout>";
    actionXml += "<concurrency>2</concurrency>";
    actionXml += "<execution>LIFO</execution>";
    actionXml += "</controls>";
    actionXml += "<input-events>";
    actionXml += "<data-in name='A' dataset='a'>";
    actionXml += "<dataset name='a' frequency='7' initial-instance='2009-02-01T01:00Z' timezone='UTC' freq_timeunit='DAY'" + " end_of_duration='NONE'>";
    actionXml += "<uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>";
    actionXml += "</dataset>";
    actionXml += "<instance>${coord:latest(0)}</instance>";
    actionXml += "</data-in>";
    actionXml += "</input-events>";
    actionXml += "<output-events>";
    actionXml += "<data-out name='LOCAL_A' dataset='local_a'>";
    actionXml += "<dataset name='local_a' frequency='7' initial-instance='2009-02-01T01:00Z' timezone='UTC' freq_timeunit=" + "'DAY' end_of_duration='NONE'>";
    actionXml += "<uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>";
    actionXml += "</dataset>";
    actionXml += "<instance>${coord:current(-1)}</instance>";
    actionXml += "</data-out>";
    actionXml += "</output-events>";
    actionXml += "<action>";
    actionXml += "<workflow>";
    actionXml += "<app-path>" + appPath.toURI() + "</app-path>";
    actionXml += "<configuration>";
    actionXml += "<property>";
    actionXml += "<name>inputA</name>";
    actionXml += "<value>" + getTestCaseFileUri("coord/US//2009/02/01") + "</value>";
    actionXml += "</property>";
    actionXml += "<property>";
    actionXml += "<name>inputB</name>";
    actionXml += "<value>" + getTestCaseFileUri("coord/US//2009/02/01") + "</value>";
    actionXml += "</property>";
    actionXml += "</configuration>";
    actionXml += "</workflow>";
    String slaXml = " <sla:info xmlns:sla='uri:oozie:sla:0.1'>" + " <sla:app-name>test-app</sla:app-name>" + " <sla:nominal-time>2009-03-06T10:00Z</sla:nominal-time>" + " <sla:should-start>5</sla:should-start>" + " <sla:should-end>120</sla:should-end>" + " <sla:notification-msg>Notifying User for nominal time : 2009-03-06T10:00Z </sla:notification-msg>" + " <sla:alert-contact>abc@example.com</sla:alert-contact>" + " <sla:dev-contact>abc@example.com</sla:dev-contact>" + " <sla:qa-contact>abc@example.com</sla:qa-contact>" + " <sla:se-contact>abc@example.com</sla:se-contact>" + "</sla:info>";
    actionXml += slaXml;
    actionXml += "</action>";
    actionXml += "</coordinator-app>";
    action.setActionXml(actionXml);
    action.setSlaXml(slaXml);
    String createdConf = "<configuration> ";
    createdConf += "<property> <name>execution_order</name> <value>LIFO</value> </property>";
    createdConf += "<property> <name>user.name</name> <value>" + getTestUser() + "</value> </property>";
    createdConf += "<property> <name>group.name</name> <value>other</value> </property>";
    createdConf += "<property> <name>app-path</name> " + "<value>" + appPath.toURI() + "/</value> </property>";
    createdConf += "<property> <name>jobTracker</name> ";
    createdConf += "<value>localhost:9001</value></property>";
    createdConf += "<property> <name>nameNode</name> <value>hdfs://localhost:9000</value></property>";
    createdConf += "<property> <name>queueName</name> <value>default</value></property>";
    createdConf += "</configuration> ";
    action.setCreatedConf(createdConf);
    jpaService.execute(new CoordActionInsertJPAExecutor(action));
    String content = "<workflow-app xmlns='uri:oozie:workflow:0.2'  xmlns:sla='uri:oozie:sla:0.1' name='no-op-wf'>";
    if (wfParam != null) {
        if (!wfParam.isEmpty()) {
            content += wfParam;
        }
    } else {
        content += "<start to='end' />";
    }
    String slaXml2 = " <sla:info>" + // + " <sla:client-id>axonite-blue</sla:client-id>"
    " <sla:app-name>test-app</sla:app-name>" + " <sla:nominal-time>2009-03-06T10:00Z</sla:nominal-time>" + " <sla:should-start>5</sla:should-start>" + " <sla:should-end>${2 * HOURS}</sla:should-end>" + " <sla:notification-msg>Notifying User for nominal time : 2009-03-06T10:00Z </sla:notification-msg>" + " <sla:alert-contact>abc@example.com</sla:alert-contact>" + " <sla:dev-contact>abc@example.com</sla:dev-contact>" + " <sla:qa-contact>abc@example.com</sla:qa-contact>" + " <sla:se-contact>abc@example.com</sla:se-contact>" + "</sla:info>";
    content += "<end name='end' />" + slaXml2 + "</workflow-app>";
    writeToFile(content, appPath.getAbsolutePath());
}
Also used : CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) Date(java.util.Date)

Example 38 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordActionStartXCommand method checkCoordAction.

private void checkCoordAction(String actionId) {
    try {
        final JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
        if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
            fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
        }
        if (action.getExternalId() != null) {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(action.getExternalId()));
            assertEquals(wfJob.getParentId(), action.getId());
        }
    } catch (JPAExecutorException je) {
        fail("Action ID " + actionId + " was not stored properly in db");
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 39 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordActionStartXCommand method testActionStartWithEscapeStrings.

/**
 * Test : configuration contains url string which should be escaped before put into the evaluator.
 * If not escape, the error 'SAXParseException' will be thrown and workflow job will not be submitted.
 *
 * @throws Exception
 */
public void testActionStartWithEscapeStrings() throws Exception {
    Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
    String actionId = action.getId();
    new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
    }
    final String wfId = action.getExternalId();
    waitFor(3000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> wfActions = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
            return wfActions.size() > 0;
        }
    });
    List<WorkflowActionBean> wfActions = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
    assertTrue(wfActions.size() > 0);
    final String wfActionId = wfActions.get(0).getId();
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId));
            return wfAction.getExternalId() != null;
        }
    });
    WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId));
    assertNotNull(wfAction.getExternalId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 40 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordActionUpdatePushMissingDependency method checkCoordAction.

private CoordinatorActionBean checkCoordAction(String actionId, String expDeps, CoordinatorAction.Status stat) throws Exception {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
        String missDeps = action.getPushMissingDependencies();
        assertEquals(missDeps, expDeps);
        assertEquals(action.getStatus(), stat);
        return action;
    } catch (JPAExecutorException se) {
        throw new Exception("Action ID " + actionId + " was not stored properly in db");
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Aggregations

JPAService (org.apache.oozie.service.JPAService)449 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)156 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)152 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)113 Date (java.util.Date)95 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)94 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)84 BundleJobBean (org.apache.oozie.BundleJobBean)78 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)78 ArrayList (java.util.ArrayList)76 CommandException (org.apache.oozie.command.CommandException)66 List (java.util.List)59 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)54 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)54 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)49 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 HashMap (java.util.HashMap)41 BundleActionBean (org.apache.oozie.BundleActionBean)35 Configuration (org.apache.hadoop.conf.Configuration)32 EntityManager (javax.persistence.EntityManager)31