Search in sources :

Example 61 with CoordinatorActionBean

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

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

Example 63 with CoordinatorActionBean

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

the class TestCoordActionInputCheckXCommand method testActionInputCheckFuture.

public void testActionInputCheckFuture() throws Exception {
    String jobId = "0000000-" + new Date().getTime() + "-TestCoordActionInputCheckXCommand-C";
    Date startTime = DateUtils.parseDateOozieTZ("2009-02-15T23:59" + TZ);
    Date endTime = DateUtils.parseDateOozieTZ("2009-02-16T23:59" + TZ);
    CoordinatorJobBean job = addRecordToCoordJobTable(jobId, startTime, endTime, "future");
    new CoordMaterializeTransitionXCommand(job.getId(), 3600).call();
    // providing some of the dataset dirs required as per coordinator specification with holes
    createTestCaseSubDir("2009/02/12/_SUCCESS".split("/"));
    createTestCaseSubDir("2009/02/26/_SUCCESS".split("/"));
    createTestCaseSubDir("2009/03/05/_SUCCESS".split("/"));
    // limit is 5. So this should be ignored
    createTestCaseSubDir("2009/03/26/_SUCCESS".split("/"));
    new CoordActionInputCheckXCommand(job.getId() + "@1", job.getId()).call();
    CoordinatorActionBean action = null;
    JPAService jpaService = Services.get().get(JPAService.class);
    try {
        action = jpaService.execute(new CoordActionGetJPAExecutor(job.getId() + "@1"));
    } catch (JPAExecutorException se) {
        fail("Action ID " + job.getId() + "@1" + " was not stored properly in db");
    }
    assertEquals(CoordCommandUtils.RESOLVED_UNRESOLVED_SEPARATOR + "${coord:futureRange(0,3,'5')}", action.getMissingDependencies());
    createTestCaseSubDir("2009/03/12/_SUCCESS".split("/"));
    new CoordActionInputCheckXCommand(job.getId() + "@1", job.getId()).call();
    try {
        action = jpaService.execute(new CoordActionGetJPAExecutor(job.getId() + "@1"));
    } catch (JPAExecutorException se) {
        fail("Action ID " + job.getId() + "@1" + " was not stored properly in db");
    }
    assertEquals("", action.getMissingDependencies());
    String actionXML = action.getActionXml();
    String resolvedList = getTestCaseFileUri("2009/02/12") + CoordELFunctions.INSTANCE_SEPARATOR + getTestCaseFileUri("2009/02/26") + CoordELFunctions.INSTANCE_SEPARATOR + getTestCaseFileUri("2009/03/05") + CoordELFunctions.INSTANCE_SEPARATOR + getTestCaseFileUri("2009/03/12");
    assertEquals(resolvedList, actionXML.substring(actionXML.indexOf("<uris>") + 6, actionXML.indexOf("</uris>")));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) 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) Date(java.util.Date)

Example 64 with CoordinatorActionBean

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

the class TestCoordActionNotificationXCommand method testCoordNotificationTimeout.

public void testCoordNotificationTimeout() throws Exception {
    XConfiguration conf = new XConfiguration();
    conf.set(OozieClient.COORD_ACTION_NOTIFICATION_URL, container.getServletURL("/hang/*"));
    String runConf = conf.toXmlString(false);
    CoordinatorActionBean coord = Mockito.mock(CoordinatorActionBean.class);
    Mockito.when(coord.getId()).thenReturn("1");
    Mockito.when(coord.getStatus()).thenReturn(CoordinatorAction.Status.SUCCEEDED);
    Mockito.when(coord.getRunConf()).thenReturn(runConf);
    CoordActionNotificationXCommand command = new CoordActionNotificationXCommand(coord);
    command.retries = 3;
    long start = System.currentTimeMillis();
    command.call();
    long end = System.currentTimeMillis();
    Assert.assertTrue(end - start >= 50);
    Assert.assertTrue(end - start <= 10000);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean)

Example 65 with CoordinatorActionBean

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

the class CoordJobGetActionsSuspendedJPAExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public List<CoordinatorActionBean> execute(EntityManager em) throws JPAExecutorException {
    try {
        List<CoordinatorActionBean> actionBeansList = new ArrayList<CoordinatorActionBean>();
        Query q = em.createNamedQuery("GET_COORD_ACTIONS_SUSPENDED");
        q.setParameter("jobId", coordJobId);
        List<Object[]> objectArrList = q.getResultList();
        for (Object[] arr : objectArrList) {
            CoordinatorActionBean caa = getBeanForCoordinatorActionFromArray(arr);
            actionBeansList.add(caa);
        }
        return actionBeansList;
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
}
Also used : Query(javax.persistence.Query) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList)

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