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