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