Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/5403#discussion_r170252510
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/SlotProfile.java
 ---
    @@ -0,0 +1,275 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.runtime.clusterframework.types;
    +
    +import org.apache.flink.annotation.VisibleForTesting;
    +import org.apache.flink.runtime.jobmanager.scheduler.Locality;
    +import org.apache.flink.runtime.jobmaster.SlotContext;
    +import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
    +import org.apache.flink.util.Preconditions;
    +
    +import javax.annotation.Nonnull;
    +import javax.annotation.Nullable;
    +
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.HashSet;
    +import java.util.Iterator;
    +import java.util.function.BiFunction;
    +import java.util.function.Function;
    +import java.util.function.Predicate;
    +import java.util.stream.Stream;
    +
    +/**
    + * A slot profile describes the profile of a slot into which a task wants 
to be scheduled. The profile contains
    + * attributes such as resource or locality constraints, some of which may 
be hard or soft. A matcher can be generated
    + * to filter out candidate slots by matching their {@link SlotContext} 
against the slot profile and, potentially,
    + * further requirements.
    + */
    +public class SlotProfile {
    +
    +   /** Singleton object for a slot profile without any requirements. */
    +   private static final SlotProfile NO_REQUIREMENTS = 
noLocality(ResourceProfile.UNKNOWN);
    +
    +   /** This specifies the desired resource profile for the slot. */
    +   @Nonnull
    +   private final ResourceProfile resourceProfile;
    +
    +   /** This specifies the preferred locations for the slot. */
    +   @Nonnull
    +   private final Collection<TaskManagerLocation> preferredLocations;
    +
    +   /** This contains desired allocation ids of the slot. */
    +   @Nonnull
    +   private final Collection<AllocationID> priorAllocations;
    +
    +   public SlotProfile(
    +           @Nonnull ResourceProfile resourceProfile,
    +           @Nonnull Collection<TaskManagerLocation> preferredLocations,
    +           @Nonnull Collection<AllocationID> priorAllocations) {
    +           this.resourceProfile = resourceProfile;
    +           this.preferredLocations = preferredLocations;
    +           this.priorAllocations = priorAllocations;
    +   }
    +
    +   /**
    +    * Returns the desired resource profile for the slot.
    +    */
    +   @Nonnull
    +   public ResourceProfile getResourceProfile() {
    +           return resourceProfile;
    +   }
    +
    +   /**
    +    * Returns the preferred locations for the slot.
    +    */
    +   @Nonnull
    +   public Collection<TaskManagerLocation> getPreferredLocations() {
    +           return preferredLocations;
    +   }
    +
    +   /**
    +    * Returns the desired allocation ids for the slot.
    +    */
    +   @Nonnull
    +   public Collection<AllocationID> getPriorAllocations() {
    +           return priorAllocations;
    +   }
    +
    +   public ProfileToSlotContextMatcher matcher() {
    +           if (priorAllocations.isEmpty()) {
    +                   return new 
LocalityAwareRequirementsToSlotMatcher(preferredLocations);
    +           } else {
    +                   return new 
PreviousAllocationProfileToSlotContextMatcher(priorAllocations);
    +           }
    +   }
    +
    +   /**
    +    * Classes that implement this interface provide a method to match 
objects to somehow represent slot candidates
    +    * against the {@link SlotProfile} that produced the matcher object. A 
matching candidate is transformed into a
    +    * desired result. If the matcher does not find a matching candidate, 
it returns null.
    +    */
    +   public interface ProfileToSlotContextMatcher {
    +
    +           /**
    --- End diff --
    
    JavaDocs not complete


---

Reply via email to