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.executiongraph;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.clusterframework.types.SlotProfile;
import org.apache.flink.runtime.instance.SlotSharingGroupId;
import org.apache.flink.runtime.jobgraph.ScheduleMode;
import org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit;
import org.apache.flink.runtime.jobmaster.LogicalSlot;
import org.apache.flink.runtime.jobmaster.SlotRequestId;
import org.apache.flink.runtime.jobmaster.slotpool.SlotProvider;
import org.apache.flink.util.Preconditions;
import javax.annotation.Nullable;
import java.util.concurrent.CompletableFuture;
/**
* Strategy to switch between different {@link SlotProvider} allocation strategies.
*/
abstract class SlotProviderStrategy {
protected final SlotProvider slotProvider;
protected final boolean allowQueuedScheduling;
SlotProviderStrategy(SlotProvider slotProvider, boolean allowQueuedScheduling) {
this.slotProvider = Preconditions.checkNotNull(slotProvider);
this.allowQueuedScheduling = allowQueuedScheduling;
}
boolean isQueuedSchedulingAllowed() {
return allowQueuedScheduling;
}
/**
* Allocating slot with specific requirement.
*
* @param slotRequestId identifying the slot request
* @param scheduledUnit The task to allocate the slot for
* @param slotProfile profile of the requested slot
* @return The future of the allocation
*/
abstract CompletableFuture allocateSlot(
SlotRequestId slotRequestId,
ScheduledUnit scheduledUnit,
SlotProfile slotProfile);
/**
* Cancels the slot request with the given {@link SlotRequestId} and {@link SlotSharingGroupId}.
*
* @param slotRequestId identifying the slot request to cancel
* @param slotSharingGroupId identifying the slot request to cancel
* @param cause of the cancellation
*/
void cancelSlotRequest(
SlotRequestId slotRequestId,
@Nullable SlotSharingGroupId slotSharingGroupId,
Throwable cause) {
slotProvider.cancelSlotRequest(slotRequestId, slotSharingGroupId, cause);
}
static SlotProviderStrategy from(
ScheduleMode scheduleMode,
SlotProvider slotProvider,
Time allocationTimeout,
boolean allowQueuedScheduling) {
switch (scheduleMode) {
case LAZY_FROM_SOURCES_WITH_BATCH_SLOT_REQUEST:
return new BatchSlotProviderStrategy(slotProvider, allowQueuedScheduling);
case LAZY_FROM_SOURCES:
case EAGER:
return new NormalSlotProviderStrategy(slotProvider, allocationTimeout, allowQueuedScheduling);
default:
throw new IllegalArgumentException(String.format("Unknown scheduling mode: %s", scheduleMode));
}
}
SlotProvider asSlotProvider() {
return slotProvider;
}
static class BatchSlotProviderStrategy extends SlotProviderStrategy {
BatchSlotProviderStrategy(SlotProvider slotProvider, boolean allowQueuedScheduling) {
super(slotProvider, allowQueuedScheduling);
}
@Override
public CompletableFuture allocateSlot(SlotRequestId slotRequestId, ScheduledUnit scheduledUnit, SlotProfile slotProfile) {
return slotProvider.allocateBatchSlot(slotRequestId, scheduledUnit, slotProfile, allowQueuedScheduling);
}
}
static class NormalSlotProviderStrategy extends SlotProviderStrategy {
private final Time allocationTimeout;
NormalSlotProviderStrategy(SlotProvider slotProvider, Time allocationTimeout, boolean allowQueuedScheduling) {
super(slotProvider, allowQueuedScheduling);
this.allocationTimeout = Preconditions.checkNotNull(allocationTimeout);
}
@Override
public CompletableFuture allocateSlot(SlotRequestId slotRequestId, ScheduledUnit scheduledUnit, SlotProfile slotProfile) {
return slotProvider.allocateSlot(slotRequestId, scheduledUnit, slotProfile, allowQueuedScheduling, allocationTimeout);
}
}
}