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