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