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.bundle; 016 017 import org.apache.oozie.BundleJobBean; 018 import org.apache.oozie.client.Job; 019 import org.apache.oozie.command.CommandException; 020 import org.apache.oozie.command.PauseTransitionXCommand; 021 import org.apache.oozie.command.PreconditionException; 022 import org.apache.oozie.executor.jpa.BundleJobUpdateJPAExecutor; 023 import org.apache.oozie.executor.jpa.JPAExecutorException; 024 import org.apache.oozie.service.JPAService; 025 import org.apache.oozie.service.Services; 026 import org.apache.oozie.util.LogUtils; 027 028 public class BundlePauseXCommand extends PauseTransitionXCommand { 029 private BundleJobBean bundleJob; 030 private JPAService jpaService = Services.get().get(JPAService.class); 031 032 public BundlePauseXCommand(BundleJobBean bundleJob) { 033 super("bundle_pause", "bundle_pause", 1); 034 this.bundleJob = bundleJob; 035 } 036 037 /* (non-Javadoc) 038 * @see org.apache.oozie.command.XCommand#getEntityKey() 039 */ 040 @Override 041 protected String getEntityKey() { 042 return bundleJob.getId(); 043 } 044 045 /* (non-Javadoc) 046 * @see org.apache.oozie.command.XCommand#isLockRequired() 047 */ 048 @Override 049 protected boolean isLockRequired() { 050 return true; 051 } 052 053 /* (non-Javadoc) 054 * @see org.apache.oozie.command.XCommand#loadState() 055 */ 056 @Override 057 public void loadState() throws CommandException { 058 LogUtils.setLogInfo(bundleJob, logInfo); 059 } 060 061 /* (non-Javadoc) 062 * @see org.apache.oozie.command.XCommand#verifyPrecondition() 063 */ 064 @Override 065 protected void verifyPrecondition() throws CommandException, PreconditionException { 066 } 067 068 /* (non-Javadoc) 069 * @see org.apache.oozie.command.TransitionXCommand#notifyParent() 070 */ 071 @Override 072 public void notifyParent() { 073 } 074 075 /* (non-Javadoc) 076 * @see org.apache.oozie.command.TransitionXCommand#getJob() 077 */ 078 @Override 079 public Job getJob() { 080 return bundleJob; 081 } 082 083 /* (non-Javadoc) 084 * @see org.apache.oozie.command.TransitionXCommand#updateJob() 085 */ 086 @Override 087 public void updateJob() throws CommandException { 088 try { 089 jpaService.execute(new BundleJobUpdateJPAExecutor(bundleJob)); 090 } 091 catch (JPAExecutorException e) { 092 throw new CommandException(e); 093 } 094 } 095 096 @Override 097 public void pauseChildren() throws CommandException { 098 // TODO - need revisit when revisiting coord job status redesign; 099 100 } 101 102 }