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