nishita-09 commented on code in PR #994:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/994#discussion_r2204029004


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/deployment/SessionReconciler.java:
##########
@@ -120,6 +126,61 @@ private void 
recoverSession(FlinkResourceContext<FlinkDeployment> ctx) throws Ex
                 
.setJobManagerDeploymentStatus(JobManagerDeploymentStatus.DEPLOYING);
     }
 
+    /**
+     * Detects unmanaged jobs running in the session cluster. Unmanaged jobs 
are jobs that exist in
+     * the Flink cluster but are not managed by FlinkSessionJob resources.
+     */
+    private Set<JobID> getUnmanagedJobs(
+            FlinkResourceContext<FlinkDeployment> ctx, Set<FlinkSessionJob> 
sessionJobs) {
+        LOG.info(
+                "Starting unmanaged job detection for session cluster: {}",
+                ctx.getResource().getMetadata().getName());
+        try {
+            // Get all jobs running in the Flink cluster
+            var flinkService = ctx.getFlinkService();
+            var clusterClient = 
flinkService.getClusterClient(ctx.getObserveConfig());
+            var allJobs =
+                    clusterClient
+                            .sendRequest(
+                                    JobsOverviewHeaders.getInstance(),
+                                    EmptyMessageParameters.getInstance(),
+                                    EmptyRequestBody.getInstance())
+                            .get()
+                            .getJobs();
+
+            // Get job IDs managed by FlinkSessionJob resources
+            Set<JobID> managedJobIds =
+                    sessionJobs.stream()
+                            .map(job -> 
job.getStatus().getJobStatus().getJobId())
+                            .filter(jobId -> jobId != null)
+                            .map(JobID::fromHexString)
+                            .collect(Collectors.toSet());
+
+            // Get job IDs that are not managed by FlinkSessionJob resources 
and are currently
+            // running
+            //    FAILED(TerminalState.GLOBALLY)
+            //    CANCELED(TerminalState.GLOBALLY)
+            //    FINISHED(TerminalState.GLOBALLY)
+            // Above terminal states are not considered since they are no 
longer active jobs

Review Comment:
   I actually thought this would be necessary to mention to clarify the 
functionality of this. 😢  Sure will remove if its too verbose



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