美文网首页
Oozie-TransitionXCommand

Oozie-TransitionXCommand

作者: PunyGod | 来源:发表于2016-06-30 10:34 被阅读66次

    从之前的组件可以看到,任务是有状态机的概念的,准备,开始,运行中,失败结束 等等,所以对任务进行操作的命令同时需要处理状态机的变化,oozie处理任务的命令都需要继承TransitionXCommand这个抽象类,而TransitionXCommand的父类是XCommand

    diagram1.png
    /* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute() */
    @Overrideprotected 
    T execute() throws CommandException {
        transitToNext();
        updateJob();
        notifyParent();
        return null;
    }
    

    对任务进行操作的 execute() 中 包含设置任务对象的状态信息(transitToNext),准备更新任务操作语句(updateJob)【异步更新或者同步更新】,通知上层组件结构(notifyParent)


    现在对它的子类做详细描述:

    PauseTransitionXCommand

    /* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#execute()
     */
    @Override
    protected Void execute() throws CommandException {
        try {
            transitToNext();
            updateJob();
            pauseChildren();
        }
        finally {
            notifyParent();
        }
        return null;
    }
    

    暂停命令执行,将正确的状态机状态置为暂停,暂停的状态码也有好几种(PAUSED、PAUSEDWITHERROR、PREPPAUSED),是因为当从暂停状态恢复的时候,任务可以恢复到它置为暂停之前的状态,更新本身任务状态,暂停所有的子任务,同时将自身状态反馈给上层组件。子类有CoordPauseXCommand CoordPauseXCommand

    UnpauseTransitionXCommand

    /* (non-Javadoc) 
    * @see org.apache.oozie.command.TransitionXCommand#execute() 
    */
    @Override
    protected Void execute() throws CommandException {
        try {
            transitToNext();
            updateJob(); 
            unpauseChildren();
        }
        finally {
            notifyParent();
        }
        return null;
    }
    

    从暂停状态恢复命令,将任务的暂停状态还原成暂停之前的状态,更新任务本身,将子任务的也从暂停状态恢复,通知上层组件自己已经从暂停状态恢复;
    子类有CoordUnpauseXCommand BundleUnpauseXCommand

    SuspendTransitionXCommand

    /* (non-Javadoc) 
    * @see org.apache.oozie.command.XCommand#execute() 
    */
    @Override
    protected Void execute() throws CommandException {
        transitToNext();
        try {
            suspendChildren();
            updateJob();
            performWrites();
        } finally {
            notifyParent();
        }
        return null;
    }
    

    挂起任务命令,将不同的状态置为暂停状态,暂停状态码分多个(PREPSUSPENDED,SUSPENDED,SUSPENDEDWITHERROR,SUSPENDED,PREPSUSPENDED),当任务从挂起状态恢复时候,可以恢复到挂起之前的状态;
    异步挂起子任务,更新任务本身状态,同时通知上层组件;子类有CoordSuspendXCommand BundleJobSuspendXCommand

    ResumeTransitionXCommand

    /* (non-Javadoc) 
    * @see org.apache.oozie.command.XCommand#execute()
     */
    @Override
    protected Void execute() throws CommandException {
        transitToNext();
        try {
            resumeChildren();
            updateJob();
            performWrites();
        } finally {
            notifyParent();
        }
        return null;
    }
    

    恢复挂起命令,将任务从挂起状态恢复,同时异步通知子任务,更新任务本身状态,通知上层组件自己已经恢复。子类有 CoordResumeXCommand BundleJobResumeXCommand

    SubmitTransitionXCommand

    /* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
    @Override
    protected String execute() throws CommandException {
        try {
           transitToNext();
           String jobId = submit();
           return jobId;
        }    finally {
            notifyParent();
        }
    }
    

    任务提交命令,任务状态置为PREP,并将任务的信息从xml中解析后存到数据库中,如果任务需要立即吊起,则发送开始命令;通知上层组件;子类有 BundleSubmitXCommand CoordSubmitXCommand CoordUpdateXCommand

    StartTransitionXCommand

    /* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#execute() 
    */
    @Override
    protected Void execute() throws CommandException {
        transitToNext();
        updateJob();
        StartChildren();
        performWrites();
        notifyParent();
        return null;
    }
    

    任务启动命令,将任务的状态置为 RUNNING ,启动子任务,更新数据库任务信息,其子类 仅仅有 BundleStartXCommand

    RerunTransitionXCommand

    /* (non-Javadoc) 
    * @see org.apache.oozie.command.TransitionXCommand#execute() 
    */
    @Override
    protected T execute() throws CommandException { 
       getLog().info("STARTED " + getClass().getSimpleName() + " for jobId=" + jobId);
        try {
            transitToNext();
            rerunChildren();
            updateJob();
            performWrites();
        }    finally {
            notifyParent();
        }
        getLog().info("ENDED " + getClass().getSimpleName() + " for jobId=" + jobId);
        return ret;
    }
    

    任务重跑命令,将任务状态置为 RUNNING 或者 RUNNINGWITHERROR
    异步发送子任务重跑命令,更新数据库任务信息,通知上层组件;
    子类有 CoordRerunXCommand BundleRerunXCommand

    MaterializeTransitionXCommand

    /* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#execute() 
    */
    @Override
    protected Void execute() throws CommandException {
        try {
            materialize();
            updateJob();
            performWrites();
        } finally {
            notifyParent();
        }
        return null;
    }
    

    任务实例化命令,子类为 CoordMaterializeTransitionXCommand

    KillTransitionXCommand

    /* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#execute()
     */
    @Override
    protected T execute() throws CommandException {
        try {
            transitToNext();
            killChildren(); 
            updateJob(); 
            performWrites();
        }
        finally {
            notifyParent();
        }
        return ret;
    }
    

    任务杀死命令,将任务的状态置为 KILLED , 杀死子任务,更新数据库任务信息,通知上层组件自己杀死状态。 子类有 CoordKillXCommand CoordActionsKillXCommand BundleKillXCommand

    IgnoreTransitionXCommand

    @Override
    protected T execute() throws CommandException {
        try {
            transitToNext(); 
            ignoreChildren();
            updateJob();
            performWrites();
        }
        finally {
            notifyParent();
        }
        return ret;
    }
    

    任务忽略命令,子类 CoordActionsIgnoreXCommand

    相关文章

      网友评论

          本文标题:Oozie-TransitionXCommand

          本文链接:https://www.haomeiwen.com/subject/tqjxjttx.html