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 java.util.Date; 021 022 import org.apache.oozie.CoordinatorActionBean; 023 import org.apache.oozie.ErrorCode; 024 import org.apache.oozie.client.CoordinatorAction; 025 import org.apache.oozie.command.CommandException; 026 import org.apache.oozie.command.PreconditionException; 027 import org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor; 028 import org.apache.oozie.executor.jpa.JPAExecutorException; 029 import org.apache.oozie.service.JPAService; 030 import org.apache.oozie.service.Services; 031 import org.apache.oozie.util.LogUtils; 032 import org.apache.oozie.util.ParamChecker; 033 034 /** 035 * This class updates the Time out in the action bean 036 */ 037 public class CoordActionTimeOutXCommand extends CoordinatorXCommand<Void> { 038 private CoordinatorActionBean actionBean; 039 private JPAService jpaService = null; 040 041 public CoordActionTimeOutXCommand(CoordinatorActionBean actionBean) { 042 super("coord_action_timeout", "coord_action_timeout", 1); 043 ParamChecker.notNull(actionBean, "ActionBean"); 044 this.actionBean = actionBean; 045 } 046 047 /* (non-Javadoc) 048 * @see org.apache.oozie.command.XCommand#execute() 049 */ 050 @Override 051 protected Void execute() throws CommandException { 052 if (actionBean.getStatus() == CoordinatorAction.Status.WAITING) { 053 actionBean.setStatus(CoordinatorAction.Status.TIMEDOUT); 054 queue(new CoordActionNotificationXCommand(actionBean), 100); 055 actionBean.setLastModifiedTime(new Date()); 056 try { 057 jpaService.execute(new org.apache.oozie.executor.jpa.CoordActionUpdateJPAExecutor(actionBean)); 058 } 059 catch (JPAExecutorException e) { 060 throw new CommandException(e); 061 } 062 } 063 return null; 064 } 065 066 /* (non-Javadoc) 067 * @see org.apache.oozie.command.XCommand#getEntityKey() 068 */ 069 @Override 070 protected String getEntityKey() { 071 return actionBean.getJobId(); 072 } 073 074 /* (non-Javadoc) 075 * @see org.apache.oozie.command.XCommand#isLockRequired() 076 */ 077 @Override 078 protected boolean isLockRequired() { 079 return true; 080 } 081 082 /* (non-Javadoc) 083 * @see org.apache.oozie.command.XCommand#loadState() 084 */ 085 @Override 086 protected void loadState() throws CommandException { 087 jpaService = Services.get().get(JPAService.class); 088 if (jpaService == null) { 089 throw new CommandException(ErrorCode.E0610); 090 } 091 092 try { 093 actionBean = jpaService.execute(new CoordActionGetJPAExecutor(actionBean.getId())); 094 } 095 catch (JPAExecutorException e) { 096 throw new CommandException(e); 097 } 098 LogUtils.setLogInfo(actionBean, logInfo); 099 } 100 101 /* (non-Javadoc) 102 * @see org.apache.oozie.command.XCommand#verifyPrecondition() 103 */ 104 @Override 105 protected void verifyPrecondition() throws CommandException, PreconditionException { 106 if (actionBean.getStatus() != CoordinatorAction.Status.WAITING) { 107 throw new PreconditionException(ErrorCode.E1100); 108 } 109 } 110 }