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