Search in sources :

Example 1 with WorkflowActionBean

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

the class TestWorkflowJobsGetFromCoordParentIdJPAExecutor method testGetCoordinatorParent.

public void testGetCoordinatorParent() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean coordJobA = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    CoordinatorJobBean coordJobB = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJobA1 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJobA2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJobB = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfActionA1 = addRecordToWfActionTable(wfJobA1.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfActionA2 = addRecordToWfActionTable(wfJobA2.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfActionB = addRecordToWfActionTable(wfJobB.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordActionA1 = addRecordToCoordActionTable(coordJobA.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobA1.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordActionA2 = addRecordToCoordActionTable(coordJobA.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobA2.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordActionB = addRecordToCoordActionTable(coordJobB.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobB.getId(), "SUCCEEDED", 0);
    List<String> children = new ArrayList<String>();
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJobA.getId(), 10)));
    checkChildren(children, wfJobA1.getId(), wfJobA2.getId());
    children = new ArrayList<String>();
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJobB.getId(), 10)));
    checkChildren(children, wfJobB.getId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 2 with WorkflowActionBean

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

the class TestWorkflowJobsGetFromCoordParentIdJPAExecutor method testGetWorkflowParentTooMany.

public void testGetWorkflowParentTooMany() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJob1 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob3 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob4 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob5 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowActionBean wfAction1 = addRecordToWfActionTable(wfJob1.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction2 = addRecordToWfActionTable(wfJob2.getId(), "2", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction3 = addRecordToWfActionTable(wfJob3.getId(), "2", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction4 = addRecordToWfActionTable(wfJob4.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction5 = addRecordToWfActionTable(wfJob5.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction1 = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob1.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction2 = addRecordToCoordActionTable(coordJob.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob2.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction3 = addRecordToCoordActionTable(coordJob.getId(), 3, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob3.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction4 = addRecordToCoordActionTable(coordJob.getId(), 4, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob4.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction5 = addRecordToCoordActionTable(coordJob.getId(), 5, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob5.getId(), "SUCCEEDED", 0);
    List<String> children = new ArrayList<String>();
    // Get the first 3
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJob.getId(), 3)));
    assertEquals(3, children.size());
    // Get the next 3 (though there's only 2 more)
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJob.getId(), 3, 3)));
    assertEquals(5, children.size());
    checkChildren(children, wfJob1.getId(), wfJob2.getId(), wfJob3.getId(), wfJob4.getId(), wfJob5.getId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 3 with WorkflowActionBean

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

the class TestWorkflowJobsGetFromWorkflowParentIdJPAExecutor method testGetCoordinatorParentTooMany.

public void testGetCoordinatorParentTooMany() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean subwfJob1 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowJobBean subwfJob2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowJobBean subwfJob3 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowJobBean subwfJob4 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowJobBean subwfJob5 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowActionBean wfAction1 = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction2 = addRecordToWfActionTable(wfJob.getId(), "2", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction3 = addRecordToWfActionTable(wfJob.getId(), "3", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction4 = addRecordToWfActionTable(wfJob.getId(), "4", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction5 = addRecordToWfActionTable(wfJob.getId(), "5", WorkflowAction.Status.OK);
    WorkflowActionBean subwfAction1 = addRecordToWfActionTable(subwfJob1.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean subwfAction2 = addRecordToWfActionTable(subwfJob2.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean subwfAction3 = addRecordToWfActionTable(subwfJob3.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean subwfAction4 = addRecordToWfActionTable(subwfJob4.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean subwfAction5 = addRecordToWfActionTable(subwfJob5.getId(), "1", WorkflowAction.Status.OK);
    List<String> children = new ArrayList<String>();
    // Get the first 3
    children.addAll(jpaService.execute(new WorkflowJobsGetFromWorkflowParentIdJPAExecutor(wfJob.getId(), 3)));
    assertEquals(3, children.size());
    // Get the next 3 (though there's only 2 more)
    children.addAll(jpaService.execute(new WorkflowJobsGetFromWorkflowParentIdJPAExecutor(wfJob.getId(), 3, 3)));
    assertEquals(5, children.size());
    checkChildren(children, subwfJob1.getId(), subwfJob2.getId(), subwfJob3.getId(), subwfJob4.getId(), subwfJob5.getId());
}
Also used : ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 4 with WorkflowActionBean

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

the class TestRecoveryService method testWorkflowActionRecoveryService.

/**
 * Tests functionality of the Recovery Service Runnable command. </p> Starts an action which behaves like an Async
 * Action (Action and Job state set to Running). Changes the action configuration to run in sync mode and updates
 * the store. Runs the recovery runnable, and ensures the state of the action and job have not changed. </p> Changes
 * the state of the action from RUNNING to PREP and updates the store. Again, runs the recovery runnable and ensures
 * the state changes to OK and the job completes successfully.
 *
 * @throws Exception
 */
public void testWorkflowActionRecoveryService() throws Exception {
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    createTestCaseSubDir("lib");
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine(getTestUser());
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("external-status", "ok");
    conf.set("signal-value", "based_on_action_status");
    conf.set("running-mode", "async");
    // TODO CHECK, without this we get JPA concurrency exceptions, ODD
    sleep(1000);
    final String jobId = engine.submitJob(conf, true);
    // TODO CHECK, without this we get JPA concurrency exceptions, ODD
    sleep(1000);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
        }
    });
    sleep(1000);
    final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    store.beginTrx();
    List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    final String actionId = action.getId();
    assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
    String actionConf = action.getConf();
    String fixedActionConf = actionConf.replaceAll("async", "sync");
    action.setConf(fixedActionConf);
    action.setPending();
    store.updateAction(action);
    store.commitTrx();
    store.closeTrx();
    Runnable recoveryRunnable = new RecoveryRunnable(0, 60, 60);
    recoveryRunnable.run();
    sleep(3000);
    final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
    assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
    store2.beginTrx();
    WorkflowActionBean action2 = store2.getAction(actionId, false);
    assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
    action2.setStatus(WorkflowActionBean.Status.PREP);
    action2.setPending();
    store2.updateAction(action2);
    store2.commitTrx();
    store2.closeTrx();
    sleep(1000);
    recoveryRunnable.run();
    sleep(3000);
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getWorkflowAction(actionId).getStatus() == WorkflowActionBean.Status.OK);
        }
    });
    // getPendingActions works correctly only with MYSQL - following assertsfail with hsql - to be investigated
    // assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
    final WorkflowStore store3 = Services.get().get(WorkflowStoreService.class).create();
    store3.beginTrx();
    WorkflowActionBean action3 = store3.getAction(actionId, false);
    assertEquals(WorkflowActionBean.Status.OK, action3.getStatus());
    store3.commitTrx();
    store3.closeTrx();
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowStore(org.apache.oozie.store.WorkflowStore) FileWriter(java.io.FileWriter) Reader(java.io.Reader) StringReader(java.io.StringReader) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) File(java.io.File) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter)

Example 5 with WorkflowActionBean

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

the class TestShareLibService method testAddShareLib_pig_withVersion.

@Test
public void testAddShareLib_pig_withVersion() throws Exception {
    setShipLauncherInOozieConfig();
    FileSystem fs = getFileSystem();
    Date time = new Date(System.currentTimeMillis());
    Path basePath = new Path(getOozieConfig().get(WorkflowAppService.SYSTEM_LIB_PATH));
    Path libpath = new Path(basePath, ShareLibService.SHARE_LIB_PREFIX + ShareLibService.dateFormat.format(time));
    fs.mkdirs(libpath);
    Path pigPath = new Path(libpath.toString() + Path.SEPARATOR + "pig");
    Path pigPath1 = new Path(libpath.toString() + Path.SEPARATOR + "pig_9");
    Path pigPath2 = new Path(libpath.toString() + Path.SEPARATOR + "pig_10");
    fs.mkdirs(pigPath);
    fs.mkdirs(pigPath1);
    fs.mkdirs(pigPath2);
    createFiles(libpath.toString() + Path.SEPARATOR + "pig_10" + Path.SEPARATOR + "pig-10.jar");
    services.init();
    String actionXml = "<pig>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<property><name>oozie.action.sharelib.for.pig</name><value>pig_10</value></property>" + "</pig>";
    Element eActionXml = XmlUtils.parseXml(actionXml);
    XConfiguration protoConf = new XConfiguration();
    protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
    WorkflowJobBean wfj = new WorkflowJobBean();
    protoConf.setBoolean(OozieClient.USE_SYSTEM_LIBPATH, true);
    wfj.setProtoActionConf(XmlUtils.prettyPrint(protoConf).toString());
    wfj.setConf(XmlUtils.prettyPrint(protoConf).toString());
    Context context = new TestJavaActionExecutor().new Context(wfj, new WorkflowActionBean());
    PigActionExecutor ae = new PigActionExecutor();
    Configuration jobConf = ae.createBaseHadoopConf(context, eActionXml);
    jobConf.set("oozie.action.sharelib.for.pig", "pig_10");
    ae.setLibFilesArchives(context, eActionXml, new Path("hdfs://dummyAppPath"), jobConf);
    verifyFilesInDistributedCache(DistributedCache.getCacheFiles(jobConf), "MyPig.jar", "MyOozie.jar", "pig-10.jar");
}
Also used : Path(org.apache.hadoop.fs.Path) Context(org.apache.oozie.action.hadoop.ActionExecutorTestCase.Context) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) Element(org.jdom.Element) TestJavaActionExecutor(org.apache.oozie.action.hadoop.TestJavaActionExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) PigActionExecutor(org.apache.oozie.action.hadoop.PigActionExecutor) Test(org.junit.Test)

Aggregations

WorkflowActionBean (org.apache.oozie.WorkflowActionBean)249 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)164 XConfiguration (org.apache.oozie.util.XConfiguration)84 JPAService (org.apache.oozie.service.JPAService)79 Configuration (org.apache.hadoop.conf.Configuration)56 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)51 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)51 Path (org.apache.hadoop.fs.Path)48 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)42 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)32 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)32 ArrayList (java.util.ArrayList)30 Date (java.util.Date)29 Element (org.jdom.Element)29 FileSystem (org.apache.hadoop.fs.FileSystem)25 Writer (java.io.Writer)22 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 IOException (java.io.IOException)20 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)18