Exemplo n.º 1
0
        public TaskStatusProto ToProto()
        {
            // This is locked because the Task continuation thread which sets the
            // result is potentially different from the HeartBeat thread.
            lock (_heartBeatManager)
            {
                Check();
                TaskStatusProto taskStatusProto = new TaskStatusProto()
                {
                    context_id = ContextId,
                    task_id    = TaskId,
                    state      = GetProtoState()
                };
                if (_result.IsPresent())
                {
                    taskStatusProto.result = ByteUtilities.CopyBytesFrom(_result.Value);
                }
                else if (_lastException.IsPresent())
                {
                    byte[] error;
                    try
                    {
                        error = ByteUtilities.SerializeToBinaryFormat(_lastException.Value);
                    }
                    catch (SerializationException se)
                    {
                        error = ByteUtilities.SerializeToBinaryFormat(
                            NonSerializableTaskException.UnableToSerialize(_lastException.Value, se));
                    }

                    var avroFailedTask = new AvroFailedTask
                    {
                        identifier = _taskId,
                        cause      = error,
                        data       = ByteUtilities.StringToByteArrays(_lastException.Value.ToString()),
                        message    = _lastException.Value.Message
                    };

                    taskStatusProto.result = AvroJsonSerializer <AvroFailedTask> .ToBytes(avroFailedTask);
                }
                else if (_state == TaskState.Running)
                {
                    foreach (TaskMessage message in GetMessages())
                    {
                        TaskStatusProto.TaskMessageProto taskMessageProto = new TaskStatusProto.TaskMessageProto()
                        {
                            source_id = message.MessageSourceId,
                            message   = ByteUtilities.CopyBytesFrom(message.Message),
                        };
                        taskStatusProto.task_message.Add(taskMessageProto);
                    }
                }
                return(taskStatusProto);
            }
        }
Exemplo n.º 2
0
        internal static TaskClientCodeException CreateWithNonSerializableInnerException(
            TaskClientCodeException e, SerializationException serializationException)
        {
            var nonSerializableTaskException = NonSerializableTaskException.UnableToSerialize(e.InnerException, serializationException);

            return(new TaskClientCodeException(
                       e.TaskId,
                       e.ContextId,
                       string.Format("Unable to serialize Task control message. TaskClientCodeException message: {0}", e.Message),
                       nonSerializableTaskException));
        }
Exemplo n.º 3
0
 private static Exception GetCause(byte[] serializedCause, string originalTaskExceptionToString)
 {
     // TODO[JIRA REEF-1422]: Distinguish between Java Task Exception and missing Exception.
     if (ByteUtilities.IsNullOrEmpty(serializedCause))
     {
         return(new TaskExceptionMissingException(
                    "Task failed without an Exception, presumably caused by an Exception failure. Please inspect the FailedTask message."));
     }
     try
     {
         return((Exception)ByteUtilities.DeserializeFromBinaryFormat(serializedCause));
     }
     catch (SerializationException se)
     {
         return(NonSerializableTaskException.UnableToDeserialize(originalTaskExceptionToString, se));
     }
 }