Search in sources :

Example 21 with BundleJobBean

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

the class TestV1JobServletBundleEngine method testBundleEngineStreamLog.

public void testBundleEngineStreamLog() throws Exception {
    final BundleJobBean bundleJobBean = xDataTestCase.addRecordToBundleJobTable(Job.Status.PREP, false);
    runTest("/v1/job/*", V1JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            MockCoordinatorEngineService.reset();
            Map<String, String> params = new HashMap<String, String>();
            params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_LOG);
            final String id = bundleJobBean.getId();
            URL url = createURL(id, params);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
            return null;
        }
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL)

Example 22 with BundleJobBean

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

the class TestV1JobServletBundleEngine method testBundleEngineGetDefinition.

public void testBundleEngineGetDefinition() throws Exception {
    final BundleJobBean bundleJobBean = xDataTestCase.addRecordToBundleJobTable(Job.Status.PREP, false);
    runTest("/v1/job/*", V1JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            MockCoordinatorEngineService.reset();
            Map<String, String> params = new HashMap<String, String>();
            params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_DEFINITION);
            final String id = bundleJobBean.getId();
            URL url = createURL(id, params);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
            String ct = conn.getHeaderField("content-type");
            assertTrue(ct.startsWith(RestConstants.XML_CONTENT_TYPE));
            String response = IOUtils.getReaderAsString(new InputStreamReader(conn.getInputStream()), -1);
            assertTrue(response != null && response.length() > 0);
            return null;
        }
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL)

Example 23 with BundleJobBean

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

the class TestV1JobServletBundleEngine method testBundleEngineGetBundleJob.

public void testBundleEngineGetBundleJob() throws Exception {
    final BundleJobBean bundleJobBean = xDataTestCase.addRecordToBundleJobTable(Job.Status.PREP, false);
    runTest("/v1/job/*", V1JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            MockCoordinatorEngineService.reset();
            Map<String, String> params = new HashMap<String, String>();
            params.put(RestConstants.JOB_SHOW_PARAM, RestConstants.JOB_SHOW_INFO);
            final String id = bundleJobBean.getId();
            URL url = createURL(id, params);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
            assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE));
            JSONObject obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream()));
            assertEquals(id, obj.get("bundleJobId"));
            return null;
        }
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) InputStreamReader(java.io.InputStreamReader) BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL)

Example 24 with BundleJobBean

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

the class TestCoordUpdateXCommand method setUpBundleAndGetCoordID.

private String setUpBundleAndGetCoordID(XConfiguration jobConf) throws UnsupportedEncodingException, IOException, CommandException, JPAExecutorException {
    final Path coordPath1 = new Path(getFsTestCaseDir(), "coord1");
    final Path coordPath2 = new Path(getFsTestCaseDir(), "coord2");
    writeCoordXml(coordPath1, "coord-multiple-input-instance3.xml");
    writeCoordXml(coordPath2, "coord-multiple-input-instance3.xml");
    Path bundleAppPath = new Path(getFsTestCaseDir(), "bundle");
    String bundleAppXml = getBundleXml("bundle-submit-job.xml");
    assertNotNull(bundleAppXml);
    assertTrue(bundleAppXml.length() > 0);
    bundleAppXml = bundleAppXml.replaceAll("#app_path1", Matcher.quoteReplacement(new Path(coordPath1.toString(), "coordinator.xml").toString()));
    bundleAppXml = bundleAppXml.replaceAll("#app_path2", Matcher.quoteReplacement(new Path(coordPath2.toString(), "coordinator.xml").toString()));
    writeToFile(bundleAppXml, bundleAppPath, "bundle.xml");
    final Path appPath = new Path(bundleAppPath, "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    jobConf.set("appName", "test");
    jobConf.set(OozieClient.USER_NAME, getTestUser());
    jobConf.set("coordName1", "NAME");
    jobConf.set("coordName2", "coord2");
    jobConf.set("isEnabled", "true");
    BundleSubmitXCommand command = new BundleSubmitXCommand(jobConf);
    final BundleJobBean bundleBean = (BundleJobBean) command.getJob();
    bundleBean.setStartTime(new Date());
    bundleBean.setEndTime(new Date());
    final String jobId = command.call();
    sleep(2000);
    new BundleStartXCommand(jobId).call();
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
            return actions.get(0).getStatus().equals(Job.Status.RUNNING);
        }
    });
    final List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
    return actions.get(0).getCoordId();
}
Also used : Path(org.apache.hadoop.fs.Path) BundleSubmitXCommand(org.apache.oozie.command.bundle.BundleSubmitXCommand) BundleStartXCommand(org.apache.oozie.command.bundle.BundleStartXCommand) BundleJobBean(org.apache.oozie.BundleJobBean) List(java.util.List) BundleActionBean(org.apache.oozie.BundleActionBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 25 with BundleJobBean

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

the class TestPurgeXCommand method testPurgeBundleWithCoordChildWithWFChild3.

/**
 * Test : The workflow and coordinator should get purged, and the bundle parent should get purged --> all will get purged
 *
 * @throws Exception
 */
public void testPurgeBundleWithCoordChildWithWFChild3() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobBean bundleJob = addRecordToBundleJobTable(Job.Status.SUCCEEDED, DateUtils.parseDateOozieTZ("2011-01-01T01:00Z"));
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob.getId(), "SUCCEEDED", 0);
    BundleActionBean bundleAction = addRecordToBundleActionTable(bundleJob.getId(), coordJob.getId(), coordJob.getAppName(), 0, Job.Status.SUCCEEDED);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(wfJob.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(wfAction.getId());
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(bundleJob.getId());
    BundleActionGetJPAExecutor bundleActionGetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob.getAppName());
    wfJob = jpaService.execute(wfJobGetCmd);
    wfAction = jpaService.execute(wfActionGetCmd);
    coordJob = jpaService.execute(coordJobGetCmd);
    coordAction = jpaService.execute(coordActionGetCmd);
    bundleJob = jpaService.execute(bundleJobGetCmd);
    bundleAction = jpaService.execute(bundleActionGetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleJob.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction.getStatus());
    new PurgeXCommand(7, 7, 7, 10).call();
    try {
        jpaService.execute(bundleJobGetCmd);
        fail("Bundle Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(bundleActionGetCmd);
        fail("Bundle Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    try {
        jpaService.execute(coordJobGetCmd);
        fail("Coordinator Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(coordActionGetCmd);
        fail("Coordinator Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    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) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

BundleJobBean (org.apache.oozie.BundleJobBean)159 JPAService (org.apache.oozie.service.JPAService)78 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)69 BundleActionBean (org.apache.oozie.BundleActionBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)46 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)44 Date (java.util.Date)35 ArrayList (java.util.ArrayList)24 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 List (java.util.List)21 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 HashMap (java.util.HashMap)20 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)18 IOException (java.io.IOException)16 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 XConfiguration (org.apache.oozie.util.XConfiguration)16 Query (javax.persistence.Query)14 CommandException (org.apache.oozie.command.CommandException)14