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


##########
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:
   (Didn't see your comments until I hit refresh). Fine to defer this.



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

Reply via email to