io.mantisrx.master.resourcecluster.ResourceClusterAkkaImpl Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2022 Netflix, Inc.
*
* Licensed 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 io.mantisrx.master.resourcecluster;
import akka.actor.ActorRef;
import akka.pattern.Patterns;
import io.mantisrx.common.Ack;
import io.mantisrx.config.dynamic.LongDynamicProperty;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.AddNewJobArtifactsToCacheRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.ArtifactList;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetActiveJobsRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetAssignedTaskExecutorRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetAvailableTaskExecutorsRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetBusyTaskExecutorsRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetDisabledTaskExecutorsRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetJobArtifactsToCacheRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetRegisteredTaskExecutorsRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetTaskExecutorStatusRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetTaskExecutorWorkerMappingRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.GetUnregisteredTaskExecutorsRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.InitializeTaskExecutorRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.MarkExecutorTaskCancelledRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.RemoveJobArtifactsToCacheRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.ResourceOverviewRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.TaskExecutorBatchAssignmentRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.TaskExecutorGatewayRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.TaskExecutorInfoRequest;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.TaskExecutorsAllocation;
import io.mantisrx.master.resourcecluster.ResourceClusterActor.TaskExecutorsList;
import io.mantisrx.master.resourcecluster.ResourceClusterScalerActor.QueueClusterRuleRefreshRequest;
import io.mantisrx.master.resourcecluster.proto.SetResourceClusterScalerStatusRequest;
import io.mantisrx.server.core.domain.ArtifactID;
import io.mantisrx.server.core.domain.WorkerId;
import io.mantisrx.server.master.resourcecluster.ClusterID;
import io.mantisrx.server.master.resourcecluster.ContainerSkuID;
import io.mantisrx.server.master.resourcecluster.PagedActiveJobOverview;
import io.mantisrx.server.master.resourcecluster.ResourceCluster;
import io.mantisrx.server.master.resourcecluster.TaskExecutorAllocationRequest;
import io.mantisrx.server.master.resourcecluster.TaskExecutorID;
import io.mantisrx.server.master.resourcecluster.TaskExecutorRegistration;
import io.mantisrx.server.worker.TaskExecutorGateway;
import io.mantisrx.shaded.com.google.common.collect.ImmutableMap;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
class ResourceClusterAkkaImpl extends ResourceClusterGatewayAkkaImpl implements ResourceCluster {
private final ClusterID clusterID;
public ResourceClusterAkkaImpl(
ActorRef resourceClusterManagerActor,
Duration askTimeout,
ClusterID clusterID,
LongDynamicProperty rateLimitPerSecondDp) {
super(resourceClusterManagerActor, askTimeout, rateLimitPerSecondDp);
this.clusterID = clusterID;
}
@Override
public String getName() {
return clusterID.getResourceID();
}
@Override
public CompletableFuture initializeTaskExecutor(TaskExecutorID taskExecutorID, WorkerId workerId) {
return Patterns.ask(
resourceClusterManagerActor,
new InitializeTaskExecutorRequest(taskExecutorID, workerId),
askTimeout)
.thenApply(Ack.class::cast)
.toCompletableFuture();
}
@Override
public CompletableFuture> getRegisteredTaskExecutors(Map attributes) {
return Patterns.ask(
resourceClusterManagerActor,
new GetRegisteredTaskExecutorsRequest(clusterID, attributes), askTimeout)
.thenApply(TaskExecutorsList.class::cast)
.toCompletableFuture()
.thenApply(l -> l.getTaskExecutors());
}
@Override
public CompletableFuture> getAvailableTaskExecutors(Map attributes) {
return Patterns.ask(
resourceClusterManagerActor,
new GetAvailableTaskExecutorsRequest(clusterID, attributes), askTimeout)
.thenApply(TaskExecutorsList.class::cast)
.toCompletableFuture()
.thenApply(l -> l.getTaskExecutors());
}
@Override
public CompletableFuture> getBusyTaskExecutors(Map attributes) {
return Patterns.ask(
resourceClusterManagerActor,
new GetBusyTaskExecutorsRequest(clusterID, attributes), askTimeout)
.thenApply(TaskExecutorsList.class::cast)
.toCompletableFuture()
.thenApply(l -> l.getTaskExecutors());
}
@Override
public CompletableFuture> getDisabledTaskExecutors(Map attributes) {
return Patterns.ask(
resourceClusterManagerActor,
new GetDisabledTaskExecutorsRequest(clusterID, attributes), askTimeout)
.thenApply(TaskExecutorsList.class::cast)
.toCompletableFuture()
.thenApply(l -> l.getTaskExecutors());
}
@Override
public CompletableFuture> getUnregisteredTaskExecutors(Map attributes) {
return Patterns.ask(
resourceClusterManagerActor,
new GetUnregisteredTaskExecutorsRequest(clusterID, attributes), askTimeout)
.thenApply(TaskExecutorsList.class::cast)
.toCompletableFuture()
.thenApply(l -> l.getTaskExecutors());
}
@Override
public CompletableFuture resourceOverview() {
return
Patterns
.ask(resourceClusterManagerActor, new ResourceOverviewRequest(clusterID), askTimeout)
.thenApply(ResourceOverview.class::cast)
.toCompletableFuture();
}
@Override
public CompletableFuture addNewJobArtifactsToCache(ClusterID clusterID, List artifacts) {
return Patterns
.ask(
resourceClusterManagerActor,
new AddNewJobArtifactsToCacheRequest(clusterID, artifacts),
askTimeout)
.thenApply(Ack.class::cast)
.toCompletableFuture();
}
@Override
public CompletableFuture markTaskExecutorWorkerCancelled(WorkerId workerId) {
return Patterns
.ask(
resourceClusterManagerActor,
new MarkExecutorTaskCancelledRequest(clusterID, workerId),
askTimeout)
.thenApply(Ack.class::cast)
.toCompletableFuture();
}
@Override
public CompletableFuture removeJobArtifactsToCache(List artifacts) {
return Patterns
.ask(
resourceClusterManagerActor,
new RemoveJobArtifactsToCacheRequest(clusterID, artifacts),
askTimeout)
.thenApply(Ack.class::cast)
.toCompletableFuture();
}
@Override
public CompletableFuture> getJobArtifactsToCache() {
return Patterns
.ask(
resourceClusterManagerActor,
new GetJobArtifactsToCacheRequest(clusterID),
askTimeout)
.thenApply(ArtifactList.class::cast)
.toCompletableFuture()
.thenApply(ArtifactList::getArtifacts);
}
@Override
public CompletableFuture