All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.runtime.healthmanager.plugins.detectors.PlanChangeDetector Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
/*
 * 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.detectors;

import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;
import org.apache.flink.runtime.healthmanager.HealthMonitor;
import org.apache.flink.runtime.healthmanager.RestServerClient;
import org.apache.flink.runtime.healthmanager.plugins.Detector;
import org.apache.flink.runtime.healthmanager.plugins.symptoms.PlanChanged;
import org.apache.flink.runtime.jobgraph.JobVertexID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * PlanChangeDetector checks whether current plan of job is the same as the plan defined in provider.
 */
public class PlanChangeDetector implements Detector {
	private static final Logger LOGGER = LoggerFactory.getLogger(PlanChangeDetector.class);
	public static final ConfigOption PLAN_PROVIDER =
			ConfigOptions.key("healthmonitor.plan.provider.class").noDefaultValue();

	private HealthMonitor monitor;
	private PlanProvider provider;

	@Override
	public void open(HealthMonitor monitor) {
		this.monitor = monitor;
		try {
			provider = (PlanProvider) Class.forName(monitor.getConfig().getString(PLAN_PROVIDER)).newInstance();
		} catch (Throwable e) {
			LOGGER.error("Fail to load plan provider", e);
		}
	}

	@Override
	public void close() {

	}

	@Override
	public PlanChanged detect() throws Exception {
		if (provider == null) {
			return null;
		}
		RestServerClient.JobConfig expectedConfig = provider.getJobConfig(monitor);

		for (Map.Entry entry: monitor.getJobConfig().getVertexConfigs().entrySet()) {
			RestServerClient.VertexConfig targetConfig = expectedConfig.getVertexConfigs().get(entry.getKey());
			if (targetConfig.getParallelism() != entry.getValue().getParallelism() ||
				!targetConfig.getResourceSpec().equals(entry.getValue().getResourceSpec())
			) {
				LOGGER.info("config of vertex {} changed, current {} target {}", entry.getKey(), entry.getValue(), targetConfig);
				return new PlanChanged(expectedConfig);
			}
		}
		return null;
	}

	/**
	 * interface to get expected JobConfig.
	 */
	public interface PlanProvider {
		RestServerClient.JobConfig getJobConfig(HealthMonitor monitor);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy