1996fanrui commented on code in PR #698:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/698#discussion_r1377480315


##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/realizer/RescaleApiScalingRealizer.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.autoscaler.realizer;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.autoscaler.JobAutoScalerContext;
+import org.apache.flink.autoscaler.config.AutoScalerOptions;
+import org.apache.flink.autoscaler.event.AutoScalerEventHandler;
+import org.apache.flink.client.program.rest.RestClusterClient;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.jobgraph.JobResourceRequirements;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.jobgraph.JobVertexResourceRequirements;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.JobMessageParameters;
+import org.apache.flink.runtime.rest.messages.job.JobResourceRequirementsBody;
+import 
org.apache.flink.runtime.rest.messages.job.JobResourceRequirementsHeaders;
+import 
org.apache.flink.runtime.rest.messages.job.JobResourcesRequirementsUpdateHeaders;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/** Rescaling job based on rescale api. */
+public class RescaleApiScalingRealizer<KEY, Context extends 
JobAutoScalerContext<KEY>>
+        implements ScalingRealizer<KEY, Context> {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RescaleApiScalingRealizer.class);
+
+    private final AutoScalerEventHandler<KEY, JobAutoScalerContext<KEY>> 
eventHandler;
+
+    public RescaleApiScalingRealizer(
+            AutoScalerEventHandler<KEY, JobAutoScalerContext<KEY>> 
eventHandler) {
+        this.eventHandler = eventHandler;
+    }
+
+    @Override
+    public void realize(Context context, Map<String, String> 
parallelismOverrides) {
+        Configuration conf = context.getConfiguration();
+        if (!conf.get(JobManagerOptions.SCHEDULER)
+                .equals(JobManagerOptions.SchedulerType.Adaptive)) {
+            LOG.debug("In-place rescaling is only available with the adaptive 
scheduler");
+            return;
+        }
+
+        JobStatus jobStatus = context.getJobStatus();
+        JobID jobID = context.getJobID();
+        if (jobID == null
+                || jobStatus == null
+                || jobStatus.isGloballyTerminalState()
+                || JobStatus.RECONCILING == jobStatus) {
+            LOG.info("Job in terminal or reconciling state cannot be scaled 
in-place");
+            return;
+        }

Review Comment:
   I try to keep the same logic with 
`NativeFlinkService#supportsInPlaceScaling`[1]. After thinking again, I think 
it can be simply: just check for `RUNNING` state.
   
   Because `JobAutoScalerImpl#scale` won't runScalingLogic  if it isn't 
`RUNNING`.
   
   [1] 
https://github.com/apache/flink-kubernetes-operator/blob/582c07aeec6b4bbcc68e0a85d31000d89dbd1958/flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/service/NativeFlinkService.java#L260



-- 
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]

Reply via email to