This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-kubernetes-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 776c496  [SPARK-55343] Simplify `HealthProbe` class
776c496 is described below

commit 776c496399e77700ebb07c630ca39faa4bde01fc
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Tue Feb 3 13:44:48 2026 -0800

    [SPARK-55343] Simplify `HealthProbe` class
    
    ### What changes were proposed in this pull request?
    
    This PR aims to simplify `HealthProbe` class
    
    ### Why are the changes needed?
    
    To make it concise and more clear.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No behavior change.
    
    ### How was this patch tested?
    
    Pass the CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: `Opus 4.5` on `Claude Code v2.1.5`
    
    Closes #482 from dongjoon-hyun/SPARK-55343.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../apache/spark/k8s/operator/probe/HealthProbe.java   | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/HealthProbe.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/HealthProbe.java
index 750827a..64a80c0 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/HealthProbe.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/HealthProbe.java
@@ -28,7 +28,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 
 import com.sun.net.httpserver.HttpExchange;
 import com.sun.net.httpserver.HttpHandler;
@@ -58,17 +57,11 @@ public class HealthProbe implements HttpHandler {
    * @return True if the operator is healthy, false otherwise.
    */
   public boolean isHealthy() {
-    Optional<Boolean> operatorsAreReady = areOperatorsStarted(operators);
-    if (operatorsAreReady.isEmpty() || !operatorsAreReady.get()) {
+    if (!areOperatorsStarted(operators).orElse(false)) {
       return false;
     }
 
-    Optional<Boolean> runtimeInfosAreHealthy =
-        operators.stream()
-            .map(operator -> checkInformersHealth(operator.getRuntimeInfo()))
-            .reduce((a, b) -> a && b);
-
-    if (runtimeInfosAreHealthy.isEmpty() || !runtimeInfosAreHealthy.get()) {
+    if (!operators.stream().allMatch(op -> 
checkInformersHealth(op.getRuntimeInfo()))) {
       return false;
     }
 
@@ -90,11 +83,8 @@ public class HealthProbe implements HttpHandler {
    */
   @Override
   public void handle(HttpExchange exchange) throws IOException {
-    if (isHealthy()) {
-      sendMessage(exchange, HTTP_OK, "healthy");
-    } else {
-      sendMessage(exchange, HTTP_INTERNAL_ERROR, "unhealthy");
-    }
+    boolean flag = isHealthy();
+    sendMessage(exchange, flag ? HTTP_OK : HTTP_INTERNAL_ERROR, flag ? 
"healthy" : "unhealthy");
   }
 
   private boolean checkInformersHealth(RuntimeInfo operatorRuntimeInfo) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to