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     * This is transition Base commands for all the jobs.
021     */
022    public abstract class KillTransitionXCommand extends TransitionXCommand<Void> {
023    
024        public KillTransitionXCommand(String name, String type, int priority) {
025            super(name, type, priority);
026        }
027    
028        public abstract void killChildren() throws CommandException;
029    
030        /* (non-Javadoc)
031         * @see org.apache.oozie.command.TransitionXCommand#transitToNext()
032         */
033        @Override
034        public final void transitToNext() {
035            if (job == null) {
036                job = this.getJob();
037            }
038            job.setStatus(Job.Status.KILLED);
039            job.setPending();
040        }
041    
042        /* (non-Javadoc)
043         * @see org.apache.oozie.command.TransitionXCommand#execute()
044         */
045        @Override
046        protected Void execute() throws CommandException {
047            try {
048                transitToNext();
049                killChildren();
050                updateJob();
051            }
052            finally {
053                notifyParent();
054            }
055            return null;
056        }
057    }