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


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/controller/FlinkResourceContext.java:
##########
@@ -47,6 +55,48 @@ public abstract class FlinkResourceContext<CR extends 
AbstractFlinkResource<?, ?
     private FlinkOperatorConfiguration operatorConfig;
     private Configuration observeConfig;
     private FlinkService flinkService;
+    private KubernetesJobAutoScalerContext autoScalerContext;
+
+    public KubernetesJobAutoScalerContext getJobAutoScalerContext() {
+        if (autoScalerContext != null) {
+            return autoScalerContext;
+        }
+        return autoScalerContext = createJobAutoScalerContext();
+    }
+
+    private KubernetesJobAutoScalerContext createJobAutoScalerContext() {
+        Configuration conf = new Configuration(getObserveConfig());
+        conf.set(
+                AutoScalerOptions.FLINK_CLIENT_TIMEOUT,
+                getOperatorConfig().getFlinkClientTimeout());
+
+        CommonStatus<?> status = getResource().getStatus();
+        String jobId = status.getJobStatus().getJobId();
+
+        JobStatus jobStatus = generateJobStatusEnum(status);
+
+        return new KubernetesJobAutoScalerContext(
+                jobId == null ? null : JobID.fromHexString(jobId),
+                jobStatus,
+                conf,
+                getResourceMetricGroup(),
+                () -> getFlinkService().getClusterClient(conf),
+                resource,
+                getKubernetesClient());
+    }
+
+    @Nullable
+    private JobStatus generateJobStatusEnum(CommonStatus<?> status) {
+        if (status.getLifecycleState() != ResourceLifecycleState.STABLE) {
+            return null;
+        }
+
+        String state = status.getJobStatus().getState();
+        if (state == null) {
+            return null;
+        }
+        return JobStatus.valueOf(state);

Review Comment:
   Hi @mxm  @gyfora , could the type of 
`org.apache.flink.kubernetes.operator.api.status.JobStatus#state` be changed 
from `String` to `org.apache.flink.api.common.JobStatus`?
   
   I see all setters respect it. If it can be changed, the 
`JobStatus.valueOf(state)` isn't necessary.



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