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.wake.time.event.StartTime;
025
026import java.util.Collections;
027import java.util.HashSet;
028import java.util.Set;
029
030/**
031 * @see DriverRestarted
032 */
033@DriverSide
034@Private
035@Unstable
036public final class DriverRestartedImpl implements DriverRestarted {
037  private final int resubmissionAttempts;
038  private final StartTime startTime;
039  private final Set<String> expectedEvaluatorIds;
040
041  DriverRestartedImpl(final int resubmissionAttempts,
042                      final StartTime startTime,
043                      final RestartEvaluators restartEvaluators) {
044    this.resubmissionAttempts = resubmissionAttempts;
045    this.startTime = startTime;
046    final Set<String> expected = new HashSet<>();
047
048    for (final String evaluatorId : restartEvaluators.getEvaluatorIds()) {
049      if (restartEvaluators.get(evaluatorId).getEvaluatorRestartState() == EvaluatorRestartState.EXPECTED) {
050        expected.add(evaluatorId);
051      }
052    }
053
054    this.expectedEvaluatorIds = Collections.unmodifiableSet(expected);
055  }
056
057  @Override
058  public int getResubmissionAttempts() {
059    return resubmissionAttempts;
060  }
061
062  @Override
063  public StartTime getStartTime() {
064    return startTime;
065  }
066
067  @Override
068  public Set<String> getExpectedEvaluatorIds() {
069    return expectedEvaluatorIds;
070  }
071}