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.annotations.audience.RuntimeAuthor;
025import org.apache.reef.tang.annotations.DefaultImplementation;
026
027import java.util.Set;
028
029/**
030 * Classes implementing this interface are in charge of recording evaluator
031 * changes as they are allocated as well as recovering Evaluators and
032 * discovering which evaluators are lost on the event of a driver restart.
033 */
034@DriverSide
035@Private
036@RuntimeAuthor
037@Unstable
038@DefaultImplementation(DefaultDriverRuntimeRestartMangerImpl.class)
039public interface DriverRuntimeRestartManager {
040  /**
041   * @return positive if the driver has been restarted as reported by the resource manager. 0 otherwise.
042   * Note that this is different from whether the driver is in the process of restarting.
043   * This returns positive both on when the driver is in the restart process or has already finished restarting.
044   * The default implementation always returns 0.
045   */
046  int getResubmissionAttempts();
047
048  /**
049   * Records the evaluators when it is allocated.
050   * @param id The evaluator ID of the allocated evaluator.
051   */
052  void recordAllocatedEvaluator(final String id);
053
054  /**
055   * Records a removed evaluator into the evaluator log.
056   * @param id The evaluator ID of the removed evaluator.
057   */
058  void recordRemovedEvaluator(final String id);
059
060  /**
061   * Gets the sets of alive and failed evaluators based on the runtime implementation.
062   * @return A map which encapsulates the states of previous evaluators.
063   */
064  RestartEvaluators getPreviousEvaluators();
065
066  /**
067   * Informs the necessary components about failed evaluators. The implementation is runtime dependent.
068   * @param failedEvaluatorIds The set of evaluator IDs of evaluators that failed during restart.
069   */
070  void informAboutEvaluatorFailures(final Set<String> failedEvaluatorIds);
071}