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