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