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.ErrorCode; 022import org.apache.oozie.client.Job; 023 024/** 025 * Transition command for pause the job. The derived class has to override these following functions: 026 * <p/> 027 * updateJob() : update job status and attributes 028 * pauseChildren() : submit or queue commands to pause children 029 * notifyParent() : update the status to upstream if any 030 * 031 * @param <T> 032 */ 033public abstract class PauseTransitionXCommand extends TransitionXCommand<Void> { 034 /** 035 * The constructor for abstract class {@link PauseTransitionXCommand} 036 * 037 * @param name the command name 038 * @param type the command type 039 * @param priority the command priority 040 */ 041 public PauseTransitionXCommand(String name, String type, int priority) { 042 super(name, type, priority); 043 } 044 045 /** 046 * pause actions associated with the job 047 * 048 * @throws CommandException thrown if failed to pause actions 049 */ 050 public abstract void pauseChildren() throws CommandException; 051 052 /* (non-Javadoc) 053 * @see org.apache.oozie.command.TransitionXCommand#transitToNext() 054 */ 055 @Override 056 public final void transitToNext() throws CommandException { 057 if (job == null) { 058 job = this.getJob(); 059 } 060 061 if (job.getStatus() == Job.Status.RUNNING) { 062 job.setStatus(Job.Status.PAUSED); 063 } 064 else if (job.getStatus() == Job.Status.RUNNINGWITHERROR) { 065 job.setStatus(Job.Status.PAUSEDWITHERROR); 066 } 067 else if (job.getStatus() == Job.Status.PREP) { 068 job.setStatus(Job.Status.PREPPAUSED); 069 } 070 else { 071 throw new CommandException(ErrorCode.E1315, job.getId()); 072 } 073 074 //TODO: to be revisited; 075 //job.setPending(); 076 } 077 078 /* (non-Javadoc) 079 * @see org.apache.oozie.command.TransitionXCommand#execute() 080 */ 081 @Override 082 protected Void execute() throws CommandException { 083 try { 084 transitToNext(); 085 updateJob(); 086 pauseChildren(); 087 } 088 finally { 089 notifyParent(); 090 } 091 return null; 092 } 093}