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    import org.apache.oozie.util.ParamChecker;
019    
020    /**
021     * This is the base commands for all the jobs related commands . This will drive the statuses for all the jobs and all
022     * the jobs will follow the same state machine.
023     *
024     * @param <T>
025     */
026    public abstract class TransitionXCommand<T> extends XCommand<T> {
027    
028        protected Job job;
029    
030        public TransitionXCommand(String name, String type, int priority) {
031            super(name, type, priority);
032        }
033    
034        public TransitionXCommand(String name, String type, int priority, boolean dryrun) {
035            super(name, type, priority, dryrun);
036        }
037    
038        /**
039         * Transit to the next status based on the result of the Job.
040         *
041         * @throws CommandException
042         */
043        public abstract void transitToNext() throws CommandException;
044    
045        /**
046         * Update the parent job.
047         *
048         * @throws CommandException
049         */
050        public abstract void updateJob() throws CommandException;
051    
052        /**
053         * This will be used to notify the parent about the status of that perticular job.
054         *
055         * @throws CommandException
056         */
057        public abstract void notifyParent() throws CommandException;
058    
059        /* (non-Javadoc)
060         * @see org.apache.oozie.command.XCommand#execute()
061         */
062        @Override
063        protected T execute() throws CommandException {
064            transitToNext();
065            updateJob();
066            notifyParent();
067            return null;
068        }
069    
070        /**
071         * Get the Job for the command.
072         *
073         * @return the job
074         */
075        public Job getJob() {
076            return job;
077        }
078    
079        /**
080         * Set the Job for the command.
081         *
082         * @param job the job
083         */
084        public void setJob(Job job) {
085            this.job = ParamChecker.notNull(job, "job");
086        }
087    
088    }