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;
024import org.apache.reef.runtime.common.driver.resourcemanager.ResourceEventImpl;
025import org.apache.reef.runtime.common.driver.resourcemanager.ResourceRecoverEvent;
026
027/**
028 * An object that encapsulates the information needed to construct an
029 * {@link org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager} for a recovered evaluator
030 * on restart.
031 */
032@Private
033@DriverSide
034@Unstable
035public final class EvaluatorRestartInfo {
036
037  private final ResourceRecoverEvent resourceRecoverEvent;
038
039  private EvaluatorRestartState evaluatorRestartState;
040
041  /**
042   * Creates an {@link EvaluatorRestartInfo} object that represents the information of an evaluator that is expected
043   * to recover.
044   */
045  public static EvaluatorRestartInfo createExpectedEvaluatorInfo(final ResourceRecoverEvent resourceRecoverEvent) {
046    return new EvaluatorRestartInfo(resourceRecoverEvent, EvaluatorRestartState.EXPECTED);
047  }
048
049  private EvaluatorRestartInfo(
050      final ResourceRecoverEvent resourceRecoverEvent, final EvaluatorRestartState evaluatorRestartState) {
051
052    this.resourceRecoverEvent = resourceRecoverEvent;
053    this.evaluatorRestartState = evaluatorRestartState;
054  }
055
056  /**
057   * Creates an {@link EvaluatorRestartInfo} object that represents the information of an evaluator that
058   * has failed on driver restart.
059   */
060  public static EvaluatorRestartInfo createFailedEvaluatorInfo(final String evaluatorId) {
061
062    final ResourceRecoverEvent resourceRecoverEvent =
063        ResourceEventImpl.newRecoveryBuilder().setIdentifier(evaluatorId).build();
064
065    return new EvaluatorRestartInfo(resourceRecoverEvent, EvaluatorRestartState.FAILED);
066  }
067
068  /**
069   * @return the {@link ResourceRecoverEvent} that contains the information (e.g. resource MB, node ID, Evaluator ID...)
070   * needed to reconstruct the {@link org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager} of the
071   * recovered evaluator on restart.
072   */
073  public ResourceRecoverEvent getResourceRecoverEvent() {
074    return this.resourceRecoverEvent;
075  }
076
077  /**
078   * @return the current process of the restart.
079   */
080  public EvaluatorRestartState getEvaluatorRestartState() {
081    return this.evaluatorRestartState;
082  }
083
084  /**
085   * sets the current process of the restart.
086   */
087  public boolean setEvaluatorRestartState(final EvaluatorRestartState to) {
088
089    if (this.evaluatorRestartState.isLegalTransition(to)) {
090      this.evaluatorRestartState = to;
091      return true;
092    }
093
094    return false;
095  }
096}