org.apache.flink.runtime.healthmanager.plugins.executors.DirectActionExecutor 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.executors;
import org.apache.flink.runtime.healthmanager.HealthMonitor;
import org.apache.flink.runtime.healthmanager.RestServerClient;
import org.apache.flink.runtime.healthmanager.metrics.MetricProvider;
import org.apache.flink.runtime.healthmanager.plugins.Action;
import org.apache.flink.runtime.healthmanager.plugins.ActionExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Direct Action Executor.
*/
public class DirectActionExecutor implements ActionExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(DirectActionExecutor.class);
private RestServerClient restServerClient;
private MetricProvider metricProvider;
@Override
public void open(HealthMonitor monitor) {
restServerClient = monitor.getRestServerClient();
metricProvider = monitor.getMetricProvider();
}
@Override
public boolean execute(Action action) throws Throwable {
action.execute(restServerClient);
if (!action.validate(metricProvider, restServerClient)) {
LOGGER.info("Action {} validate failed, try to roll back", action);
// execution roll back action if validation failed.
Action actionToRollback = action.rollback();
LOGGER.info("Executing roll back action {}", actionToRollback);
actionToRollback.execute(restServerClient);
return false;
}
LOGGER.info("Action {} validate succeed.", action);
return true;
}
@Override
public void close() {
}
}