Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNOX-2962 - Knox readiness check gateway-status endpoint should return the list of topologies for which it is waiting for #800

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ public synchronized boolean status() {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,4 +45,20 @@ public void testReadyStatus() throws Exception {
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Response status() {
.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();
Expand Down
Loading