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    import java.util.Map;
019    
020    import org.apache.oozie.BundleJobInfo;
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.BundleJobInfoGetJPAExecutor;
027    import org.apache.oozie.service.JPAService;
028    import org.apache.oozie.service.Services;
029    
030    /**
031     * The command to get a job info for a list of bundle jobs by given filters.
032     */
033    public class BundleJobsXCommand extends XCommand<BundleJobInfo> {
034        private Map<String, List<String>> filter;
035        private int start = 1;
036        private int len = 50;
037    
038        /**
039         * The constructor for BundleJobsXCommand
040         *
041         * @param filter the filter string
042         * @param start start location for paging
043         * @param len total length to get
044         */
045        public BundleJobsXCommand(Map<String, List<String>> filter, int start, int length) {
046            super("bundle.job.info", "bundle.job.info", 1);
047            this.filter = filter;
048            this.start = start;
049            this.len = length;
050        }
051    
052        /* (non-Javadoc)
053         * @see org.apache.oozie.command.XCommand#isLockRequired()
054         */
055        @Override
056        protected boolean isLockRequired() {
057            return false;
058        }
059    
060        /* (non-Javadoc)
061         * @see org.apache.oozie.command.XCommand#getEntityKey()
062         */
063        @Override
064        protected String getEntityKey() {
065            return null;
066        }
067    
068        /* (non-Javadoc)
069         * @see org.apache.oozie.command.XCommand#loadState()
070         */
071        @Override
072        protected void loadState() throws CommandException {
073        }
074    
075        /* (non-Javadoc)
076         * @see org.apache.oozie.command.XCommand#verifyPrecondition()
077         */
078        @Override
079        protected void verifyPrecondition() throws CommandException, PreconditionException {
080        }
081    
082        /* (non-Javadoc)
083         * @see org.apache.oozie.command.XCommand#execute()
084         */
085        @Override
086        protected BundleJobInfo execute() throws CommandException {
087            try {
088                JPAService jpaService = Services.get().get(JPAService.class);
089                BundleJobInfo bundleInfo = null;
090                if (jpaService != null) {
091                    bundleInfo = jpaService.execute(new BundleJobInfoGetJPAExecutor(filter, start, len));
092                }
093                else {
094                    LOG.error(ErrorCode.E0610);
095                }
096                return bundleInfo;
097            }
098            catch (XException ex) {
099                throw new CommandException(ex);
100            }
101        }
102    
103    }