Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.resourcemanager.slotmanager;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.clusterframework.types.SlotID;
import org.apache.flink.runtime.clusterframework.types.TaskManagerSlot;
import org.apache.flink.runtime.concurrent.ScheduledExecutor;
import org.apache.flink.runtime.resourcemanager.SlotRequest;
import org.apache.flink.util.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
* This slot manager is used by yarn session mode. It will ignore the resource for a slot,
* but will make the total resources for all tasks in the slots of a task manager
* not exceed the total resource of the task manager.
*/
public class DynamicAssigningSlotManager extends SlotManager {
private static final Logger LOG = LoggerFactory.getLogger(DynamicAssigningSlotManager.class);
/**
* All allocated slots's resource profile.
* If the task manager has no allocated slots(all slots are free), it does not exist in this map.
* ResourceID : The id of each task manager
* Tuple2 : The allocated slots and resources of the task manager
* f0 : The allocated slots map, keyed by slotId and value is resource profile of the slot
* f1 : The remaining resource of the task manager identified by resourceId
*/
private final Map, ResourceProfile>> allocatedSlotsResource;
/**
* The resource can be used by task in a task manager.
*/
private ResourceProfile totalResourceOfTaskExecutor;
private SlotPlacementPolicy slotPlacementPolicy;
private Comparator slotComparator;
public DynamicAssigningSlotManager(
ScheduledExecutor scheduledExecutor,
Time taskManagerRequestTimeout,
Time slotRequestTimeout,
Time taskManagerTimeout,
Time taskManagerCheckerInitialDelay) {
this(scheduledExecutor,
taskManagerRequestTimeout,
slotRequestTimeout,
taskManagerTimeout,
taskManagerCheckerInitialDelay,
SlotPlacementPolicy.RANDOM);
}
public DynamicAssigningSlotManager(
ScheduledExecutor scheduledExecutor,
Time taskManagerRequestTimeout,
Time slotRequestTimeout,
Time taskManagerTimeout,
Time taskManagerCheckerInitialDelay,
SlotPlacementPolicy slotPlacementPolicy) {
super(scheduledExecutor, taskManagerRequestTimeout, slotRequestTimeout, taskManagerTimeout, taskManagerCheckerInitialDelay);
this.allocatedSlotsResource = new HashMap<>();
this.slotPlacementPolicy = slotPlacementPolicy;
switch (slotPlacementPolicy) {
case SLOT:
slotComparator = new Comparator() {
@Override
public int compare(TaskManagerSlot o1, TaskManagerSlot o2) {
ResourceID rid1 = o1.getSlotId().getResourceID();
ResourceID rid2 = o2.getSlotId().getResourceID();
Tuple2