Dennis-Mircea commented on code in PR #1000: URL: https://github.com/apache/flink-kubernetes-operator/pull/1000#discussion_r3094241987
########## flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkRuntimeConfigurationUtils.java: ########## @@ -0,0 +1,254 @@ +/* + * 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.utils; + +import org.apache.flink.configuration.CheckpointingOptions; +import org.apache.flink.configuration.CoreOptions; +import org.apache.flink.configuration.PipelineOptions; +import org.apache.flink.configuration.StateChangelogOptions; +import org.apache.flink.runtime.rest.messages.JobConfigInfo; +import org.apache.flink.runtime.rest.messages.checkpoints.CheckpointConfigInfo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Utility class for mapping Flink REST API responses (execution config, checkpoint config) into + * Flink {@link org.apache.flink.configuration.ConfigOption} key-value pairs suitable for the + * runtime configuration cache. + */ +public class FlinkRuntimeConfigurationUtils { + + private static final Logger LOG = LoggerFactory.getLogger(FlinkRuntimeConfigurationUtils.class); + + private static final org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind + .ObjectMapper + CHECKPOINT_CONFIG_MAPPER = + new org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind + .ObjectMapper(); + + /** + * Maps REST API JSON field names from {@link CheckpointConfigInfo} to Flink {@link + * org.apache.flink.configuration.ConfigOption} keys. Both sides use Flink's own constants for + * compile-time safety. + */ + public enum CheckpointConfigMapping { + PROCESSING_MODE( + CheckpointConfigInfo.FIELD_NAME_PROCESSING_MODE, + CheckpointingOptions.CHECKPOINTING_CONSISTENCY_MODE.key(), + false), + INTERVAL( + CheckpointConfigInfo.FIELD_NAME_CHECKPOINT_INTERVAL, + CheckpointingOptions.CHECKPOINTING_INTERVAL.key(), + true), + TIMEOUT( + CheckpointConfigInfo.FIELD_NAME_CHECKPOINT_TIMEOUT, + CheckpointingOptions.CHECKPOINTING_TIMEOUT.key(), + true), + MIN_PAUSE( + CheckpointConfigInfo.FIELD_NAME_CHECKPOINT_MIN_PAUSE, + CheckpointingOptions.MIN_PAUSE_BETWEEN_CHECKPOINTS.key(), + true), + MAX_CONCURRENT( + CheckpointConfigInfo.FIELD_NAME_CHECKPOINT_MAX_CONCURRENT, + CheckpointingOptions.MAX_CONCURRENT_CHECKPOINTS.key(), + false), + TOLERABLE_FAILURES( + CheckpointConfigInfo.FIELD_NAME_TOLERABLE_FAILED_CHECKPOINTS, + CheckpointingOptions.TOLERABLE_FAILURE_NUMBER.key(), + false), + UNALIGNED( + CheckpointConfigInfo.FIELD_NAME_UNALIGNED_CHECKPOINTS, + CheckpointingOptions.ENABLE_UNALIGNED.key(), + false), + ALIGNED_TIMEOUT( + CheckpointConfigInfo.FIELD_NAME_ALIGNED_CHECKPOINT_TIMEOUT, + CheckpointingOptions.ALIGNED_CHECKPOINT_TIMEOUT.key(), + true), + CHECKPOINTS_AFTER_TASKS_FINISH( + CheckpointConfigInfo.FIELD_NAME_CHECKPOINTS_AFTER_TASKS_FINISH, + CheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH.key(), + false), + STATE_CHANGELOG( + CheckpointConfigInfo.FIELD_NAME_STATE_CHANGELOG, + StateChangelogOptions.ENABLE_STATE_CHANGE_LOG.key(), + false), + PERIODIC_MATERIALIZATION_INTERVAL( + CheckpointConfigInfo.FIELD_NAME_PERIODIC_MATERIALIZATION_INTERVAL, + StateChangelogOptions.PERIODIC_MATERIALIZATION_INTERVAL.key(), + true), + CHANGELOG_STORAGE( + CheckpointConfigInfo.FIELD_NAME_CHANGELOG_STORAGE, + StateChangelogOptions.STATE_CHANGE_LOG_STORAGE.key(), + false); + + private final String jsonField; + private final String configKey; + private final boolean isDuration; + + CheckpointConfigMapping(String jsonField, String configKey, boolean isDuration) { + this.jsonField = jsonField; + this.configKey = configKey; + this.isDuration = isDuration; + } + + public String getJsonField() { + return jsonField; + } + } + + private static final Map<String, String> STATE_BACKEND_NAMES = + Map.of( + "EmbeddedRocksDBStateBackend", "rocksdb", + "HashMapStateBackend", "hashmap"); + + private static final Map<String, String> CHECKPOINT_STORAGE_NAMES = + Map.of( + "FileSystemCheckpointStorage", "filesystem", + "JobManagerCheckpointStorage", "jobmanager"); + + /** All config keys that {@link #mapCheckpointConfiguration} can produce. */ + public static final Set<String> CHECKPOINT_CONFIG_KEYS = + Stream.concat( + Stream.of(CheckpointConfigMapping.values()).map(m -> m.configKey), + Stream.of( + CheckpointingOptions.EXTERNALIZED_CHECKPOINT_RETENTION.key(), + CheckpointingOptions.STATE_BACKEND.key(), Review Comment: I see `CheckpointingOptions.STATE_BACKEND` is deprecated. Can we use `StateBackendOptions.STATE_BACKEND` instead? -- 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]
