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