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