Search in sources :

Example 1 with CoordinatorActionInfo

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

the class V2JobServlet method ignoreCoordinatorJob.

/**
 * Ignore a coordinator job/action
 *
 * @param request servlet request
 * @param response servlet response
 * @throws XServletException
 */
@SuppressWarnings("unchecked")
private JSONObject ignoreCoordinatorJob(HttpServletRequest request, HttpServletResponse response) throws XServletException {
    JSONObject json = null;
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    String jobId = getResourceName(request);
    String type = request.getParameter(RestConstants.JOB_COORD_RANGE_TYPE_PARAM);
    String scope = request.getParameter(RestConstants.JOB_COORD_SCOPE_PARAM);
    String changeValue = "status=" + CoordinatorAction.Status.IGNORED;
    List<CoordinatorActionBean> coordActions = new ArrayList<CoordinatorActionBean>();
    try {
        if (type != null && !type.equals(RestConstants.JOB_COORD_SCOPE_ACTION)) {
            throw new CommandException(ErrorCode.E1024, "Currently ignore only support -action option");
        }
        CoordinatorActionInfo coordInfo = null;
        if (scope == null || scope.isEmpty()) {
            coordEngine.change(jobId, changeValue);
        } else {
            coordInfo = coordEngine.ignore(jobId, type, scope);
        }
        if (coordInfo != null) {
            coordActions = coordInfo.getCoordActions();
            json = new JSONObject();
            json.put(JsonTags.COORDINATOR_ACTIONS, CoordinatorActionBean.toJSONArray(coordActions, "GMT"));
        }
        return json;
    } catch (CommandException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 2 with CoordinatorActionInfo

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

the class CoordActionsKillXCommand method killChildren.

@Override
public void killChildren() throws CommandException {
    InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
    for (CoordinatorActionBean coordAction : coordActions) {
        coordAction.setStatus(CoordinatorAction.Status.KILLED);
        coordAction.setLastModifiedTime(new Date());
        // kill Workflow job associated with this Coord action
        if (coordAction.getExternalId() != null) {
            queue(new KillXCommand(coordAction.getExternalId()));
            coordAction.incrementAndGetPending();
        } else {
            coordAction.setPending(0);
        }
        updateList.add(new UpdateEntry(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
        if (EventHandlerService.isEnabled()) {
            CoordinatorXCommand.generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), coordAction.getCreatedTime());
        }
        queue(new CoordActionNotificationXCommand(coordAction), 100);
    }
    CoordinatorActionInfo coordInfo = new CoordinatorActionInfo(coordActions);
    ret = coordInfo;
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) KillXCommand(org.apache.oozie.command.wf.KillXCommand) Date(java.util.Date)

Example 3 with CoordinatorActionInfo

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

the class CoordRerunXCommand method rerunChildren.

@Override
public void rerunChildren() throws CommandException {
    boolean isError = false;
    try {
        CoordinatorActionInfo coordInfo = null;
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        if (checkAllActionsRunnable(coordActions)) {
            Map<String, Context> uriHandlerContextMap = new HashMap<String, Context>();
            Configuration coordJobConf = null;
            try {
                coordJobConf = new XConfiguration(new StringReader(coordJob.getConf()));
            } catch (IOException e) {
                throw new CommandException(ErrorCode.E0907, "failed to read coord job conf to clean up output data");
            }
            try {
                for (CoordinatorActionBean coordAction : coordActions) {
                    String actionXml = coordAction.getActionXml();
                    // Cleanup activity should not run when failed option has been provided
                    if (!noCleanup && !failed) {
                        Element eAction = XmlUtils.parseXml(actionXml);
                        cleanupOutputEvents(eAction, coordJobConf, uriHandlerContextMap);
                    }
                    if (refresh) {
                        refreshAction(coordJob, coordAction);
                    }
                    updateAction(coordJob, coordAction);
                    if (SLAService.isEnabled()) {
                        SLAOperations.updateRegistrationEvent(coordAction.getId());
                    }
                    queue(new CoordActionNotificationXCommand(coordAction), 100);
                    queue(new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 100);
                    if (coordAction.getPushMissingDependencies() != null) {
                        queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true), 100);
                    }
                }
            } finally {
                Iterator<Entry<String, Context>> itr = uriHandlerContextMap.entrySet().iterator();
                while (itr.hasNext()) {
                    Entry<String, Context> entry = itr.next();
                    entry.getValue().destroy();
                    itr.remove();
                }
            }
        } else {
            isError = true;
            throw new CommandException(ErrorCode.E1018, "part or all actions are not eligible to rerun!");
        }
        coordInfo = new CoordinatorActionInfo(coordActions);
        ret = coordInfo;
    } catch (XException xex) {
        isError = true;
        throw new CommandException(xex);
    } catch (JDOMException jex) {
        isError = true;
        throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
    } catch (Exception ex) {
        isError = true;
        throw new CommandException(ErrorCode.E1018, ex.getMessage(), ex);
    } finally {
        if (isError) {
            transitToPrevious();
        }
    }
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) IOException(java.io.IOException) XException(org.apache.oozie.XException) XConfiguration(org.apache.oozie.util.XConfiguration) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) Entry(java.util.Map.Entry) XException(org.apache.oozie.XException) StringReader(java.io.StringReader)

Example 4 with CoordinatorActionInfo

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

the class CoordActionsIgnoreXCommand method ignoreChildren.

@Override
public void ignoreChildren() throws CommandException {
    for (CoordinatorActionBean action : coordActions) {
        action.setStatus(Status.IGNORED);
        action.setLastModifiedTime(new Date());
        action.setPending(0);
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action));
        LOG.info("Ignore coord action = [{0}], new status = [{1}]", action.getId(), action.getStatus());
    }
    ret = new CoordinatorActionInfo(coordActions);
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 5 with CoordinatorActionInfo

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

the class TestCoordActionsIgnoreXCommand method testCoordActionsIgnore.

public void testCoordActionsIgnore() throws Exception {
    createDBRecords();
    // positive test of single action - oozie job -ingore job1 -action 1
    CoordinatorActionInfo retInfo = new CoordActionsIgnoreXCommand(coordJobs.get(0).getId(), "action", "1").call();
    CoordinatorActionBean actionBean1 = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordActions.get(0).getId());
    assertEquals(CoordinatorAction.Status.IGNORED, actionBean1.getStatus());
    assertEquals(1, retInfo.getCoordActions().size());
    assertEquals(actionBean1.getId(), retInfo.getCoordActions().get(0).getId());
    // positive test of action range - oozie job -ignore job1 -action 2-3
    retInfo = new CoordActionsIgnoreXCommand(coordJobs.get(0).getId(), "action", "2-3").call();
    CoordinatorActionBean actionBean2 = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordActions.get(1).getId());
    CoordinatorActionBean actionBean3 = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordActions.get(2).getId());
    assertEquals(CoordinatorAction.Status.IGNORED, actionBean2.getStatus());
    assertEquals(CoordinatorAction.Status.IGNORED, actionBean3.getStatus());
    assertEquals(2, retInfo.getCoordActions().size());
    String retId1 = retInfo.getCoordActions().get(0).getId();
    String retId2 = retInfo.getCoordActions().get(1).getId();
    assertTrue(actionBean2.getId().equals(retId1) || actionBean2.getId().equals(retId2));
    assertTrue(actionBean3.getId().equals(retId1) || actionBean3.getId().equals(retId2));
    // negative test when ignoring a coord action in RUNNING (@5 is running)
    try {
        new CoordActionsIgnoreXCommand(coordJobs.get(0).getId(), "action", "4-5").call();
    } catch (CommandException ex) {
        assertEquals(ex.getErrorCode(), ErrorCode.E1024);
        assertTrue(ex.getMessage().indexOf("part or all actions are not eligible to ignore, check state of action number(s) [5]") > -1);
    }
    // negative test when ignore command on coordinator job in PREP
    try {
        new CoordActionsIgnoreXCommand(coordJobs.get(1).getId(), "action", "1").call();
    } catch (CommandException ex) {
        assertEquals(ex.getErrorCode(), ErrorCode.E1024);
        assertTrue(ex.getMessage().indexOf("No actions are materialized to ignore") > -1);
    }
}
Also used : CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CommandException(org.apache.oozie.command.CommandException)

Aggregations

CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 CoordinatorActionInfo (org.apache.oozie.CoordinatorActionInfo)5 CommandException (org.apache.oozie.command.CommandException)3 Date (java.util.Date)2 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Configuration (org.apache.hadoop.conf.Configuration)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)1 XException (org.apache.oozie.XException)1 PreconditionException (org.apache.oozie.command.PreconditionException)1 KillXCommand (org.apache.oozie.command.wf.KillXCommand)1 Context (org.apache.oozie.dependency.URIHandler.Context)1 URIHandlerException (org.apache.oozie.dependency.URIHandlerException)1 CoordActionQuery (org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)1