Search in sources :

Example 1 with CoordinatorWfActionBean

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

the class MockCoordinatorEngineService method createDummyCoordWfAction.

private static CoordinatorWfActionBean createDummyCoordWfAction(String name, int id) {
    CoordinatorWfActionBean coordWfAction = null;
    WorkflowActionBean wfAction = new WorkflowActionBean();
    wfAction.setName(name);
    coordWfAction = new CoordinatorWfActionBean(id, wfAction, null);
    return coordWfAction;
}
Also used : WorkflowActionBean(org.apache.oozie.WorkflowActionBean) CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Example 2 with CoordinatorWfActionBean

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

the class TestCoordWfActionInfoXCommand method testWorkflowInstanceMissing.

public void testWorkflowInstanceMissing() throws CommandException {
    List<CoordinatorWfActionBean> coordWfActions = new CoordWfActionInfoXCommand(coordJob.getId(), "aa", 2, 4).call();
    assertEquals(4, coordWfActions.size());
    CoordinatorWfActionBean coordWfAction = coordWfActions.get(3);
    assertEquals(5, coordWfAction.getActionNumber());
    assertEquals(null, coordWfAction.getAction());
    String expectNullReason = CoordinatorWfAction.NullReason.PARENT_NULL.getNullReason();
    assertEquals(expectNullReason, coordWfAction.getNullReason());
}
Also used : CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Example 3 with CoordinatorWfActionBean

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

the class CoordWfActionInfoXCommand method execute.

@Override
protected List<CoordinatorWfActionBean> execute() throws CommandException {
    List<CoordinatorWfActionBean> coordWfActions = new ArrayList<CoordinatorWfActionBean>();
    for (CoordinatorActionBean coordAction : coordActions) {
        String wfId = coordAction.getExternalId();
        String nullReason = null;
        WorkflowActionBean wfAction = null;
        if (wfId != null) {
            String wfActionId = wfId + "@" + actionName;
            try {
                wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId, true));
                if (wfAction == null) {
                    nullReason = CoordinatorWfAction.NullReason.ACTION_NULL.getNullReason(actionName, wfId);
                }
            } catch (JPAExecutorException ex) {
                throw new CommandException(ex);
            }
        } else {
            nullReason = CoordinatorWfAction.NullReason.PARENT_NULL.getNullReason();
            LOG.warn(nullReason);
            wfAction = null;
        }
        int actionNumber = coordAction.getActionNumber();
        CoordinatorWfActionBean coordWfAction = new CoordinatorWfActionBean(actionNumber, wfAction, nullReason);
        coordWfActions.add(coordWfAction);
    }
    return coordWfActions;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Example 4 with CoordinatorWfActionBean

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

the class V2JobServlet method getWfActionByJobIdAndName.

@Override
protected JSONObject getWfActionByJobIdAndName(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    String jobId = getResourceName(request);
    String action = request.getParameter(RestConstants.ACTION_NAME_PARAM);
    String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
    String lenStr = request.getParameter(RestConstants.LEN_PARAM);
    String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM);
    timeZoneId = (timeZoneId == null) ? "GMT" : timeZoneId;
    if (action == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, RestConstants.ACTION_NAME_PARAM);
    }
    int offset = (startStr != null) ? Integer.parseInt(startStr) : 1;
    offset = (offset < 1) ? 1 : offset;
    /**
     * set default number of wf actions to be retrieved to
     * default number of coordinator actions to be retrieved
     */
    int defaultLen = ConfigurationService.getInt(COORD_ACTIONS_DEFAULT_LENGTH);
    int len = (lenStr != null) ? Integer.parseInt(lenStr) : 0;
    len = getCoordinatorJobLength(defaultLen, len);
    try {
        JSONObject json = new JSONObject();
        List<CoordinatorWfActionBean> coordWfActions = coordEngine.getWfActionByJobIdAndName(jobId, action, offset, len);
        JSONArray array = new JSONArray();
        for (CoordinatorWfActionBean coordWfAction : coordWfActions) {
            array.add(coordWfAction.toJSONObject(timeZoneId));
        }
        json.put(JsonTags.COORDINATOR_JOB_ID, jobId);
        json.put(JsonTags.COORDINATOR_WF_ACTIONS, array);
        return json;
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) JSONArray(org.json.simple.JSONArray) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService) CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Example 5 with CoordinatorWfActionBean

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

the class TestCoordWfActionInfoXCommand method testNormalCase.

public void testNormalCase() throws Exception {
    int offset = 2, len = 2;
    List<CoordinatorWfActionBean> coordWfActions = new CoordWfActionInfoXCommand(coordJob.getId(), "aa", offset, len).call();
    assertEquals(2, coordWfActions.size());
    List<String> wfIds = Arrays.asList(wfJobs.get(1).getId(), wfJobs.get(2).getId());
    for (int i = 0; i < coordWfActions.size(); i++) {
        CoordinatorWfActionBean coordWfAction = coordWfActions.get(i);
        WorkflowActionBean wfAction = coordWfAction.getAction();
        assertEquals(i + offset, coordWfActions.get(i).getActionNumber());
        assertEquals(wfIds.get(i), wfAction.getWfId());
        assertEquals(null, coordWfAction.getNullReason());
    }
}
Also used : WorkflowActionBean(org.apache.oozie.WorkflowActionBean) CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Aggregations

CoordinatorWfActionBean (org.apache.oozie.CoordinatorWfActionBean)7 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)3 ArrayList (java.util.ArrayList)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)1 CoordinatorJob (org.apache.oozie.client.CoordinatorJob)1 CommandException (org.apache.oozie.command.CommandException)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)1 CoordinatorEngineService (org.apache.oozie.service.CoordinatorEngineService)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1