XComp commented on a change in pull request #18913: URL: https://github.com/apache/flink/pull/18913#discussion_r815774271
########## File path: flink-core/src/main/java/org/apache/flink/configuration/CleanupOptions.java ########## @@ -0,0 +1,195 @@ +/* + * 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.configuration; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.annotation.docs.ConfigGroup; +import org.apache.flink.annotation.docs.ConfigGroups; +import org.apache.flink.configuration.description.Description; +import org.apache.flink.configuration.description.TextElement; + +import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableSet; + +import java.time.Duration; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.apache.flink.configuration.description.TextElement.code; +import static org.apache.flink.configuration.description.TextElement.text; + +/** + * {@link ConfigOption} collection for the configuring repeatable cleanup of resource cleanup after + * a job reached a globally-terminated state. + * + * <p>This implementation copies {@link RestartStrategyOptions} to provide similar user experience. + * FLINK-26359 is created to clean this up. + */ +@PublicEvolving +@ConfigGroups( + groups = { + @ConfigGroup( + name = "ExponentialDelayCleanupStrategy", + keyPrefix = "cleanup-strategy.exponential-delay"), + @ConfigGroup( + name = "FixedDelayCleanupStrategy", + keyPrefix = "cleanup-strategy.fixed-delay"), + }) +public class CleanupOptions { + + private static final String CLEANUP_STRATEGY_PARAM = "cleanup-strategy"; + + public static final String FIXED_DELAY_LABEL = "fixed-delay"; + public static final String EXPONENTIAL_DELAY_LABEL = "exponential-delay"; + + public static final Set<String> NONE_PARAM_VALUES = ImmutableSet.of("none", "disable", "off"); + + private static String createParameterPrefix(String paramGroupKey) { + return CLEANUP_STRATEGY_PARAM + "." + paramGroupKey + "."; + } + + private static String createFixedDelayParameterPrefix(String parameter) { + return createParameterPrefix(FIXED_DELAY_LABEL) + parameter; + } + + private static String createExponentialBackoffParameterPrefix(String parameter) { + return createParameterPrefix(EXPONENTIAL_DELAY_LABEL) + parameter; + } + + public static String extractAlphaNumericCharacters(String paramName) { + return paramName.replaceAll("[^a-zA-Z0-9]", ""); + } + + public static final ConfigOption<String> CLEANUP_STRATEGY = + ConfigOptions.key(CLEANUP_STRATEGY_PARAM) + .stringType() + .defaultValue(EXPONENTIAL_DELAY_LABEL) + .withDescription( + Description.builder() + .text( + "Defines the cleanup strategy to use in case of cleanup failures.") + .linebreak() + .text("Accepted values are:") + .list( + text( + NONE_PARAM_VALUES.stream() + .map(ignored -> "%s") + .collect( + Collectors.joining( + ", ")) + + ": Cleanup is only performed once. No retry " + + "will be initiated in case of failure.", + NONE_PARAM_VALUES.stream() + .map(TextElement::code) + .collect(Collectors.toList()) + .toArray( + new TextElement + [NONE_PARAM_VALUES + .size()])), + text( + "%s, %s: Cleanups will run in a static interval up " Review comment: thanks for the suggestion. I like it 👍 -- 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]
