001    /**
002     * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
003     * Licensed under the Apache License, Version 2.0 (the "License");
004     * you may not use this file except in compliance with the License.
005     * You may obtain a copy of the License at
006     *
007     *   http://www.apache.org/licenses/LICENSE-2.0
008     *
009     *  Unless required by applicable law or agreed to in writing, software
010     *  distributed under the License is distributed on an "AS IS" BASIS,
011     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012     *  See the License for the specific language governing permissions and
013     *  limitations under the License. See accompanying LICENSE file.
014     */
015    package org.apache.oozie.command.bundle;
016    
017    import java.util.List;
018    
019    import org.apache.oozie.BundleJobBean;
020    import org.apache.oozie.CoordinatorJobBean;
021    import org.apache.oozie.ErrorCode;
022    import org.apache.oozie.XException;
023    import org.apache.oozie.command.CommandException;
024    import org.apache.oozie.command.PreconditionException;
025    import org.apache.oozie.command.XCommand;
026    import org.apache.oozie.executor.jpa.BundleJobGetCoordinatorsJPAExecutor;
027    import org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor;
028    import org.apache.oozie.service.JPAService;
029    import org.apache.oozie.service.Services;
030    import org.apache.oozie.util.ParamChecker;
031    
032    /**
033     * Command for Getting the Bundle job bean it also gets coordinators information in the Bundle job.
034     */
035    public class BundleJobXCommand extends XCommand<BundleJobBean> {
036        private final String id;
037    
038        /**
039         * Command for Getting the Bundle job bean it also gets coordinators information in the Bundle job.
040         *
041         * @param id bundle jobId
042         */
043        public BundleJobXCommand(String id) {
044            super("job.info", "job.info", 1);
045            this.id = ParamChecker.notEmpty(id, "id");
046        }
047    
048        /* (non-Javadoc)
049         * @see org.apache.oozie.command.XCommand#isLockRequired()
050         */
051        @Override
052        protected boolean isLockRequired() {
053            return false;
054        }
055    
056        /* (non-Javadoc)
057         * @see org.apache.oozie.command.XCommand#getEntityKey()
058         */
059        @Override
060        protected String getEntityKey() {
061            return this.id;
062        }
063    
064        /* (non-Javadoc)
065         * @see org.apache.oozie.command.XCommand#loadState()
066         */
067        @Override
068        protected void loadState() throws CommandException {
069        }
070    
071        /* (non-Javadoc)
072         * @see org.apache.oozie.command.XCommand#verifyPrecondition()
073         */
074        @Override
075        protected void verifyPrecondition() throws CommandException, PreconditionException {
076        }
077    
078        /* (non-Javadoc)
079         * @see org.apache.oozie.command.XCommand#execute()
080         */
081        @Override
082        protected BundleJobBean execute() throws CommandException {
083            try {
084                JPAService jpaService = Services.get().get(JPAService.class);
085                BundleJobBean bundleJob = null;
086                if (jpaService != null) {
087                    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(id));
088    
089                    List<CoordinatorJobBean> coordinators = jpaService.execute(new BundleJobGetCoordinatorsJPAExecutor(id));
090                    bundleJob.setCoordJobs(coordinators);
091                }
092                else {
093                    LOG.error(ErrorCode.E0610);
094                }
095                return bundleJob;
096            }
097            catch (XException ex) {
098                throw new CommandException(ex);
099            }
100        }
101    
102    }