Search in sources :

Example 81 with JPAService

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

the class CoordXTestCase method setUp.

protected void setUp() throws Exception {
    super.setUp();
    services = new Services();
    services.init();
    jpaService = Services.get().get(JPAService.class);
    if (jpaService == null) {
        fail("jpaService can not be null");
    }
}
Also used : Services(org.apache.oozie.service.Services) JPAService(org.apache.oozie.service.JPAService)

Example 82 with JPAService

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

the class TestCoordActionInputCheckXCommand method testActionInputCheck.

public void testActionInputCheck() throws Exception {
    String jobId = "0000000-" + new Date().getTime() + "-TestCoordActionInputCheckXCommand-C";
    Date startTime = DateUtils.parseDateOozieTZ("2009-02-01T23:59" + TZ);
    Date endTime = DateUtils.parseDateOozieTZ("2009-02-02T23:59" + TZ);
    CoordinatorJobBean job = addRecordToCoordJobTable(jobId, startTime, endTime);
    new CoordMaterializeTransitionXCommand(job.getId(), 3600).call();
    createTestCaseSubDir("2009/02/05/_SUCCESS".split("/"));
    createTestCaseSubDir("2009/01/15/_SUCCESS".split("/"));
    new CoordActionInputCheckXCommand(job.getId() + "@1", job.getId()).call();
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(job.getId() + "@1"));
    System.out.println("missingDeps " + action.getMissingDependencies() + " Xml " + action.getActionXml());
    if (action.getMissingDependencies().indexOf("/2009/02/05/") >= 0) {
        fail("directory should be resolved :" + action.getMissingDependencies());
    }
    if (action.getMissingDependencies().indexOf("/2009/01/15/") < 0) {
        fail("directory should NOT be resolved :" + action.getMissingDependencies());
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 83 with JPAService

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

the class TestCoordActionInputCheckXCommand method addRecordToCoordJobTable.

private CoordinatorJobBean addRecordToCoordJobTable(String jobId, Date start, Date end, String dataInType) throws CommandException {
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(jobId);
    coordJob.setAppName("testApp");
    coordJob.setAppPath("testAppPath");
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    coordJob.setCreatedTime(new Date());
    coordJob.setLastModifiedTime(new Date());
    coordJob.setUser("testUser");
    coordJob.setGroup("testGroup");
    coordJob.setTimeZone("UTC");
    coordJob.setTimeUnit(Timeunit.DAY);
    coordJob.setMatThrottling(2);
    try {
        coordJob.setStartTime(start);
        coordJob.setEndTime(end);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not set Date/time");
    }
    String testDir = getTestCaseDir();
    XConfiguration jobConf = new XConfiguration();
    jobConf.set(OozieClient.USER_NAME, getTestUser());
    String confStr = jobConf.toXmlString(false);
    coordJob.setConf(confStr);
    String appXml = "<coordinator-app xmlns='uri:oozie:coordinator:0.2' name='NAME' frequency=\"1\" start='2009-02-01T01:00" + TZ + "' end='2009-02-03T23:59" + TZ + "' timezone='UTC' freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<controls>";
    appXml += "<timeout>10</timeout>";
    appXml += "<concurrency>2</concurrency>";
    appXml += "<execution>LIFO</execution>";
    appXml += "</controls>";
    appXml += "<input-events>";
    appXml += "<data-in name='A' dataset='a'>";
    appXml += "<dataset name='a' frequency='7' initial-instance='2009-01-01T01:00" + TZ + "' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    if (dataInType.equals("future")) {
        appXml += "<start-instance>${coord:" + dataInType + "(0,5)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(3,5)}</end-instance>";
    } else if (dataInType.equals("latest")) {
        appXml += "<start-instance>${coord:" + dataInType + "(-3)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(0)}</end-instance>";
    } else if (dataInType.equals("current")) {
        appXml += "<start-instance>${coord:" + dataInType + "(-3)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(1)}</end-instance>";
    }
    appXml += "</data-in>";
    appXml += "</input-events>";
    appXml += "<output-events>";
    appXml += "<data-out name='LOCAL_A' dataset='local_a'>";
    appXml += "<dataset name='local_a' frequency='7' initial-instance='2009-01-01T01:00" + TZ + "' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    appXml += "<start-instance>${coord:current(-3)}</start-instance>";
    appXml += "<instance>${coord:current(0)}</instance>";
    appXml += "</data-out>";
    appXml += "</output-events>";
    appXml += "<action>";
    appXml += "<workflow>";
    appXml += "<app-path>hdfs:///tmp/workflows/</app-path>";
    appXml += "<configuration>";
    appXml += "<property>";
    appXml += "<name>inputA</name>";
    appXml += "<value>${coord:dataIn('A')}</value>";
    appXml += "</property>";
    appXml += "<property>";
    appXml += "<name>inputB</name>";
    appXml += "<value>${coord:dataOut('LOCAL_A')}</value>";
    appXml += "</property>";
    appXml += "</configuration>";
    appXml += "</workflow>";
    appXml += "</action>";
    appXml += "</coordinator-app>";
    coordJob.setJobXml(appXml);
    coordJob.setLastActionNumber(0);
    coordJob.setFrequency("1");
    coordJob.setExecutionOrder(Execution.FIFO);
    coordJob.setConcurrency(1);
    JPAService jpaService = Services.get().get(JPAService.class);
    if (jpaService != null) {
        try {
            jpaService.execute(new CoordJobInsertJPAExecutor(coordJob));
        } catch (JPAExecutorException e) {
            throw new CommandException(e);
        }
    } else {
        fail("Unable to insert the test job record to table");
    }
    return coordJob;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 84 with JPAService

use of org.apache.oozie.service.JPAService 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 85 with JPAService

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

the class TestCoordActionInputCheckXCommand method testResolveCoordConfiguration.

public void testResolveCoordConfiguration() {
    try {
        CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-job-for-action-input-check.xml", CoordinatorJob.Status.RUNNING, false, true);
        CoordinatorActionBean action = addRecordToCoordActionTableForWaiting(job.getId(), 1, CoordinatorAction.Status.WAITING, "coord-action-for-action-input-check.xml");
        createTestCaseSubDir("2009/01/29/_SUCCESS".split("/"));
        createTestCaseSubDir("2009/01/22/_SUCCESS".split("/"));
        createTestCaseSubDir("2009/01/15/_SUCCESS".split("/"));
        createTestCaseSubDir("2009/01/08/_SUCCESS".split("/"));
        sleep(3000);
        new CoordActionInputCheckXCommand(action.getId(), job.getId()).call();
        sleep(3000);
        final JPAService jpaService = Services.get().get(JPAService.class);
        CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(action.getId());
        CoordinatorActionBean caBean = jpaService.execute(coordGetCmd);
        Element eAction = XmlUtils.parseXml(caBean.getActionXml());
        Element configElem = eAction.getChild("action", eAction.getNamespace()).getChild("workflow", eAction.getNamespace()).getChild("configuration", eAction.getNamespace());
        List<?> elementList = configElem.getChildren("property", configElem.getNamespace());
        Element e1 = (Element) elementList.get(0);
        Element e2 = (Element) elementList.get(1);
        assertEquals("file://,testDir/2009/29,file://,testDir/2009/22,file://,testDir/2009/15,file://,testDir/2009/08", e1.getChild("value", e1.getNamespace()).getValue());
        assertEquals("file://,testDir/2009/29", e2.getChild("value", e1.getNamespace()).getValue());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unexpected exception");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Element(org.jdom.Element) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

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