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    /**
020     * Transition command for start the job. The derived class has to override these following functions:
021     * <p/>
022     * loadState() : load the job's and/or actions' state
023     * updateJob() : update job status and attributes
024     * StartChildren() : submit or queue commands to start children
025     * notifyParent() : update the status to upstream if any
026     */
027    public abstract class StartTransitionXCommand extends TransitionXCommand<Void> {
028    
029        /**
030         * The constructor for abstract class {@link StartTransitionXCommand}
031         *
032         * @param name the command name
033         * @param type the command type
034         * @param priority the command priority
035         */
036        public StartTransitionXCommand(String name, String type, int priority) {
037            super(name, type, priority);
038        }
039    
040        /**
041         * The constructor for abstract class {@link StartTransitionXCommand}
042         *
043         * @param name the command name
044         * @param type the command type
045         * @param priority the command priority
046         * @param dryrun true if dryrun is enable
047         */
048        public StartTransitionXCommand(String name, String type, int priority, boolean dryrun) {
049            super(name, type, priority, dryrun);
050        }
051    
052        /**
053         * Start actions associated with the job
054         *
055         * @throws CommandException thrown if failed to start actions
056         */
057        public abstract void StartChildren() throws CommandException;
058    
059        /* (non-Javadoc)
060         * @see org.apache.oozie.command.TransitionXCommand#transitToNext()
061         */
062        @Override
063        public final void transitToNext() {
064            if (job == null) {
065                job = this.getJob();
066            }
067            job.setStatus(Job.Status.RUNNING);
068            job.setPending();
069        }
070    
071        /* (non-Javadoc)
072         * @see org.apache.oozie.command.TransitionXCommand#execute()
073         */
074        @Override
075        protected Void execute() throws CommandException {
076            transitToNext();
077            updateJob();
078            StartChildren();
079            notifyParent();
080            return null;
081        }
082    }