Search in sources :

Example 1 with CoordActionInsertJPAExecutor

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

the class TestRecoveryService method addRecordToCoordActionTableForWaiting.

protected CoordinatorActionBean addRecordToCoordActionTableForWaiting(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName) throws Exception {
    CoordinatorActionBean action = createCoordAction(jobId, actionNum, status, resourceXmlName, 0);
    String testDir = getTestCaseDir();
    String missDeps = getTestCaseFileUri("2009/29/_SUCCESS") + "#" + getTestCaseFileUri("2009/22/_SUCCESS") + "#" + getTestCaseFileUri("2009/15/_SUCCESS") + "#" + getTestCaseFileUri("2009/08/_SUCCESS");
    missDeps = missDeps.replaceAll("#testDir", testDir);
    action.setMissingDependencies(missDeps);
    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)

Example 2 with CoordActionInsertJPAExecutor

use of org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor 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 3 with CoordActionInsertJPAExecutor

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

the class TestCoordActionInputCheckXCommand method addRecordToCoordActionTableForWaiting.

protected CoordinatorActionBean addRecordToCoordActionTableForWaiting(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName) throws Exception {
    CoordinatorActionBean action = createCoordAction(jobId, actionNum, status, resourceXmlName, 0, TZ, null);
    String missDeps = getTestCaseFileUri("2009/01/29/_SUCCESS") + "#" + getTestCaseFileUri("2009/01/22/_SUCCESS") + "#" + getTestCaseFileUri("2009/01/15/_SUCCESS") + "#" + getTestCaseFileUri("2009/01/08/_SUCCESS");
    action.setMissingDependencies(missDeps);
    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 4 with CoordActionInsertJPAExecutor

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

the class TestSLACalculatorMemory method testWFEndNotCoord.

public void testWFEndNotCoord() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    SLARegistrationBean slaRegBean = _createSLARegistration("job-C@1", AppType.COORDINATOR_ACTION);
    String coordActionId = slaRegBean.getId();
    slaRegBean.setExpectedEnd(sdf.parse("2013-03-07"));
    slaRegBean.setExpectedStart(sdf.parse("2012-03-07"));
    slaCalcMemory.addRegistration(coordActionId, slaRegBean);
    SLACalcStatus calc1 = slaCalcMemory.get(coordActionId);
    calc1.setEventProcessed(1);
    calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
    calc1.setJobStatus(WorkflowAction.Status.RUNNING.name());
    calc1.setLastModifiedTime(new Date());
    SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
    // Simulate a lost failed event
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    coordAction.setId(coordActionId);
    coordAction.setStatus(CoordinatorAction.Status.RUNNING);
    coordAction.setLastModifiedTime(sdf.parse("2013-02-07"));
    coordAction.setExternalId("wf_job-W");
    CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(coordAction);
    jpaService.execute(caInsertCmd);
    WorkflowJobBean wjb = new WorkflowJobBean();
    wjb.setId("wf_job-W");
    wjb.setStartTime(sdf.parse("2012-02-07"));
    wjb.setLastModifiedTime(new Date());
    wjb.setStatus(WorkflowJob.Status.SUCCEEDED);
    WorkflowJobQueryExecutor.getInstance().insert(wjb);
    calc1 = slaCalcMemory.get(coordActionId);
    slaCalcMemory.updateJobSla(coordActionId);
    slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, coordActionId);
    // cord action is running and wf job is completed
    assertEquals(slaSummaryBean.getJobStatus(), WorkflowInstance.Status.RUNNING.name());
    coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction);
    slaCalcMemory.addJobStatus(coordActionId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, sdf.parse("2012-02-07"), sdf.parse("2012-03-07"));
    slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, coordActionId);
    assertEquals(slaSummaryBean.getJobStatus(), WorkflowInstance.Status.SUCCEEDED.toString());
}
Also used : CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) SimpleDateFormat(java.text.SimpleDateFormat) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Example 5 with CoordActionInsertJPAExecutor

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

the class TestSLACalculatorMemory method testCoordinatorActionSLAStatusOnRestart.

@Test
public void testCoordinatorActionSLAStatusOnRestart() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    SLARegistrationBean slaRegBean1 = _createSLARegistration("job-C@1", AppType.COORDINATOR_ACTION);
    String jobId1 = slaRegBean1.getId();
    slaRegBean1.setExpectedEnd(sdf.parse("2013-03-07"));
    slaRegBean1.setExpectedStart(sdf.parse("2012-03-07"));
    slaCalcMemory.addRegistration(jobId1, slaRegBean1);
    SLACalcStatus calc1 = slaCalcMemory.get(jobId1);
    calc1.setEventProcessed(1);
    calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
    calc1.setJobStatus(WorkflowAction.Status.RUNNING.name());
    calc1.setLastModifiedTime(new Date());
    SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
    // Simulate a lost failed event
    CoordinatorActionBean cab = new CoordinatorActionBean();
    cab.setId(jobId1);
    cab.setStatus(CoordinatorAction.Status.FAILED);
    cab.setLastModifiedTime(sdf.parse("2013-02-07"));
    cab.setExternalId("wf_job-W");
    CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(cab);
    jpaService.execute(caInsertCmd);
    WorkflowJobBean wjb = new WorkflowJobBean();
    wjb.setId("wf_job-W");
    wjb.setStartTime(sdf.parse("2012-02-07"));
    wjb.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().insert(wjb);
    slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    slaCalcMemory.updateAllSlaStatus();
    // As job succeeded, it should not be in memory
    assertEquals(0, slaCalcMemory.size());
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
    assertEquals("job-C@1", slaSummary.getId());
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(AppType.COORDINATOR_ACTION, slaSummary.getAppType());
    assertEquals("FAILED", slaSummary.getJobStatus());
    assertEquals(SLAEvent.SLAStatus.MISS, slaSummary.getSLAStatus());
    assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
    assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
    assertEquals(sdf.parse("2013-02-07").getTime() - sdf.parse("2012-02-07").getTime(), slaSummary.getActualDuration());
}
Also used : CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) SimpleDateFormat(java.text.SimpleDateFormat) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) 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