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