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 */
019package org.apache.reef.driver.restart;
020
021import org.apache.reef.annotations.Unstable;
022import org.apache.reef.annotations.audience.DriverSide;
023import org.apache.reef.annotations.audience.Private;
024
025/**
026 * The state that the evaluator is in in the driver restart process.
027 */
028@Private
029@DriverSide
030@Unstable
031public enum EvaluatorRestartState {
032  /**
033   * The evaluator is not a restarted instance. Not expecting.
034   */
035  NOT_EXPECTED,
036
037  /**
038   * Have not yet heard back from an evaluator, but we are expecting it to report back.
039   */
040  EXPECTED,
041
042  /**
043   * Received the evaluator heartbeat, but have not yet processed it.
044   */
045  REPORTED,
046
047  /**
048   * The evaluator has had its recovery heartbeat processed.
049   */
050  REREGISTERED,
051
052  /**
053   * The evaluator has had its context/running task processed.
054   */
055  PROCESSED,
056
057  /**
058   * The evaluator has only contacted the driver after the expiration period.
059   */
060  EXPIRED,
061
062  /**
063   * The evaluator has failed on driver restart.
064   */
065  FAILED;
066
067  /**
068   * @return true if the transition of {@link EvaluatorRestartState} is legal.
069   */
070  public static boolean isLegalTransition(final EvaluatorRestartState from, final EvaluatorRestartState to) {
071    switch(from) {
072    case EXPECTED:
073      switch(to) {
074      case EXPIRED:
075      case REPORTED:
076        return true;
077      default:
078        return false;
079      }
080    case REPORTED:
081      switch(to) {
082      case REREGISTERED:
083        return true;
084      default:
085        return false;
086      }
087    case REREGISTERED:
088      switch(to) {
089      case PROCESSED:
090        return true;
091      default:
092        return false;
093      }
094    default:
095      return false;
096    }
097  }
098
099  /**
100   * @return true if the evaluator has heartbeated back to the driver.
101   */
102  public boolean hasReported() {
103    switch(this) {
104    case REPORTED:
105    case REREGISTERED:
106    case PROCESSED:
107      return true;
108    default:
109      return false;
110    }
111  }
112
113  /**
114   * @return true if the evaluator has failed on driver restart or is not expected to report back to the driver.
115   */
116  public boolean isFailedOrNotExpected() {
117    switch(this) {
118    case FAILED:
119    case NOT_EXPECTED:
120      return true;
121    default:
122      return false;
123    }
124  }
125
126  /**
127   * @return true if the evaluator has failed on driver restart or has been expired.
128   */
129  public boolean isFailedOrExpired() {
130    switch(this) {
131    case FAILED:
132    case EXPIRED:
133      return true;
134    default:
135      return false;
136    }
137  }
138}