Search in sources :

Example 1 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance in project oozie by apache.

the class HadoopELFunctions method hadoop_counters.

@SuppressWarnings("unchecked")
public static Map<String, Map<String, Long>> hadoop_counters(String nodeName) throws ELEvaluationException {
    WorkflowInstance instance = DagELFunctions.getWorkflow().getWorkflowInstance();
    Object obj = instance.getTransientVar(nodeName + WorkflowInstance.NODE_VAR_SEPARATOR + HADOOP_COUNTERS);
    Map<String, Map<String, Long>> counters = (Map<String, Map<String, Long>>) obj;
    if (counters == null) {
        counters = getCounters(nodeName);
        instance.setTransientVar(nodeName + WorkflowInstance.NODE_VAR_SEPARATOR + HADOOP_COUNTERS, counters);
    }
    return counters;
}
Also used : WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) Map(java.util.Map)

Example 2 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance in project oozie by apache.

the class TestCoordActionsKillXCommand method createDBRecords.

private String[] createDBRecords() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T23:59Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-02T23:59Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, true, 0);
    CoordinatorActionBean action1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    CoordinatorActionBean action2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    action2.setNominalTime(DateUtils.parseDateOozieTZ("2009-12-15T02:00Z"));
    action2.setExternalId(null);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action2);
    WorkflowJobBean wf = new WorkflowJobBean();
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    wf.setId(action1.getExternalId());
    wf.setStatus(WorkflowJob.Status.RUNNING);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance = workflowLib.createInstance(app, new XConfiguration());
    ((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.RUNNING);
    wf.setWorkflowInstance(wfInstance);
    jpaService.execute(new WorkflowJobInsertJPAExecutor(wf));
    return new String[] { job.getId(), action1.getId(), action2.getId(), wf.getId() };
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) JPAService(org.apache.oozie.service.JPAService)

Example 3 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance in project oozie by apache.

the class TestPurgeXCommand method testKillJobPurgeXCommand.

/**
 * Test : purge killed wf job and action successfully
 *
 * @throws Exception
 */
public void testKillJobPurgeXCommand() throws Exception {
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.KILLED);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.KILLED);
    assertEquals(action.getStatus(), WorkflowAction.Status.KILLED);
    WorkflowInstance wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.KILLED);
    new PurgeXCommand(7, 1, 1, 10).call();
    try {
        jpaService.execute(wfJobGetCmd);
        fail("Workflow Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(wfActionGetCmd);
        fail("Workflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 4 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance in project oozie by apache.

the class TestPurgeXCommand method testPurgeXCommandFailed.

/**
 * Test : purge wf job and action failed
 *
 * @throws Exception
 */
public void testPurgeXCommandFailed() throws Exception {
    WorkflowJobBean job = this.addRecordToWfJobTableForNegCase(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    job = jpaService.execute(wfJobGetCmd);
    action = jpaService.execute(wfActionGetCmd);
    assertEquals(job.getStatus(), WorkflowJob.Status.RUNNING);
    assertEquals(action.getStatus(), WorkflowAction.Status.RUNNING);
    WorkflowInstance wfInstance = job.getWorkflowInstance();
    assertEquals(wfInstance.getStatus(), WorkflowInstance.Status.RUNNING);
    new PurgeXCommand(7, 1, 1, 10).call();
    try {
        jpaService.execute(wfJobGetCmd);
    } catch (JPAExecutorException ce) {
        ce.printStackTrace();
        fail("Workflow Job should not have been purged");
    }
    try {
        jpaService.execute(wfActionGetCmd);
    } catch (JPAExecutorException ce) {
        fail("Workflow Action should have been purged");
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 5 with WorkflowInstance

use of org.apache.oozie.workflow.WorkflowInstance in project oozie by apache.

the class TestPurgeXCommand method createWorkflow.

@Override
protected WorkflowJobBean createWorkflow(WorkflowApp app, Configuration conf, WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    Configuration protoActionConf = wps.createProtoActionConf(conf, true);
    WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
    WorkflowInstance wfInstance = workflowLib.createInstance(app, conf);
    ((LiteWorkflowInstance) wfInstance).setStatus(instanceStatus);
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
    workflow.setAppName(app.getName());
    workflow.setAppPath(conf.get(OozieClient.APP_PATH));
    workflow.setConf(XmlUtils.prettyPrint(conf).toString());
    workflow.setProtoActionConf(XmlUtils.prettyPrint(protoActionConf).toString());
    workflow.setCreatedTime(new Date());
    workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
    workflow.setStatus(jobStatus);
    workflow.setRun(0);
    workflow.setUser(conf.get(OozieClient.USER_NAME));
    workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
    workflow.setWorkflowInstance(wfInstance);
    workflow.setStartTime(DateUtils.parseDateOozieTZ("2009-12-18T01:00Z"));
    workflow.setEndTime(DateUtils.parseDateOozieTZ("2009-12-18T03:00Z"));
    return workflow;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Aggregations

WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)34 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)26 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)17 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 Date (java.util.Date)15 JPAService (org.apache.oozie.service.JPAService)12 XConfiguration (org.apache.oozie.util.XConfiguration)12 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)11 CommandException (org.apache.oozie.command.CommandException)10 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)10 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)9 WorkflowLib (org.apache.oozie.workflow.WorkflowLib)9 Configuration (org.apache.hadoop.conf.Configuration)8 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)7 WorkflowAppService (org.apache.oozie.service.WorkflowAppService)7 WorkflowException (org.apache.oozie.workflow.WorkflowException)7 ELEvaluator (org.apache.oozie.util.ELEvaluator)6 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)6 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5