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