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, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.driver.task; 020 021import org.apache.reef.annotations.Provided; 022import org.apache.reef.annotations.audience.DriverSide; 023import org.apache.reef.annotations.audience.Public; 024import org.apache.reef.common.AbstractFailure; 025import org.apache.reef.driver.context.ActiveContext; 026import org.apache.reef.util.Optional; 027 028/** 029 * An error message that REEF Driver gets from a failed Task. 030 */ 031@DriverSide 032@Provided 033@Public 034public final class FailedTask extends AbstractFailure { 035 036 /** 037 * (Optional) Context of the failed Task. 038 */ 039 private final Optional<ActiveContext> context; 040 041 /** 042 * @param id Identifier of the entity that produced the error. Cannot be null. 043 * @param message One-line error message. Cannot be null. 044 * @param description Long error description. Can be null. 045 * @param cause Java Exception that caused the error. Can be null. 046 * @param data byte array that contains serialized version of the error. Can be null. 047 * @param context the Context the Task failed on. 048 */ 049 public FailedTask(final String id, 050 final String message, 051 final Optional<String> description, 052 final Optional<Throwable> cause, 053 final Optional<byte[]> data, 054 final Optional<ActiveContext> context) { 055 super(id, message, description, cause, data); 056 this.context = context; 057 } 058 059 060 /** 061 * Access the context the task ran (and crashed) on, if it could be recovered. 062 * <p> 063 * An ActiveContext is given when the task fails but the context remains alive. 064 * On context failure, the context also fails and is surfaced via the FailedContext event. 065 * <p> 066 * Note that receiving an ActiveContext here is no guarantee that the context (and evaluator) 067 * are in a consistent state. Application developers need to investigate the reason available 068 * via getCause() to make that call. 069 * 070 * @return the context the Task ran on. 071 */ 072 public Optional<ActiveContext> getActiveContext() { 073 return this.context; 074 } 075}