Search in sources :

Example 11 with WorkflowJobBean

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

the class MockDagEngineService method createDummyWorkflow.

private static WorkflowJob createDummyWorkflow(int idx, String conf) {
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(JOB_ID + idx + JOB_ID_END);
    workflow.setAppPath("hdfs://blah/blah/" + idx + "-blah");
    workflow.setStatus((idx % 2) == 0 ? WorkflowJob.Status.RUNNING : WorkflowJob.Status.SUCCEEDED);
    workflow.setRun(idx);
    workflow.setCreatedTime(new Date());
    workflow.setStartTime(new Date());
    workflow.setEndTime((idx % 2) == 0 ? null : (new Date()));
    workflow.setConf(conf);
    workflow.setAppName("workflow-" + idx);
    workflow.setGroup(GROUP);
    workflow.setUser(USER);
    List<WorkflowActionBean> actions = new ArrayList<WorkflowActionBean>();
    for (int i = 0; i < idx; i++) {
        actions.add(createDummyAction(i));
    }
    workflow.setActions(actions);
    return workflow;
}
Also used : ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 12 with WorkflowJobBean

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

the class TestStatusTransitService method addRecordToWfJobTable.

protected WorkflowJobBean addRecordToWfJobTable(String wfId, WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    Configuration conf = new Configuration();
    Path appUri = new Path(getAppPath(), "workflow.xml");
    conf.set(OozieClient.APP_PATH, appUri.toString());
    conf.set(OozieClient.LOG_TOKEN, "testToken");
    conf.set(OozieClient.USER_NAME, getTestUser());
    WorkflowJobBean wfBean = createWorkflow(app, conf, jobStatus, instanceStatus);
    wfBean.setId(wfId);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wfBean);
        jpaService.execute(wfInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test wf job record to table");
        throw je;
    }
    return wfBean;
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) Path(org.apache.hadoop.fs.Path) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef)

Example 13 with WorkflowJobBean

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

the class TestStatusTransitService method testBundleStatusTransitServiceRunningWithError.

/**
 * Test : kill one coord job and keep the other running. Check whether the bundle job's status
 * is updated to RUNNINGWITHERROR
 * @throws Exception
 */
public void testBundleStatusTransitServiceRunningWithError() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    setClassesToBeExcluded(services.getConf(), excludedServices);
    services.init();
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 1, Job.Status.RUNNING);
    addRecordToBundleActionTable(bundleId, "action2-C", 1, Job.Status.RUNNING);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1-C", CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2-C", CoordinatorJob.Status.RUNNING, start, end, true, false, 2);
    WorkflowJobBean wfJob1_1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_4 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable("action1-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_1.getId(), wfJob1_1.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable("action1-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_2.getId(), wfJob1_2.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_3 = addRecordToCoordActionTable("action2-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_3.getId(), wfJob1_3.getStatusStr(), 1);
    final CoordinatorActionBean coordAction1_4 = addRecordToCoordActionTable("action2-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_4.getId(), wfJob1_4.getStatusStr(), 1);
    new CoordKillXCommand("action1-C").call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(coordAction1_1.getExternalId()));
            return wfJob.getStatus().equals(Job.Status.KILLED);
        }
    });
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.isPending() == false;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertTrue(bundleJob.isPending());
    assertEquals(Job.Status.RUNNINGWITHERROR, bundleJob.getStatus());
    BundleActionBean bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertFalse(bundleAction1.isPending());
    assertEquals(Job.Status.KILLED, bundleAction1.getStatus());
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor("action1-C"));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.KILLED, coordJob1.getStatus());
    BundleActionBean bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action2-C"));
    assertTrue(bundleAction2.isPending());
    assertEquals(Job.Status.RUNNING, bundleAction2.getStatus());
    CoordinatorJobBean coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor("action2-C"));
    assertTrue(coordJob2.isPending());
    assertEquals(Job.Status.RUNNING, coordJob2.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 14 with WorkflowJobBean

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

the class TestAuthorizationService method testErrors.

public void testErrors() throws Exception {
    init(false, true);
    services.setService(ForTestAuthorizationService.class);
    AuthorizationService as = services.get(AuthorizationService.class);
    Configuration conf = new Configuration();
    HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
    URI uri = getFileSystem().getUri();
    Configuration fsConf = has.createConfiguration(uri.getAuthority());
    FileSystem fileSystem = has.createFileSystem(getTestUser(), uri, fsConf);
    try {
        as.authorizeForGroup(getTestUser3(), getTestGroup());
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0502, ex.getErrorCode());
    }
    try {
        as.authorizeForAdmin(getTestUser(), true);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0503, ex.getErrorCode());
    }
    try {
        Path app = new Path(getFsTestCaseDir(), "w");
        as.authorizeForApp(getTestUser(), getTestGroup(), app.toString(), conf);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0504, ex.getErrorCode());
    }
    try {
        Path app = new Path(getFsTestCaseDir(), "w");
        fileSystem.mkdirs(app);
        as.authorizeForApp(getTestUser(), getTestGroup(), app.toString(), conf);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0505, ex.getErrorCode());
    }
    try {
        Path app = new Path(getFsTestCaseDir(), "w");
        Path wf = new Path(app, "workflow.xml");
        fileSystem.mkdirs(wf);
        as.authorizeForApp(getTestUser(), getTestGroup(), app.toString(), conf);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0506, ex.getErrorCode());
    }
    try {
        Path app = new Path(getFsTestCaseDir(), "ww");
        fileSystem.mkdirs(app);
        Path wf = new Path(app, "workflow.xml");
        fileSystem.create(wf).close();
        FsPermission fsPermission = new FsPermission(FsAction.READ, FsAction.NONE, FsAction.NONE);
        fileSystem.setPermission(app, fsPermission);
        as.authorizeForApp(getTestUser2(), getTestGroup() + "-invalid", app.toString(), conf);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0507, ex.getErrorCode());
    }
    try {
        as.authorizeForJob(getTestUser(), "1", true);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0604, ex.getErrorCode());
    }
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    try {
        as.authorizeForJob(getTestUser3(), job.getId(), true);
        fail();
    } catch (AuthorizationException ex) {
        assertEquals(ErrorCode.E0508, ex.getErrorCode());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) FsPermission(org.apache.hadoop.fs.permission.FsPermission) URI(java.net.URI) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 15 with WorkflowJobBean

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

the class DummySLACalculatorMemory method createWorkflow.

private WorkflowJobBean createWorkflow(String id) throws Exception {
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(id);
    workflow.setStatusStr("PREP");
    workflow.setStartTime(new Date());
    workflow.setSlaXml("<sla></sla>");
    insertList.add(workflow);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    return workflow;
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Aggregations

WorkflowJobBean (org.apache.oozie.WorkflowJobBean)304 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)164 JPAService (org.apache.oozie.service.JPAService)95 XConfiguration (org.apache.oozie.util.XConfiguration)94 Configuration (org.apache.hadoop.conf.Configuration)66 Date (java.util.Date)60 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)58 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)57 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)53 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)53 Path (org.apache.hadoop.fs.Path)50 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)32 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)30 Element (org.jdom.Element)28 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)26 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)25 HashMap (java.util.HashMap)23 BundleJobBean (org.apache.oozie.BundleJobBean)21