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.wf; 016 017 import java.util.List; 018 import java.util.Map; 019 020 import org.apache.oozie.ErrorCode; 021 import org.apache.oozie.WorkflowJobBean; 022 import org.apache.oozie.WorkflowsInfo; 023 import org.apache.oozie.command.CommandException; 024 import org.apache.oozie.command.PreconditionException; 025 import org.apache.oozie.executor.jpa.WorkflowsJobGetJPAExecutor; 026 import org.apache.oozie.service.JPAService; 027 import org.apache.oozie.service.Services; 028 029 public class JobsXCommand extends WorkflowXCommand<WorkflowsInfo> { 030 private final Map<String, List<String>> filter; 031 private final int start; 032 private final int len; 033 private WorkflowsInfo workflows; 034 035 /** 036 * Constructor taking the filter information 037 * 038 * @param filter Can be name, status, user, group and combination of these 039 * @param start starting from this index in the list of workflows matching the filter are returned 040 * @param length number of workflows to be returned from the list of workflows matching the filter and starting from 041 * index "start". 042 */ 043 public JobsXCommand(Map<String, List<String>> filter, int start, int length) { 044 super("job.info", "job.info", 1, true); 045 this.filter = filter; 046 this.start = start; 047 this.len = length; 048 } 049 050 /* (non-Javadoc) 051 * @see org.apache.oozie.command.XCommand#execute() 052 */ 053 @Override 054 protected WorkflowsInfo execute() throws CommandException { 055 try { 056 JPAService jpaService = Services.get().get(JPAService.class); 057 if (jpaService != null) { 058 this.workflows = jpaService.execute(new WorkflowsJobGetJPAExecutor(this.filter, this.start, this.len)); 059 } 060 else { 061 throw new CommandException(ErrorCode.E0610); 062 } 063 for (WorkflowJobBean workflow : this.workflows.getWorkflows()) { 064 workflow.setConsoleUrl(JobCommand.getJobConsoleUrl(workflow.getId())); 065 } 066 return this.workflows; 067 } 068 catch (Exception ex) { 069 throw new CommandException(ErrorCode.E0603, ex); 070 } 071 } 072 073 /* (non-Javadoc) 074 * @see org.apache.oozie.command.XCommand#getEntityKey() 075 */ 076 @Override 077 protected String getEntityKey() { 078 return null; 079 } 080 081 /* (non-Javadoc) 082 * @see org.apache.oozie.command.XCommand#isLockRequired() 083 */ 084 @Override 085 protected boolean isLockRequired() { 086 return false; 087 } 088 089 /* (non-Javadoc) 090 * @see org.apache.oozie.command.XCommand#loadState() 091 */ 092 @Override 093 protected void loadState() throws CommandException { 094 } 095 096 /* (non-Javadoc) 097 * @see org.apache.oozie.command.XCommand#verifyPrecondition() 098 */ 099 @Override 100 protected void verifyPrecondition() throws CommandException, PreconditionException { 101 } 102 }