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.coord;
016    
017    import java.util.List;
018    import java.util.Map;
019    
020    import org.apache.oozie.CoordinatorJobInfo;
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.executor.jpa.CoordJobInfoGetJPAExecutor;
026    import org.apache.oozie.service.JPAService;
027    import org.apache.oozie.service.Services;
028    
029    /**
030     * The command to get a job info for a list of coordinator jobs by given filters.
031     */
032    public class CoordJobsXCommand extends CoordinatorXCommand<CoordinatorJobInfo> {
033        private Map<String, List<String>> filter;
034        private int start = 1;
035        private int len = 50;
036    
037        public CoordJobsXCommand(Map<String, List<String>> filter, int start, int length) {
038            super("coord.job.info", "coord.job.info", 1);
039            this.filter = filter;
040            this.start = start;
041            this.len = length;
042        }
043    
044        /* (non-Javadoc)
045         * @see org.apache.oozie.command.XCommand#isLockRequired()
046         */
047        @Override
048        protected boolean isLockRequired() {
049            return false;
050        }
051    
052        /* (non-Javadoc)
053         * @see org.apache.oozie.command.XCommand#getEntityKey()
054         */
055        @Override
056        protected String getEntityKey() {
057            return null;
058        }
059    
060        /* (non-Javadoc)
061         * @see org.apache.oozie.command.XCommand#loadState()
062         */
063        @Override
064        protected void loadState() throws CommandException {
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.XCommand#execute()
076         */
077        @Override
078        protected CoordinatorJobInfo execute() throws CommandException {
079            try {
080                JPAService jpaService = Services.get().get(JPAService.class);
081                CoordinatorJobInfo coordInfo = null;
082                if (jpaService != null) {
083                    coordInfo = jpaService.execute(new CoordJobInfoGetJPAExecutor(filter, start, len));
084                }
085                else {
086                    LOG.error(ErrorCode.E0610);
087                }
088                return coordInfo;
089            }
090            catch (XException ex) {
091                throw new CommandException(ex);
092            }
093        }
094    
095    }