Search in sources :

Example 21 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class BatchQueryExecutor method executeBatchInsertUpdateDelete.

@SuppressWarnings("rawtypes")
public void executeBatchInsertUpdateDelete(Collection<JsonBean> insertList, Collection<UpdateEntry> updateList, Collection<JsonBean> deleteList) throws JPAExecutorException {
    List<QueryEntry> queryList = new ArrayList<QueryEntry>();
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    if (updateList != null) {
        for (UpdateEntry entry : updateList) {
            Query query = null;
            JsonBean bean = entry.getBean();
            if (bean instanceof WorkflowJobBean) {
                query = WorkflowJobQueryExecutor.getInstance().getUpdateQuery((WorkflowJobQuery) entry.getQueryName(), (WorkflowJobBean) entry.getBean(), em);
            } else if (bean instanceof WorkflowActionBean) {
                query = WorkflowActionQueryExecutor.getInstance().getUpdateQuery((WorkflowActionQuery) entry.getQueryName(), (WorkflowActionBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorJobBean) {
                query = CoordJobQueryExecutor.getInstance().getUpdateQuery((CoordJobQuery) entry.getQueryName(), (CoordinatorJobBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorActionBean) {
                query = CoordActionQueryExecutor.getInstance().getUpdateQuery((CoordActionQuery) entry.getQueryName(), (CoordinatorActionBean) entry.getBean(), em);
            } else if (bean instanceof BundleJobBean) {
                query = BundleJobQueryExecutor.getInstance().getUpdateQuery((BundleJobQuery) entry.getQueryName(), (BundleJobBean) entry.getBean(), em);
            } else if (bean instanceof BundleActionBean) {
                query = BundleActionQueryExecutor.getInstance().getUpdateQuery((BundleActionQuery) entry.getQueryName(), (BundleActionBean) entry.getBean(), em);
            } else if (bean instanceof SLARegistrationBean) {
                query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery((SLARegQuery) entry.getQueryName(), (SLARegistrationBean) entry.getBean(), em);
            } else if (bean instanceof SLASummaryBean) {
                query = SLASummaryQueryExecutor.getInstance().getUpdateQuery((SLASummaryQuery) entry.getQueryName(), (SLASummaryBean) entry.getBean(), em);
            } else {
                throw new JPAExecutorException(ErrorCode.E0603, "BatchQueryExecutor failed to construct a query");
            }
            queryList.add(new QueryEntry(entry.getQueryName(), query));
        }
    }
    jpaService.executeBatchInsertUpdateDelete(insertList, queryList, deleteList, em);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Query(javax.persistence.Query) WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) BundleActionQuery(org.apache.oozie.executor.jpa.BundleActionQueryExecutor.BundleActionQuery) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) QueryEntry(org.apache.oozie.service.JPAService.QueryEntry) EntityManager(javax.persistence.EntityManager) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleActionBean(org.apache.oozie.BundleActionBean) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 22 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class BaseJobServlet method doGet.

/**
 * Return information about jobs.
 */
@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String jobId = getResourceName(request);
    String show = request.getParameter(RestConstants.JOB_SHOW_PARAM);
    String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
    try {
        AuthorizationService auth = Services.get().get(AuthorizationService.class);
        auth.authorizeForJob(getUser(request), jobId, false);
    } catch (AuthorizationException ex) {
        throw new XServletException(HttpServletResponse.SC_UNAUTHORIZED, ex);
    }
    if (show == null || show.equals(RestConstants.JOB_SHOW_INFO)) {
        stopCron();
        JsonBean job = null;
        try {
            job = getJob(request, response);
        } catch (BaseEngineException e) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, e);
        }
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, job, timeZoneId);
    } else if (show.equals(RestConstants.ALL_WORKFLOWS_FOR_COORD_ACTION)) {
        stopCron();
        JSONObject json = getJobsByParentId(request, response);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (show.equals(RestConstants.JOB_SHOW_JMS_TOPIC)) {
        stopCron();
        String jmsTopicName = getJMSTopicName(request, response);
        JSONObject json = new JSONObject();
        json.put(JsonTags.JMS_TOPIC_NAME, jmsTopicName);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (show.equals(RestConstants.JOB_SHOW_LOG)) {
        response.setContentType(TEXT_UTF8);
        streamJobLog(request, response);
    } else if (show.equals(RestConstants.JOB_SHOW_ERROR_LOG)) {
        response.setContentType(TEXT_UTF8);
        streamJobErrorLog(request, response);
    } else if (show.equals(RestConstants.JOB_SHOW_AUDIT_LOG)) {
        response.setContentType(TEXT_UTF8);
        streamJobAuditLog(request, response);
    } else if (show.equals(RestConstants.JOB_SHOW_DEFINITION)) {
        stopCron();
        response.setContentType(XML_UTF8);
        String wfDefinition = getJobDefinition(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().write(wfDefinition);
    } else if (show.equals(RestConstants.JOB_SHOW_GRAPH)) {
        stopCron();
        streamJobGraph(request, response);
        // -- should happen before you stream anything in response?
        startCron();
    } else if (show.equals(RestConstants.JOB_SHOW_STATUS)) {
        stopCron();
        String status = getJobStatus(request, response);
        JSONObject json = new JSONObject();
        json.put(JsonTags.STATUS, status);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (show.equals(RestConstants.JOB_SHOW_ACTION_RETRIES_PARAM)) {
        stopCron();
        JSONArray retries = getActionRetries(request, response);
        JSONObject json = new JSONObject();
        json.put(JsonTags.WORKFLOW_ACTION_RETRIES, retries);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (show.equals(RestConstants.COORD_ACTION_MISSING_DEPENDENCIES)) {
        stopCron();
        JSONObject json = getCoordActionMissingDependencies(request, response);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (show.equals(RestConstants.JOB_SHOW_WF_ACTIONS_IN_COORD)) {
        stopCron();
        JSONObject json = getWfActionByJobIdAndName(request, response);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303, RestConstants.JOB_SHOW_PARAM, show);
    }
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) JSONObject(org.json.simple.JSONObject) AuthorizationService(org.apache.oozie.service.AuthorizationService) AuthorizationException(org.apache.oozie.service.AuthorizationException) BaseEngineException(org.apache.oozie.BaseEngineException) JSONArray(org.json.simple.JSONArray)

Example 23 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class V0JobServlet method getJob.

/*
     * v0 service method to get a job in JsonBean representation
     */
@Override
protected JsonBean getJob(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
    JsonBean jobBean = null;
    String jobId = getResourceName(request);
    try {
        jobBean = (JsonBean) dagEngine.getJob(jobId);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return jobBean;
}
Also used : DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JsonBean(org.apache.oozie.client.rest.JsonBean) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 24 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangePauseTime.

/**
 * test pause time change : pending should mark false if job is running with
 * pending true. two actions should be removed for pause time changes.
 *
 * @throws Exception
 */
public void testCoordChangePauseTime() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-01T04:59Z");
    // 2 hrs
    Date pauseTime = new Date(startTime.getTime() + (3 * HOURS_IN_MS));
    String pauseTimeChangeStr = "pausetime=" + DateUtils.formatDateOozieTZ(pauseTime);
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.RUNNING, startTime, endTime, endTime, true, false, 4);
    CoordinatorActionBean ca1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean ca2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
    CoordinatorActionBean ca3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
    CoordinatorActionBean ca4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));
    SLARegistrationBean slaRegBean1 = new SLARegistrationBean();
    slaRegBean1.setId(ca1.getId());
    SLARegistrationBean slaRegBean2 = new SLARegistrationBean();
    slaRegBean2.setId(ca2.getId());
    SLARegistrationBean slaRegBean3 = new SLARegistrationBean();
    slaRegBean3.setId(ca3.getId());
    SLARegistrationBean slaRegBean4 = new SLARegistrationBean();
    slaRegBean4.setId(ca4.getId());
    SLASummaryBean slaSummaryBean1 = new SLASummaryBean();
    slaSummaryBean1.setId(ca1.getId());
    SLASummaryBean slaSummaryBean3 = new SLASummaryBean();
    slaSummaryBean3.setId(ca3.getId());
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(slaRegBean1);
    insertList.add(slaRegBean2);
    insertList.add(slaRegBean3);
    insertList.add(slaRegBean4);
    insertList.add(slaSummaryBean1);
    insertList.add(slaSummaryBean3);
    JPAService jpaService = Services.get().get(JPAService.class);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    new CoordChangeXCommand(job.getId(), pauseTimeChangeStr).call();
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getPauseTime()), DateUtils.formatDateOozieTZ(pauseTime));
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    assertEquals(2, coordJob.getLastActionNumber());
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 3));
        fail("Expected to fail as action 3 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 4));
        fail("Expected to fail as action 4 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    slaRegBean1 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean1.getId());
    assertNotNull(slaRegBean1);
    slaRegBean2 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean2.getId());
    assertNotNull(slaRegBean2);
    slaRegBean3 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean3.getId());
    assertNull(slaRegBean3);
    slaRegBean4 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean4.getId());
    assertNull(slaRegBean4);
    slaSummaryBean3 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean3.getId());
    assertNull(slaSummaryBean3);
    slaSummaryBean1 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean1.getId());
    assertNotNull(slaSummaryBean1);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordJobGetActionByActionNumberJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionByActionNumberJPAExecutor) JPAService(org.apache.oozie.service.JPAService) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 25 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class DummySLACalculatorMemory method createDBEntryForStarted.

private SLASummaryBean createDBEntryForStarted(String actionId, Date expectedStartTS, Date expectedEndTS, int eventProcessed) throws Exception {
    ArrayList<JsonBean> insertList = new ArrayList<JsonBean>();
    Date modTime = new Date();
    WorkflowJobBean wf = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, actionId);
    wf.setStatus(wf.getStatus());
    wf.setStartTime(expectedStartTS);
    wf.setLastModifiedTime(modTime);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wf);
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    coordAction.setId(actionId);
    coordAction.setJobId(actionId.split("@", -1)[0]);
    coordAction.setStatusStr("RUNNING");
    coordAction.setLastModifiedTime(modTime);
    coordAction.setExternalId(wf.getId());
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(actionId.split("@", -1)[0]);
    coordJob.setUser("dummy");
    coordJob.setAppName("dummy");
    coordJob.setStatusStr("RUNNING");
    coordJob.setAppNamespace("dummy");
    SLASummaryBean sla = new SLASummaryBean();
    sla.setId(actionId);
    sla.setAppType(AppType.COORDINATOR_ACTION);
    sla.setJobStatus("RUNNING");
    sla.setSLAStatus(SLAStatus.IN_PROCESS);
    sla.setEventProcessed(eventProcessed);
    sla.setLastModifiedTime(modTime);
    sla.setExpectedStart(expectedStartTS);
    sla.setActualStart(expectedStartTS);
    sla.setExpectedEnd(expectedEndTS);
    sla.setExpectedDuration(10 * 60 * 1000);
    SLARegistrationBean reg = new SLARegistrationBean();
    reg.setId(actionId);
    insertList.add(coordAction);
    insertList.add(coordJob);
    insertList.add(sla);
    insertList.add(reg);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    return sla;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Aggregations

JsonBean (org.apache.oozie.client.rest.JsonBean)28 ArrayList (java.util.ArrayList)20 Date (java.util.Date)15 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)10 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)9 JPAService (org.apache.oozie.service.JPAService)9 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)7 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)7 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)6 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)5 BundleActionBean (org.apache.oozie.BundleActionBean)3 CommandException (org.apache.oozie.command.CommandException)3 IOException (java.io.IOException)2 BundleJobBean (org.apache.oozie.BundleJobBean)2 DagEngine (org.apache.oozie.DagEngine)2 DagEngineException (org.apache.oozie.DagEngineException)2 PreconditionException (org.apache.oozie.command.PreconditionException)2