srpraneeth commented on code in PR #682: URL: https://github.com/apache/flink-kubernetes-operator/pull/682#discussion_r1348082819
########## flink-kubernetes-operator-autoscaler/src/main/java/org/apache/flink/kubernetes/operator/autoscaler/validation/AutoScalerValidator.java: ########## @@ -0,0 +1,109 @@ +/* + * 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.autoscaler.validation; + +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.kubernetes.operator.api.FlinkDeployment; +import org.apache.flink.kubernetes.operator.api.FlinkSessionJob; +import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec; +import org.apache.flink.kubernetes.operator.autoscaler.config.AutoScalerOptions; +import org.apache.flink.kubernetes.operator.utils.FlinkUtils; +import org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Optional; + +/** Validator implementation for the AutoScaler from {@link Configuration}. */ +public class AutoScalerValidator implements FlinkResourceValidator { + + private static final Logger LOG = LoggerFactory.getLogger(FlinkUtils.class); + + @Override + public Optional<String> validateSessionJob( + FlinkSessionJob sessionJob, Optional<FlinkDeployment> session) { + LOG.info("AutoScaler Configurations validator {}", sessionJob); + var spec = sessionJob.getSpec(); + if (spec.getFlinkConfiguration() != null) { + var flinkConfiguration = Configuration.fromMap(spec.getFlinkConfiguration()); + return validateAutoScalerFlinkConfiguration(flinkConfiguration); + } + return Optional.empty(); + } + + @Override + public Optional<String> validateDeployment(FlinkDeployment deployment) { + LOG.info("AutoScaler Configurations validator {}", deployment); + FlinkDeploymentSpec spec = deployment.getSpec(); + if (spec.getFlinkConfiguration() != null) { + var flinkConfiguration = Configuration.fromMap(spec.getFlinkConfiguration()); + return validateAutoScalerFlinkConfiguration(flinkConfiguration); + } + return Optional.empty(); + } + + private Optional<String> validateAutoScalerFlinkConfiguration( + Configuration flinkConfiguration) { + return firstPresent( + validateNumber(flinkConfiguration, AutoScalerOptions.MAX_SCALE_DOWN_FACTOR, 0.0d), + validateNumber(flinkConfiguration, AutoScalerOptions.MAX_SCALE_UP_FACTOR, 1.0d), Review Comment: Done.. Fixed.. Now all the above options are just validated for the non negative number. || Rule | Affecting Property | MinValue | MaxValue | |-| ----------- | ----------- | ----------- | ----------- | |1| validateMaxScaleDownFactor | kubernetes.operator.job.autoscaler.scale-down.max-factor | 0.0d | None | |2| validateMaxScaleUpFactor | kubernetes.operator.job.autoscaler.scale-up.max-factor | 0.0d | None | |3| validateTargetUtilization | kubernetes.operator.job.autoscaler.target.utilization | 0.0d | None | |4| validateTargetUtilizationBoundary | kubernetes.operator.job.autoscaler.target.utilization.boundary | 0.0d | None | -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org