org.apache.flink.runtime.healthmanager.plugins.policies.DryRunPolicy Maven / Gradle / Ivy
/*
* 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.healthmanager.plugins.policies;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.healthmanager.HealthMonitor;
import org.apache.flink.runtime.healthmanager.plugins.Policy;
import org.apache.flink.runtime.healthmanager.plugins.detectors.DirectOOMDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.DryRunCheckTrigger;
import org.apache.flink.runtime.healthmanager.plugins.detectors.FailoverDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.FrequentFullGCDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.HeapOOMDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.HighNativeMemoryDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.JobStableDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.KilledDueToMemoryExceedDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.LongTimeFullGCDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.LowMemoryDetector;
import org.apache.flink.runtime.healthmanager.plugins.executors.DryRunActionExecutor;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.DirectMemoryAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.DryRunParallelismResolver;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.HeapMemoryAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.NativeMemoryAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.utils.HealthMonitorOptions;
import java.util.HashSet;
import java.util.Set;
/**
* Dry run policy.
*/
public class DryRunPolicy implements Policy {
@Override
public void apply(HealthMonitor monitor) {
Configuration config = monitor.getConfig();
// slow down health check.
if (!config.contains(HealthMonitor.HEALTH_CHECK_INTERNAL)) {
config.setLong(HealthMonitor.HEALTH_CHECK_INTERNAL,
config.getLong(HealthMonitorOptions.PARALLELISM_SCALE_INTERVAL) / 2);
}
if (!config.contains(HealthMonitorOptions.PARALLELISM_SCALE_BY_MAX_WORKLOAD)) {
config.setBoolean(HealthMonitorOptions.PARALLELISM_SCALE_BY_MAX_WORKLOAD, true);
}
// set special action executor.
config.setString(HealthMonitor.ACTION_EXECUTOR_CLASS, DryRunActionExecutor.class.getCanonicalName());
setDetectors(config);
setResolvers(config);
}
@Override
public boolean reloadPlugin() {
return false;
}
public void setResolvers(Configuration config) {
Set resolverClazzs = new HashSet<>();
if (config.getBoolean(HealthMonitorOptions.ENABLE_PARALLELISM_RESCALE)) {
resolverClazzs.add(DryRunParallelismResolver.class.getCanonicalName());
}
if (config.getBoolean(HealthMonitorOptions.ENABLE_RESOURCE_RESCALE)) {
if (config.getBoolean(HealthMonitorOptions.ENABLE_MEMORY_RESCALE)) {
resolverClazzs.add(HeapMemoryAdjuster.class.getCanonicalName());
resolverClazzs.add(DirectMemoryAdjuster.class.getCanonicalName());
resolverClazzs.add(NativeMemoryAdjuster.class.getCanonicalName());
}
}
config.setString(HealthMonitor.RESOLVER_CLASSES, String.join(",", resolverClazzs));
}
private void setDetectors(Configuration config) {
Set detectorClazzs = new HashSet<>();
if (config.getBoolean(HealthMonitorOptions.ENABLE_PARALLELISM_RESCALE)) {
// detectors which will check state of job
detectorClazzs.add(JobStableDetector.class.getCanonicalName());
detectorClazzs.add(FailoverDetector.class.getCanonicalName());
detectorClazzs.add(FrequentFullGCDetector.class.getCanonicalName());
detectorClazzs.add(LongTimeFullGCDetector.class.getCanonicalName());
detectorClazzs.add(DryRunCheckTrigger.class.getCanonicalName());
}
if (config.getBoolean(HealthMonitorOptions.ENABLE_RESOURCE_RESCALE)) {
detectorClazzs.add(HeapOOMDetector.class.getCanonicalName());
detectorClazzs.add(FrequentFullGCDetector.class.getCanonicalName());
detectorClazzs.add(LongTimeFullGCDetector.class.getCanonicalName());
detectorClazzs.add(DirectOOMDetector.class.getCanonicalName());
detectorClazzs.add(HighNativeMemoryDetector.class.getCanonicalName());
detectorClazzs.add(KilledDueToMemoryExceedDetector.class.getCanonicalName());
detectorClazzs.add(LowMemoryDetector.class.getCanonicalName());
detectorClazzs.add(JobStableDetector.class.getCanonicalName());
}
config.setString(HealthMonitor.DETECTOR_CLASSES, String.join(",", detectorClazzs));
}
}