001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.oozie.command;
020
021import org.apache.oozie.client.Job;
022
023/**
024 * Transition command for start the job. The derived class has to override these following functions:
025 * <p>
026 * loadState() : load the job's and/or actions' state
027 * updateJob() : update job status and attributes
028 * StartChildren() : submit or queue commands to start children
029 * notifyParent() : update the status to upstream if any
030 */
031public abstract class StartTransitionXCommand extends TransitionXCommand<Void> {
032
033    /**
034     * The constructor for abstract class {@link StartTransitionXCommand}
035     *
036     * @param name the command name
037     * @param type the command type
038     * @param priority the command priority
039     */
040    public StartTransitionXCommand(String name, String type, int priority) {
041        super(name, type, priority);
042    }
043
044    /**
045     * The constructor for abstract class {@link StartTransitionXCommand}
046     *
047     * @param name the command name
048     * @param type the command type
049     * @param priority the command priority
050     * @param dryrun true if dryrun is enable
051     */
052    public StartTransitionXCommand(String name, String type, int priority, boolean dryrun) {
053        super(name, type, priority, dryrun);
054    }
055
056    /**
057     * Start actions associated with the job
058     *
059     * @throws CommandException thrown if failed to start actions
060     */
061    public abstract void StartChildren() throws CommandException;
062
063    /* (non-Javadoc)
064     * @see org.apache.oozie.command.TransitionXCommand#transitToNext()
065     */
066    @Override
067    public final void transitToNext() {
068        if (job == null) {
069            job = this.getJob();
070        }
071        job.setStatus(Job.Status.RUNNING);
072        job.setPending();
073    }
074
075    /* (non-Javadoc)
076     * @see org.apache.oozie.command.TransitionXCommand#execute()
077     */
078    @Override
079    protected Void execute() throws CommandException {
080        transitToNext();
081        updateJob();
082        StartChildren();
083        performWrites();
084        notifyParent();
085        return null;
086    }
087}