001    /**
002     * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
003     * Licensed under the Apache License, Version 2.0 (the "License");
004     * you may not use this file except in compliance with the License.
005     * You may obtain a copy of the License at
006     *
007     *   http://www.apache.org/licenses/LICENSE-2.0
008     *
009     *  Unless required by applicable law or agreed to in writing, software
010     *  distributed under the License is distributed on an "AS IS" BASIS,
011     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012     *  See the License for the specific language governing permissions and
013     *  limitations under the License. See accompanying LICENSE file.
014     */
015    package org.apache.oozie.command;
016    
017    import org.apache.oozie.client.Job;
018    
019    public abstract class ResumeTransitionXCommand extends TransitionXCommand<Void> {
020    
021        /**
022         * Resume all children of the job
023         *
024         * @throws CommandException
025         */
026        public abstract void resumeChildren() throws CommandException;
027    
028        public ResumeTransitionXCommand(String name, String type, int priority) {
029            super(name, type, priority);
030        }
031    
032        public ResumeTransitionXCommand(String name, String type, int priority, boolean dryrun) {
033            super(name, type, priority, dryrun);
034        }
035    
036        /**
037         * Transit job to PREP from PREPSUSPENDED or to RUNNING from SUSPENDED.
038         *
039         * @see org.apache.oozie.command.TransitionXCommand#transitToNext()
040         */
041        @Override
042        public void transitToNext() {
043            if (job == null) {
044                job = this.getJob();
045            }
046            if (job.getStatus() == Job.Status.PREPSUSPENDED) {
047                job.setStatus(Job.Status.PREP);
048            }
049            else if (job.getStatus() == Job.Status.SUSPENDED) {
050                job.setStatus(Job.Status.RUNNING);
051            }
052            job.setPending();
053        }
054    
055        /* (non-Javadoc)
056         * @see org.apache.oozie.command.XCommand#execute()
057         */
058        @Override
059        protected Void execute() throws CommandException {
060            transitToNext();
061            try {
062                resumeChildren();
063                updateJob();
064            } finally {
065                notifyParent();
066            }
067            return null;
068        }
069    }