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