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