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.bundle;
019    
020    import org.apache.oozie.BundleJobBean;
021    import org.apache.oozie.client.Job;
022    import org.apache.oozie.command.CommandException;
023    import org.apache.oozie.command.PauseTransitionXCommand;
024    import org.apache.oozie.command.PreconditionException;
025    import org.apache.oozie.executor.jpa.BundleJobUpdateJPAExecutor;
026    import org.apache.oozie.executor.jpa.JPAExecutorException;
027    import org.apache.oozie.service.JPAService;
028    import org.apache.oozie.service.Services;
029    import org.apache.oozie.util.LogUtils;
030    
031    public class BundlePauseXCommand extends PauseTransitionXCommand {
032        private BundleJobBean bundleJob;
033        private JPAService jpaService = Services.get().get(JPAService.class);
034    
035        public BundlePauseXCommand(BundleJobBean bundleJob) {
036            super("bundle_pause", "bundle_pause", 1);
037            this.bundleJob = bundleJob;
038        }
039    
040        /* (non-Javadoc)
041         * @see org.apache.oozie.command.XCommand#getEntityKey()
042         */
043        @Override
044        public String getEntityKey() {
045            return bundleJob.getId();
046        }
047    
048        /* (non-Javadoc)
049         * @see org.apache.oozie.command.XCommand#isLockRequired()
050         */
051        @Override
052        protected boolean isLockRequired() {
053            return true;
054        }
055    
056        /* (non-Javadoc)
057         * @see org.apache.oozie.command.XCommand#loadState()
058         */
059        @Override
060        public void loadState() throws CommandException {
061            LogUtils.setLogInfo(bundleJob, logInfo);
062        }
063    
064        /* (non-Javadoc)
065         * @see org.apache.oozie.command.XCommand#verifyPrecondition()
066         */
067        @Override
068        protected void verifyPrecondition() throws CommandException, PreconditionException {
069        }
070    
071        /* (non-Javadoc)
072         * @see org.apache.oozie.command.TransitionXCommand#notifyParent()
073         */
074        @Override
075        public void notifyParent() {
076        }
077    
078        /* (non-Javadoc)
079         * @see org.apache.oozie.command.TransitionXCommand#getJob()
080         */
081        @Override
082        public Job getJob() {
083            return bundleJob;
084        }
085    
086        /* (non-Javadoc)
087         * @see org.apache.oozie.command.TransitionXCommand#updateJob()
088         */
089        @Override
090        public void updateJob() throws CommandException {
091            try {
092                jpaService.execute(new BundleJobUpdateJPAExecutor(bundleJob));
093            }
094            catch (JPAExecutorException e) {
095                throw new CommandException(e);
096            }
097        }
098    
099        @Override
100        public void pauseChildren() throws CommandException {
101            // TODO - need revisit when revisiting coord job status redesign;
102    
103        }
104    
105        @Override
106        public void performWrites() throws CommandException {
107        }
108    
109    }