Search in sources :

Example 86 with WorkflowActionBean

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

the class TestWorkflowActionRetryInfoXCommand method validateRetryConsoleUrl.

public void validateRetryConsoleUrl(String wfXml) throws Exception {
    Configuration conf = new XConfiguration();
    File workflowUri = new File(getTestCaseDir(), "workflow.xml");
    writeToFile(wfXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    conf.set("external-childIds", "1");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    final JPAService jpaService = Services.get().get(JPAService.class);
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getType().equals("test")) {
                    action = bean;
                    break;
                }
            }
            return (action != null && action.getUserRetryCount() == 2);
        }
    });
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action1 = null;
    WorkflowActionBean action2 = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test") && bean.getName().equals("action1")) {
            action1 = bean;
        } else if (bean.getType().equals("test") && bean.getName().equals("action2")) {
            action2 = bean;
        }
    }
    WorkflowActionRetryInfoXCommand command = new WorkflowActionRetryInfoXCommand(action1.getId());
    List<Map<String, String>> retriesList = command.call();
    assertEquals(2, retriesList.size());
    assertEquals(2, action1.getUserRetryCount());
    assertEquals(retriesList.get(0).get(JsonTags.ACTION_ATTEMPT), "1");
    assertEquals(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_START_TIME), JsonUtils.formatDateRfc822(action1.getStartTime()));
    assertNotNull(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_CONSOLE_URL));
    assertNotNull(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS));
    assertNotNull(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_CONSOLE_URL));
    assertNotNull(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS));
    final Date actionEndTime = action2 == null ? action1.getEndTime() : action2.getEndTime();
    final Date secondRetryEndTime = JsonUtils.parseDateRfc822(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_END_TIME));
    assertTrue("action end time should be within ten seconds of second retry end time", new Interval(secondRetryEndTime.getTime(), secondRetryEndTime.getTime() + 10_000).contains(actionEndTime.getTime()));
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) Map(java.util.Map) Interval(org.joda.time.Interval)

Example 87 with WorkflowActionBean

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

the class TestWorkflowActionKillXCommand method testWfActionKillSuccess.

/**
 * Test : kill action successfully.
 *
 * @throws Exception
 */
public void testWfActionKillSuccess() throws Exception {
    String externalJobID = launchSleepJob(1000);
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), externalJobID, "1", WorkflowAction.Status.KILLED, null);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(WorkflowAction.Status.KILLED, action.getStatus());
    assertEquals("RUNNING", action.getExternalStatus());
    new ActionKillXCommand(action.getId()).call();
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(WorkflowAction.Status.KILLED, action.getStatus());
    assertEquals("KILLED", action.getExternalStatus());
}
Also used : WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 88 with WorkflowActionBean

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

the class TestWorkflowActionKillXCommand method addRecordToWfActionTable.

protected WorkflowActionBean addRecordToWfActionTable(String wfId, String externalJobID, String actionName, WorkflowAction.Status status, String childID) throws Exception {
    WorkflowActionBean action = new WorkflowActionBean();
    action.setId(Services.get().get(UUIDService.class).generateChildId(wfId, actionName));
    action.setJobId(wfId);
    action.setName(actionName);
    action.setType("map-reduce");
    action.setStatus(status);
    action.setStartTime(new Date());
    action.setEndTime(new Date());
    action.setLastCheckTime(new Date());
    action.setPending();
    action.setExternalId(externalJobID);
    action.setExternalStatus("RUNNING");
    action.setExternalChildIDs(childID);
    String actionXml = "<map-reduce>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<configuration>" + "<property><name>mapred.mapper.class</name><value>" + MapperReducerForTest.class.getName() + "</value></property>" + "<property><name>mapred.reducer.class</name><value>" + MapperReducerForTest.class.getName() + "</value></property>" + "<property><name>mapred.input.dir</name><value>inputDir</value></property>" + "<property><name>mapred.output.dir</name><value>outputDir</value></property>" + "</configuration>" + "</map-reduce>";
    action.setConf(actionXml);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowActionInsertJPAExecutor actionInsertExe = new WorkflowActionInsertJPAExecutor(action);
        jpaService.execute(actionInsertExe);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test wf action record to table");
        throw je;
    }
    return action;
}
Also used : MapperReducerForTest(org.apache.oozie.action.hadoop.MapperReducerForTest) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowActionInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date)

Example 89 with WorkflowActionBean

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

the class TestHCatELFunctions method testHCatTableExists.

@Test
public void testHCatTableExists() throws Exception {
    dropTable("db1", "table1", true);
    dropDatabase("db1", true);
    createDatabase("db1");
    createTable("db1", "table1");
    Configuration protoConf = new Configuration();
    protoConf.set(OozieClient.USER_NAME, getTestUser());
    protoConf.set("hadoop.job.ugi", getTestUser() + "," + "group");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, "appPath");
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("test.dir", getTestCaseDir());
    conf.set("table1", getHCatURI("db1", "table1").toString());
    conf.set("table2", getHCatURI("db1", "table2").toString());
    LiteWorkflowApp def = new LiteWorkflowApp("name", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    LiteWorkflowInstance job = new LiteWorkflowInstance(def, conf, "wfId");
    WorkflowJobBean wf = new WorkflowJobBean();
    wf.setId(job.getId());
    wf.setAppName("name");
    wf.setAppPath("appPath");
    wf.setUser(getTestUser());
    wf.setGroup("group");
    wf.setWorkflowInstance(job);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    protoConf.writeXml(baos);
    wf.setProtoActionConf(baos.toString());
    WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setName("actionName");
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
    DagELFunctions.configureEvaluator(eval, wf, action);
    assertEquals(true, (boolean) eval.evaluate("${hcat:exists(wf:conf('table1'))}", Boolean.class));
    assertEquals(false, (boolean) eval.evaluate("${hcat:exists(wf:conf('table2'))}", Boolean.class));
    dropTable("db1", "table1", true);
    dropDatabase("db1", true);
}
Also used : EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) ELService(org.apache.oozie.service.ELService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) ELEvaluator(org.apache.oozie.util.ELEvaluator) Test(org.junit.Test)

Example 90 with WorkflowActionBean

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

the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDelete.

public void testExecuteBatchUpdateInsertDelete() throws Exception {
    BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
    // for update
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
    // for insert
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    coordAction.setId("testCoordAction1");
    JPAService jpaService = Services.get().get(JPAService.class);
    // update the status
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
    // update the list for doing bulk writes
    List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
    updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_MODTIME, coordJob));
    updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wfJob));
    // insert beans
    Collection<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(coordAction);
    // delete beans
    Collection<JsonBean> deleteList = new ArrayList<JsonBean>();
    deleteList.add(wfAction);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, deleteList);
    // check update after running ExecuteBatchUpdateInsertDelete
    coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coordJob.getId());
    assertEquals("RUNNING", coordJob.getStatusStr());
    wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, wfJob.getId());
    assertEquals("SUCCEEDED", wfJob.getStatusStr());
    coordAction = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordAction.getId());
    assertEquals("testCoordAction1", coordAction.getId());
    try {
        wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfJob.getId());
        fail();
    } catch (JPAExecutorException ex) {
        assertEquals(ex.getErrorCode().toString(), "E0605");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)

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