This project has retired. For details please refer to its Attic page.
Source code
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 */
019
020package org.apache.reef.runtime.common.driver.evaluator.pojos;
021
022import org.apache.reef.annotations.audience.DriverSide;
023import org.apache.reef.annotations.audience.Private;
024import org.apache.reef.proto.ReefServiceProtos;
025import org.apache.reef.proto.ReefServiceProtos.TaskStatusProto.TaskMessageProto;
026
027import java.util.ArrayList;
028import java.util.List;
029
030/**
031 * DriverSide representation of TaskStatusProto.
032 */
033@DriverSide
034@Private
035public final class TaskStatusPOJO {
036
037  private final String taskId;
038  private final String contextId;
039  private final State state;
040  private final byte[] result;
041  private final List<TaskMessagePOJO> taskMessages = new ArrayList<>();
042
043  public TaskStatusPOJO(final ReefServiceProtos.TaskStatusProto proto, final long sequenceNumber){
044
045    taskId = proto.getTaskId();
046    contextId = proto.getContextId();
047    state = proto.hasState()? getStateFromProto(proto.getState()) : null;
048    result = proto.hasResult() ? proto.getResult().toByteArray() : null;
049
050    for (final TaskMessageProto taskMessageProto : proto.getTaskMessageList()) {
051      taskMessages.add(new TaskMessagePOJO(taskMessageProto, sequenceNumber));
052    }
053
054  }
055
056  /**
057   * @return a list of messages sent by a task
058   */
059  public List<TaskMessagePOJO> getTaskMessageList(){
060    return taskMessages;
061  }
062
063  /**
064   * @return true, if a completed task returned a non-null value in the 'return' statement
065   */
066  public boolean hasResult(){
067    return null != result;
068  }
069
070  /**
071   * @return serialized result that a completed task returned to the Driver
072   */
073  public byte[] getResult(){
074    return result;
075  }
076
077  /**
078   * @return the id of a task
079   */
080  public String getTaskId(){
081    return taskId;
082  }
083
084  /**
085   * @return the id of a context that this task runs within
086   */
087  public String getContextId(){
088    return contextId;
089  }
090
091  /**
092   * @return current {@link org.apache.reef.runtime.common.driver.evaluator.pojos.State} of a task
093   */
094  public State getState(){
095    return state;
096  }
097
098  private State getStateFromProto(final org.apache.reef.proto.ReefServiceProtos.State protoState) {
099
100    switch (protoState) {
101    case INIT:
102      return State.INIT;
103    case RUNNING:
104      return State.RUNNING;
105    case DONE:
106      return State.DONE;
107    case SUSPEND:
108      return State.SUSPEND;
109    case FAILED:
110      return State.FAILED;
111    case KILLED:
112      return State.KILLED;
113    default:
114      throw new IllegalStateException("Unknown state " + protoState + " in EvaluatorStatusProto");
115    }
116
117  }
118}