gaborgsomogyi commented on code in PR #394: URL: https://github.com/apache/flink-kubernetes-operator/pull/394#discussion_r993616745
########## flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/deployment/JobHealthChecker.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.kubernetes.operator.reconciler.deployment; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.kubernetes.operator.health.JobHealthInfo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; + +import java.time.Clock; +import java.time.Duration; + +import static org.apache.flink.kubernetes.operator.config.KubernetesOperatorConfigOptions.OPERATOR_CLUSTER_HEALTH_CHECK_RESTARTS_THRESHOLD; +import static org.apache.flink.kubernetes.operator.config.KubernetesOperatorConfigOptions.OPERATOR_CLUSTER_HEALTH_CHECK_RESTARTS_WINDOW; + +/** Evaluates whether the job is healthy. */ +public class JobHealthChecker { + + private static final Logger LOG = LoggerFactory.getLogger(JobHealthChecker.class); + + private final Clock clock; + @VisibleForTesting @Nullable JobHealthInfo lastValidJobHealthInfo; + + public JobHealthChecker(Clock clock) { + this.clock = clock; + } + + @VisibleForTesting + void setLastValidJobHealthInfo(JobHealthInfo lastValidJobHealthInfo) { + LOG.debug("Setting last valid health check info"); + this.lastValidJobHealthInfo = lastValidJobHealthInfo; Review Comment: Refactored fully. ########## flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/deployment/ApplicationReconciler.java: ########## @@ -272,6 +286,46 @@ private void recoverJmDeployment( restoreJob(deployment, specToRecover, deployment.getStatus(), ctx, observeConfig, true); } + private boolean shouldRestartJobBecauseUnhealthy( + FlinkDeployment deployment, Configuration observeConfig) { + if (observeConfig.getBoolean(OPERATOR_CLUSTER_HEALTH_CHECK_ENABLED)) { + if (jobHealthChecker == null) { + jobHealthChecker = new JobHealthChecker(Clock.systemDefaultZone()); + } + } else { + if (jobHealthChecker != null) { + jobHealthChecker = null; + } + } + + boolean result = false; + + if (jobHealthChecker != null) { + final String clusterInfoKey = JobHealthInfo.class.getSimpleName(); + if (deployment.getStatus().getClusterInfo().containsKey(clusterInfoKey)) { + LOG.debug("Cluster info contains job health info"); + if (!jobHealthChecker.isJobHealthy( Review Comment: Refactored fully. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
