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 java.util.Date;
018
019 import org.apache.oozie.CoordinatorActionBean;
020 import org.apache.oozie.CoordinatorJobBean;
021 import org.apache.oozie.client.CoordinatorAction;
022 import org.apache.oozie.client.CoordinatorJob;
023 import org.apache.oozie.command.CommandException;
024 import org.apache.oozie.store.CoordinatorStore;
025 import org.apache.oozie.store.StoreException;
026 import org.apache.oozie.util.XLog;
027
028 public class CoordActionTimeOut extends CoordinatorCommand<Void> {
029 private CoordinatorActionBean actionBean;
030 private final XLog log = XLog.getLog(getClass());
031
032 public CoordActionTimeOut(CoordinatorActionBean actionBean) {
033 super("coord_action_timeout", "coord_action_timeout", 1, XLog.STD);
034 this.actionBean = actionBean;
035 }
036
037 @Override
038 protected Void call(CoordinatorStore store) throws StoreException, CommandException {
039 // actionBean = store.getCoordinatorAction(actionBean.getId(), false);
040 actionBean = store.getEntityManager().find(CoordinatorActionBean.class, actionBean.getId());
041 if (actionBean.getStatus() == CoordinatorAction.Status.WAITING) {
042 actionBean.setStatus(CoordinatorAction.Status.TIMEDOUT);
043 queueCallable(new CoordActionNotification(actionBean), 100);
044 store.updateCoordinatorAction(actionBean);
045 }
046 return null;
047 }
048
049 @Override
050 protected Void execute(CoordinatorStore store) throws StoreException, CommandException {
051 String jobId = actionBean.getJobId();
052 setLogInfo(actionBean);
053 log.info("STARTED CoordinatorActionTimeOut for Action Id " + actionBean.getId() + " of job Id :"
054 + actionBean.getJobId() + ". Timeout value is " + actionBean.getTimeOut() + " mins");
055 try {
056 if (lock(jobId)) {
057 call(store);
058 }
059 else {
060 queueCallable(new CoordActionTimeOut(actionBean), LOCK_FAILURE_REQUEUE_INTERVAL);
061 log.warn("CoordinatorActionTimeOut lock was not acquired - " + " failed " + jobId
062 + ". Requeing the same.");
063 }
064 }
065 catch (InterruptedException e) {
066 queueCallable(new CoordActionTimeOut(actionBean), LOCK_FAILURE_REQUEUE_INTERVAL);
067 log.warn("CoordinatorActionTimeOut lock acquiring failed " + " with exception " + e.getMessage()
068 + " for job id " + jobId + ". Requeing the same.");
069 }
070 finally {
071 log.info("ENDED CoordinatorActionTimeOut for Action Id " + actionBean.getId());
072 }
073 return null;
074 }
075 }