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 package org.apache.oozie.command.coord; 019 020 import java.util.Collections; 021 import java.util.List; 022 023 import org.apache.oozie.CoordinatorActionBean; 024 import org.apache.oozie.CoordinatorJobBean; 025 import org.apache.oozie.ErrorCode; 026 import org.apache.oozie.XException; 027 import org.apache.oozie.command.CommandException; 028 import org.apache.oozie.command.PreconditionException; 029 import org.apache.oozie.executor.jpa.CoordJobGetActionsSubsetJPAExecutor; 030 import org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor; 031 import org.apache.oozie.service.JPAService; 032 import org.apache.oozie.service.Services; 033 import org.apache.oozie.util.ParamChecker; 034 035 /** 036 * Command for loading a coordinator job information 037 */ 038 public class CoordJobXCommand extends CoordinatorXCommand<CoordinatorJobBean> { 039 private final String id; 040 private final boolean getActionInfo; 041 private int start = 1; 042 private int len = Integer.MAX_VALUE; 043 private List<String> filterList; 044 045 /** 046 * Constructor for loading a coordinator job information 047 * 048 * @param id coord jobId 049 */ 050 public CoordJobXCommand(String id) { 051 this(id, Collections.<String>emptyList(), 1, Integer.MAX_VALUE); 052 } 053 054 /** 055 * Constructor for loading a coordinator job information 056 * 057 * @param id coord jobId 058 * @param start starting index in the list of actions belonging to the job 059 * @param length number of actions to be returned 060 */ 061 public CoordJobXCommand(String id, List<String> filterList, int start, int length) { 062 super("job.info", "job.info", 1); 063 this.id = ParamChecker.notEmpty(id, "id"); 064 this.getActionInfo = true; 065 this.filterList = filterList; 066 this.start = start; 067 this.len = length; 068 } 069 070 /** 071 * Constructor for loading a coordinator job information 072 * 073 * @param id coord jobId 074 * @param getActionInfo false to ignore loading actions for the job 075 */ 076 public CoordJobXCommand(String id, boolean getActionInfo) { 077 super("job.info", "job.info", 1); 078 this.id = ParamChecker.notEmpty(id, "id"); 079 this.getActionInfo = getActionInfo; 080 } 081 082 /* (non-Javadoc) 083 * @see org.apache.oozie.command.XCommand#isLockRequired() 084 */ 085 @Override 086 protected boolean isLockRequired() { 087 return false; 088 } 089 090 /* (non-Javadoc) 091 * @see org.apache.oozie.command.XCommand#getEntityKey() 092 */ 093 @Override 094 public String getEntityKey() { 095 return this.id; 096 } 097 098 /* (non-Javadoc) 099 * @see org.apache.oozie.command.XCommand#loadState() 100 */ 101 @Override 102 protected void loadState() throws CommandException { 103 } 104 105 /* (non-Javadoc) 106 * @see org.apache.oozie.command.XCommand#verifyPrecondition() 107 */ 108 @Override 109 protected void verifyPrecondition() throws CommandException, PreconditionException { 110 } 111 112 /* (non-Javadoc) 113 * @see org.apache.oozie.command.XCommand#execute() 114 */ 115 @Override 116 protected CoordinatorJobBean execute() throws CommandException { 117 try { 118 JPAService jpaService = Services.get().get(JPAService.class); 119 CoordinatorJobBean coordJob = null; 120 if (jpaService != null) { 121 coordJob = jpaService.execute(new CoordJobGetJPAExecutor(id)); 122 if (getActionInfo) { 123 List<CoordinatorActionBean> coordActions = jpaService 124 .execute(new CoordJobGetActionsSubsetJPAExecutor(id, filterList, start, len)); 125 coordJob.setActions(coordActions); 126 } 127 } 128 else { 129 LOG.error(ErrorCode.E0610); 130 } 131 return coordJob; 132 } 133 catch (XException ex) { 134 throw new CommandException(ex); 135 } 136 } 137 138 }