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
019package org.apache.oozie.command.coord;
020
021import java.util.List;
022import java.util.Map;
023
024import org.apache.oozie.CoordinatorJobInfo;
025import org.apache.oozie.ErrorCode;
026import org.apache.oozie.XException;
027import org.apache.oozie.command.CommandException;
028import org.apache.oozie.command.PreconditionException;
029import org.apache.oozie.executor.jpa.CoordJobInfoGetJPAExecutor;
030import org.apache.oozie.service.JPAService;
031import org.apache.oozie.service.Services;
032
033/**
034 * The command to get a job info for a list of coordinator jobs by given filters.
035 */
036public class CoordJobsXCommand extends CoordinatorXCommand<CoordinatorJobInfo> {
037    private Map<String, List<String>> filter;
038    private int start = 1;
039    private int len = 50;
040
041    public CoordJobsXCommand(Map<String, List<String>> filter, int start, int length) {
042        super("coord.job.info", "coord.job.info", 1);
043        this.filter = filter;
044        this.start = start;
045        this.len = length;
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    public String getEntityKey() {
061        return null;
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 CoordinatorJobInfo execute() throws CommandException {
083        try {
084            JPAService jpaService = Services.get().get(JPAService.class);
085            CoordinatorJobInfo coordInfo = null;
086            if (jpaService != null) {
087                coordInfo = jpaService.execute(new CoordJobInfoGetJPAExecutor(filter, start, len));
088            }
089            else {
090                LOG.error(ErrorCode.E0610);
091            }
092            return coordInfo;
093        }
094        catch (XException ex) {
095            throw new CommandException(ex);
096        }
097    }
098
099}