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

amagyar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new ff6bcbcac KNOX-2962 - Knox readiness check gateway-status endpoint 
should return the list of topologies for which it is waiting for (#800)
ff6bcbcac is described below

commit ff6bcbcac5c5d0e8f00f4944207975f5b1bfeebf
Author: Attila Magyar <[email protected]>
AuthorDate: Wed Oct 11 11:54:50 2023 +0200

    KNOX-2962 - Knox readiness check gateway-status endpoint should return the 
list of topologies for which it is waiting for (#800)
---
 .../services/topology/impl/GatewayStatusService.java   |  9 +++++++--
 .../topology/impl/GatewayStatusServiceTest.java        | 18 ++++++++++++++++++
 .../knox/gateway/service/health/PingResource.java      |  2 +-
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusService.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusService.java
index 08ad866b2..1cc447245 100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusService.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusService.java
@@ -45,12 +45,17 @@ public class GatewayStatusService implements Service {
       LOG.noTopologiesToCheck();
       return false;
     }
-    Set<String> missing = new HashSet<>(topologyNamesToCheck);
-    missing.removeAll(deployedTopologies);
+    Set<String> missing = pendingTopologies();
     LOG.checkingGatewayStatus(deployedTopologies, missing);
     return missing.isEmpty();
   }
 
+  public synchronized Set<String> pendingTopologies() {
+    Set<String> missing = new HashSet<>(topologyNamesToCheck);
+    missing.removeAll(deployedTopologies);
+    return missing;
+  }
+
   /**
    * The list of topologies (which will be used to check the gateway status.)
    * are either coming from the config or collected automatically.
diff --git 
a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusServiceTest.java
 
b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusServiceTest.java
index fe866a660..8e121a1b9 100644
--- 
a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusServiceTest.java
+++ 
b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/impl/GatewayStatusServiceTest.java
@@ -17,10 +17,12 @@
  */
 package org.apache.knox.gateway.services.topology.impl;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 
 import org.apache.knox.gateway.config.GatewayConfig;
@@ -43,4 +45,20 @@ public class GatewayStatusServiceTest {
     statusService.onTopologyReady("t2");
     assertTrue(statusService.status());
   }
+
+  @Test
+  public void testPendingTopologies() throws Exception {
+    GatewayStatusService statusService = new GatewayStatusService();
+    GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
+    statusService.init(config, null);
+    assertFalse(statusService.status());
+    EasyMock.expect(config.getHealthCheckTopologies()).andReturn(new 
HashSet<>(Arrays.asList("t1", "t2"))).anyTimes();
+    EasyMock.replay(config);
+    statusService.initTopologiesToCheck();
+    assertEquals(new HashSet<>(Arrays.asList("t1", "t2")), 
statusService.pendingTopologies());
+    statusService.onTopologyReady("t1");
+    assertEquals(new HashSet<>(Arrays.asList("t2")), 
statusService.pendingTopologies());
+    statusService.onTopologyReady("t2");
+    assertEquals(Collections.emptySet(), statusService.pendingTopologies());
+  }
 }
\ No newline at end of file
diff --git 
a/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
 
b/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
index 2d4f4e720..0a58aeaa5 100644
--- 
a/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
+++ 
b/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
@@ -101,7 +101,7 @@ public class PingResource {
             .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
     GatewayStatusService statusService = 
services.getService(ServiceType.GATEWAY_STATUS_SERVICE);
     try (PrintWriter writer = response.getWriter()) {
-      writer.println(statusService.status() ? OK : PENDING);
+      writer.println(statusService.status() ? OK : PENDING + ": " + 
statusService.pendingTopologies());
     } catch (IOException e) {
       log.logException("status", e);
       return Response.serverError().entity(String.format(Locale.ROOT, "Failed 
to reply correctly due to : %s ", e)).build();

Reply via email to