|
| 1 | +/* |
| 2 | + * Copyright 2022 Netflix, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.mantisrx.server.master.resourcecluster; |
| 18 | + |
| 19 | +import io.mantisrx.common.Ack; |
| 20 | +import io.mantisrx.runtime.MachineDefinition; |
| 21 | +import io.mantisrx.server.core.domain.WorkerId; |
| 22 | +import io.mantisrx.server.worker.TaskExecutorGateway; |
| 23 | +import java.time.Instant; |
| 24 | +import java.util.List; |
| 25 | +import java.util.concurrent.CompletableFuture; |
| 26 | +import javax.annotation.Nullable; |
| 27 | +import lombok.Value; |
| 28 | + |
| 29 | +/** |
| 30 | + * Abstraction to deal with all interactions with the resource cluster such as |
| 31 | + * 1). listing the set of task executors registered |
| 32 | + * 2). listing the set of task executors available |
| 33 | + * 3). listing the set of task executors busy |
| 34 | + * 4). get the current state of a task executor |
| 35 | + * 5). get the current state of the system |
| 36 | + * 6). assign a task executor for a given worker |
| 37 | + */ |
| 38 | +public interface ResourceCluster extends ResourceClusterGateway { |
| 39 | + /** |
| 40 | + * API that gets invoked when the resource cluster migrates from one machine to another and needs to be initialized. |
| 41 | + * |
| 42 | + * @param taskExecutorID taskExecutorID that was originally running the worker |
| 43 | + * @param workerId workerID of the task that being run on the task executor |
| 44 | + * @return Ack when the initialization is done |
| 45 | + */ |
| 46 | + CompletableFuture<Ack> initializeTaskExecutor(TaskExecutorID taskExecutorID, WorkerId workerId); |
| 47 | + |
| 48 | + CompletableFuture<List<TaskExecutorID>> getRegisteredTaskExecutors(); |
| 49 | + |
| 50 | + CompletableFuture<List<TaskExecutorID>> getAvailableTaskExecutors(); |
| 51 | + |
| 52 | + CompletableFuture<List<TaskExecutorID>> getBusyTaskExecutors(); |
| 53 | + |
| 54 | + CompletableFuture<List<TaskExecutorID>> getUnregisteredTaskExecutors(); |
| 55 | + |
| 56 | + CompletableFuture<ResourceOverview> resourceOverview(); |
| 57 | + |
| 58 | + /** |
| 59 | + * Can throw {@link NoResourceAvailableException} wrapped within the CompletableFuture in case there |
| 60 | + * are no task executors. |
| 61 | + * |
| 62 | + * @param machineDefinition machine definition that's requested for the worker |
| 63 | + * @param workerId worker id of the task that's going to run on the node. |
| 64 | + * @return task executor assigned for the particular task. |
| 65 | + */ |
| 66 | + CompletableFuture<TaskExecutorID> getTaskExecutorFor(MachineDefinition machineDefinition, WorkerId workerId); |
| 67 | + |
| 68 | + CompletableFuture<TaskExecutorGateway> getTaskExecutorGateway(TaskExecutorID taskExecutorID); |
| 69 | + |
| 70 | + CompletableFuture<TaskExecutorRegistration> getTaskExecutorInfo(String hostName); |
| 71 | + |
| 72 | + CompletableFuture<TaskExecutorRegistration> getTaskExecutorInfo(TaskExecutorID taskExecutorID); |
| 73 | + |
| 74 | + CompletableFuture<TaskExecutorStatus> getTaskExecutorState(TaskExecutorID taskExecutorID); |
| 75 | + |
| 76 | + class NoResourceAvailableException extends Exception { |
| 77 | + |
| 78 | + public NoResourceAvailableException(String message) { |
| 79 | + super(message); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + @Value |
| 84 | + class ResourceOverview { |
| 85 | + long numRegisteredTaskExecutors; |
| 86 | + long numAvailableTaskExecutors; |
| 87 | + long numOccupiedTaskExecutors; |
| 88 | + long numAssignedTaskExecutors; |
| 89 | + } |
| 90 | + |
| 91 | + @Value |
| 92 | + class TaskExecutorStatus { |
| 93 | + TaskExecutorRegistration registration; |
| 94 | + boolean isRegistered; |
| 95 | + boolean isRunningTask; |
| 96 | + boolean isAssignedTask; |
| 97 | + @Nullable |
| 98 | + WorkerId workerId; |
| 99 | + Instant lastHeartbeat; |
| 100 | + } |
| 101 | +} |
0 commit comments