mateczagany commented on code in PR #821: URL: https://github.com/apache/flink-kubernetes-operator/pull/821#discussion_r1667389146
########## flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/observer/snapshot/StateSnapshotObserver.java: ########## @@ -0,0 +1,197 @@ +/* + * 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.observer.snapshot; + +import org.apache.flink.autoscaler.utils.DateTimeUtils; +import org.apache.flink.kubernetes.operator.api.FlinkDeployment; +import org.apache.flink.kubernetes.operator.api.FlinkStateSnapshot; +import org.apache.flink.kubernetes.operator.api.status.FlinkStateSnapshotState; +import org.apache.flink.kubernetes.operator.controller.FlinkResourceContext; +import org.apache.flink.kubernetes.operator.controller.FlinkStateSnapshotContext; +import org.apache.flink.kubernetes.operator.observer.CheckpointFetchResult; +import org.apache.flink.kubernetes.operator.observer.SavepointFetchResult; +import org.apache.flink.kubernetes.operator.reconciler.ReconciliationUtils; +import org.apache.flink.kubernetes.operator.service.FlinkResourceContextFactory; +import org.apache.flink.kubernetes.operator.utils.EventRecorder; + +import io.fabric8.kubernetes.client.KubernetesClient; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.Instant; + +/** The observer of {@link org.apache.flink.kubernetes.operator.api.FlinkStateSnapshot}. */ +@RequiredArgsConstructor +public class StateSnapshotObserver { + + private static final Logger LOG = LoggerFactory.getLogger(StateSnapshotObserver.class); + + private final FlinkResourceContextFactory ctxFactory; + private final EventRecorder eventRecorder; + + public void observe(FlinkStateSnapshotContext ctx) { + var resource = ctx.getResource(); + var savepointState = resource.getStatus().getState(); + + if (FlinkStateSnapshotState.IN_PROGRESS.equals(savepointState)) { + observeSavepointState(ctx); + } + } + + private void observeSavepointState(FlinkStateSnapshotContext ctx) { + var resource = ctx.getResource(); + var resourceName = resource.getMetadata().getName(); + var triggerId = resource.getStatus().getTriggerId(); + + if (StringUtils.isEmpty(triggerId)) { + return; + } + + LOG.debug("Observing savepoint state for resource {}...", resourceName); + var secondaryResource = + ctx.getSecondaryResource() + .orElseThrow( + () -> + new RuntimeException( + String.format( + "Secondary resource %s for savepoint %s was not found", + resource.getSpec().getJobReference(), + resourceName))); Review Comment: Yeah, I agree this should be abandoned as well. I have also added an event that will be produced when the snapshot gets to an abandoned state. -- 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]
