Search in sources :

Example 71 with BundleJobBean

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

the class BundleJobQueryExecutor method getIfExist.

@Override
public BundleJobBean getIfExist(BundleJobQuery namedQuery, Object... parameters) throws JPAExecutorException {
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    Query query = getSelectQuery(namedQuery, em, parameters);
    Object ret = jpaService.executeGet(namedQuery.name(), query, em);
    if (ret == null) {
        return null;
    }
    BundleJobBean bean = constructBean(namedQuery, ret, parameters);
    return bean;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService)

Example 72 with BundleJobBean

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

the class BundleJobQueryExecutor method getList.

@Override
public List<BundleJobBean> getList(BundleJobQuery namedQuery, Object... parameters) throws JPAExecutorException {
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    Query query = getSelectQuery(namedQuery, em, parameters);
    List<?> retList = (List<?>) jpaService.executeGetList(namedQuery.name(), query, em);
    List<BundleJobBean> beanList = new ArrayList<BundleJobBean>();
    if (retList != null) {
        for (Object ret : retList) {
            beanList.add(constructBean(namedQuery, ret));
        }
    }
    return beanList;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService)

Example 73 with BundleJobBean

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

the class BundleJobsGetPausedJPAExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public List<BundleJobBean> execute(EntityManager em) throws JPAExecutorException {
    List<BundleJobBean> bjBeans;
    try {
        Query q = em.createNamedQuery("GET_BUNDLE_JOBS_PAUSED");
        if (limit > 0) {
            q.setMaxResults(limit);
        }
        bjBeans = q.getResultList();
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    return bjBeans;
}
Also used : Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean)

Example 74 with BundleJobBean

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

the class TestV1JobsServletBundleEngine method testGetBundleJobs.

/**
 * Tests method {@link BundleEngine#getBundleJobs(String, int, int)}. Also
 * tests positive cases of the filter parsing by
 * {@link BundleEngine#parseFilter(String)}.
 */
public void testGetBundleJobs() throws Exception {
    final BundleJobBean bundleJobBean = xDataTestCase.addRecordToBundleJobTable(Job.Status.PREP, false);
    runTest("/v1/jobs", V1JobsServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            MockDagEngineService.reset();
            Map<String, String> params = new HashMap<String, String>();
            params.put(RestConstants.JOBTYPE_PARAM, "bundle");
            params.put(RestConstants.JOBS_FILTER_PARAM, OozieClient.FILTER_STATUS + "=PREP;" + OozieClient.FILTER_NAME + "=BUNDLE-TEST;" + OozieClient.FILTER_USER + "=" + getTestUser());
            URL url = createURL("", 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 json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream()));
            assertEquals(Long.valueOf(1L), json.get("total"));
            JSONArray array = (JSONArray) json.get("bundlejobs");
            JSONObject jo = (JSONObject) array.get(0);
            assertEquals(bundleJobBean.getId(), jo.get("bundleJobId"));
            return null;
        }
    });
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONArray(org.json.simple.JSONArray) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) BundleJobBean(org.apache.oozie.BundleJobBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 75 with BundleJobBean

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

the class TestOozieJobInfo method createBundleJob.

protected BundleJobBean createBundleJob(Job.Status jobStatus, boolean pending) throws Exception {
    Path coordPath1 = new Path(getFsTestCaseDir(), "coord1");
    String coord = "<coordinator-app name='COORD-TEST' frequency='${coord:days(1)}' " + "start=\"${START_TIME}\" end=\"${END_TIME}\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\">" + "<controls>" + "<concurrency>2</concurrency>" + "<execution>LIFO</execution>" + "</controls>" + "<action>" + "<workflow>" + "<app-path>${wfAppPath}</app-path>" + "<configuration>" + "<property>" + "<name>inputA</name>" + "<value>aaaa</value>" + "</property>" + "</configuration>" + "</workflow> " + "</action>" + "</coordinator-app>";
    writeToFile(coord, coordPath1, "coordinator.xml");
    Path bundleAppPath = new Path(getFsTestCaseDir(), "bundle");
    String bundleAppXml = "<bundle-app name='test_bundle' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " + "xmlns='uri:oozie:bundle:0.1'> " + "<controls> <kick-off-time>2009-02-02T00:00Z</kick-off-time> </controls> " + "<coordinator name='c12'> " + "<app-path>#app_path1</app-path>" + "<configuration> " + "<property> <name>START_TIME</name> <value>2009-02-01T00:00Z</value> </property> </configuration> " + "</coordinator></bundle-app>";
    bundleAppXml = bundleAppXml.replaceAll("#app_path1", Matcher.quoteReplacement(new Path(coordPath1.toString(), "coordinator.xml").toString()));
    writeToFile(bundleAppXml, bundleAppPath, "bundle.xml");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.BUNDLE_APP_PATH, bundleAppPath.toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("jobTracker", getJobTrackerUri());
    conf.set("nameNode", getNameNodeUri());
    conf.set("appName", "bundle-app-name");
    conf.set("start", "2009-02-01T00:00Z");
    conf.set("end", "2009-02-01T00:00Z");
    conf.set("START_TIME", "2009-02-01T00:00Z");
    conf.set("END_TIME", "2009-03-01T00:00Z");
    setCoordConf(conf);
    BundleJobBean bundle = new BundleJobBean();
    bundle.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.BUNDLE));
    bundle.setAppName("BUNDLE-TEST");
    bundle.setAppPath(bundleAppPath.toString());
    bundle.setConf(XmlUtils.prettyPrint(conf).toString());
    bundle.setConsoleUrl("consoleUrl");
    bundle.setCreatedTime(new Date());
    bundle.setJobXml(bundleAppXml);
    bundle.setLastModifiedTime(new Date());
    bundle.setOrigJobXml(bundleAppXml);
    if (pending) {
        bundle.setPending();
    } else {
        bundle.resetPending();
    }
    bundle.setStatus(jobStatus);
    bundle.setUser(conf.get(OozieClient.USER_NAME));
    return bundle;
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) BundleJobBean(org.apache.oozie.BundleJobBean) Date(java.util.Date)

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