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