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.action; 016 017 import org.apache.oozie.util.ParamChecker; 018 import org.apache.oozie.util.XLog; 019 020 /** 021 * ActionExecutor exception. <p/> The exception provides information regarding the transient/no-transient/fatal nature 022 * of the exception. 023 */ 024 public class ActionExecutorException extends Exception { 025 026 /** 027 * Enum that defines the type of error an {@link ActionExecutor} has produced. 028 */ 029 public static enum ErrorType { 030 031 /** 032 * The action will be automatically retried by Oozie. 033 */ 034 TRANSIENT, 035 036 /** 037 * The job in set in SUSPEND mode and it will wait for an admin to resume the job. 038 */ 039 040 NON_TRANSIENT, 041 042 /** 043 * The action completes with an error transition. 044 */ 045 ERROR, 046 047 /** 048 * The action fails. No transition is taken. 049 */ 050 FAILED 051 } 052 053 private ErrorType errorType; 054 private String errorCode; 055 056 /** 057 * Create an action executor exception. 058 * 059 * @param errorType the error type. 060 * @param errorCode the error code. 061 * @param message the error message. 062 */ 063 public ActionExecutorException(ErrorType errorType, String errorCode, String message) { 064 super(message); 065 this.errorType = ParamChecker.notNull(errorType, "errorType"); 066 this.errorCode = ParamChecker.notEmpty(errorCode, "errorCode"); 067 } 068 069 /** 070 * Create an action executor exception. 071 * 072 * <p/> If the last parameter is an Exception it is used as the exception cause. 073 * 074 * @param errorType the error type. 075 * @param errorCode the error code. 076 * @param messageTemplate the error message. 077 * @param params parameters used to create the exception message together with the messageTemplate. If the last 078 * parameter is an Exception it is used as the exception cause. 079 */ 080 public ActionExecutorException(ErrorType errorType, String errorCode, String messageTemplate, Object... params) { 081 super(errorCode + ": " + XLog.format(messageTemplate, params), XLog.getCause(params)); 082 this.errorType = ParamChecker.notNull(errorType, "errorType"); 083 this.errorCode = ParamChecker.notEmpty(errorCode, "errorCode"); 084 } 085 086 /** 087 * Return the error type of the exception. 088 * 089 * @return the error type of the exception. 090 */ 091 public ErrorType getErrorType() { 092 return errorType; 093 } 094 095 /** 096 * Return the error code of the exception. 097 * 098 * @return the error code of the exception. 099 */ 100 public String getErrorCode() { 101 return errorCode; 102 } 103 }