Search in sources :

Example 1 with ResourceOverview

use of org.apache.flink.runtime.resourcemanager.ResourceOverview in project flink by apache.

the class MiniClusterResource method cancelAllJobs.

private void cancelAllJobs(boolean waitUntilSlotsAreFreed) {
    try {
        final long shutdownTimeout = miniClusterResourceConfiguration.getShutdownTimeout().toMilliseconds();
        final Deadline jobCancellationDeadline = Deadline.fromNow(Duration.ofMillis(shutdownTimeout));
        final List<CompletableFuture<Acknowledge>> jobCancellationFutures = miniCluster.listJobs().get(jobCancellationDeadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS).stream().filter(status -> !status.getJobState().isGloballyTerminalState()).map(status -> miniCluster.cancelJob(status.getJobId())).collect(Collectors.toList());
        FutureUtils.waitForAll(jobCancellationFutures).get(jobCancellationDeadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
        CommonTestUtils.waitUntilCondition(() -> {
            final long unfinishedJobs = miniCluster.listJobs().get(jobCancellationDeadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS).stream().filter(status -> !status.getJobState().isGloballyTerminalState()).count();
            return unfinishedJobs == 0;
        }, jobCancellationDeadline);
        if (waitUntilSlotsAreFreed) {
            CommonTestUtils.waitUntilCondition(() -> {
                final ResourceOverview resourceOverview = miniCluster.getResourceOverview().get();
                return resourceOverview.getNumberRegisteredSlots() == resourceOverview.getNumberFreeSlots();
            }, jobCancellationDeadline);
        }
    } catch (Exception e) {
        log.warn("Exception while shutting down remaining jobs.", e);
    }
}
Also used : MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) Deadline(org.apache.flink.api.common.time.Deadline) LoggerFactory(org.slf4j.LoggerFactory) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) MemorySize(org.apache.flink.configuration.MemorySize) UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) ResourceOverview(org.apache.flink.runtime.resourcemanager.ResourceOverview) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Duration(java.time.Duration) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) RestOptions(org.apache.flink.configuration.RestOptions) URI(java.net.URI) HeartbeatManagerOptions(org.apache.flink.configuration.HeartbeatManagerOptions) Logger(org.slf4j.Logger) Configuration(org.apache.flink.configuration.Configuration) Reference(org.apache.flink.util.Reference) JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RpcSystem(org.apache.flink.runtime.rpc.RpcSystem) ExternalResource(org.junit.rules.ExternalResource) CoreOptions(org.apache.flink.configuration.CoreOptions) PseudoRandomValueSelector.randomize(org.apache.flink.runtime.testutils.PseudoRandomValueSelector.randomize) TemporaryFolder(org.junit.rules.TemporaryFolder) CompletableFuture(java.util.concurrent.CompletableFuture) Deadline(org.apache.flink.api.common.time.Deadline) ResourceOverview(org.apache.flink.runtime.resourcemanager.ResourceOverview)

Example 2 with ResourceOverview

use of org.apache.flink.runtime.resourcemanager.ResourceOverview in project flink by apache.

the class Dispatcher method requestClusterOverview.

@Override
public CompletableFuture<ClusterOverview> requestClusterOverview(Time timeout) {
    CompletableFuture<ResourceOverview> taskManagerOverviewFuture = runResourceManagerCommand(resourceManagerGateway -> resourceManagerGateway.requestResourceOverview(timeout));
    final List<CompletableFuture<Optional<JobStatus>>> optionalJobInformation = queryJobMastersForInformation(jobManagerRunner -> jobManagerRunner.requestJobStatus(timeout));
    CompletableFuture<Collection<Optional<JobStatus>>> allOptionalJobsFuture = FutureUtils.combineAll(optionalJobInformation);
    CompletableFuture<Collection<JobStatus>> allJobsFuture = allOptionalJobsFuture.thenApply(this::flattenOptionalCollection);
    final JobsOverview completedJobsOverview = executionGraphInfoStore.getStoredJobsOverview();
    return allJobsFuture.thenCombine(taskManagerOverviewFuture, (Collection<JobStatus> runningJobsStatus, ResourceOverview resourceOverview) -> {
        final JobsOverview allJobsOverview = JobsOverview.create(runningJobsStatus).combine(completedJobsOverview);
        return new ClusterOverview(resourceOverview, allJobsOverview);
    });
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterOverview(org.apache.flink.runtime.messages.webmonitor.ClusterOverview) Collection(java.util.Collection) ResourceOverview(org.apache.flink.runtime.resourcemanager.ResourceOverview) JobsOverview(org.apache.flink.runtime.messages.webmonitor.JobsOverview)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 ResourceOverview (org.apache.flink.runtime.resourcemanager.ResourceOverview)2 URI (java.net.URI)1 Duration (java.time.Duration)1 Collection (java.util.Collection)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 JobStatus (org.apache.flink.api.common.JobStatus)1 Deadline (org.apache.flink.api.common.time.Deadline)1 Configuration (org.apache.flink.configuration.Configuration)1 CoreOptions (org.apache.flink.configuration.CoreOptions)1 HeartbeatManagerOptions (org.apache.flink.configuration.HeartbeatManagerOptions)1 JobManagerOptions (org.apache.flink.configuration.JobManagerOptions)1 MemorySize (org.apache.flink.configuration.MemorySize)1 RestOptions (org.apache.flink.configuration.RestOptions)1 TaskManagerOptions (org.apache.flink.configuration.TaskManagerOptions)1 UnmodifiableConfiguration (org.apache.flink.configuration.UnmodifiableConfiguration)1 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)1 ClusterOverview (org.apache.flink.runtime.messages.webmonitor.ClusterOverview)1