From b73466296046c65e2315767ecd4af3b3fe3a8c34 Mon Sep 17 00:00:00 2001 From: Jakub Balhar Date: Tue, 30 Apr 2024 11:17:17 +0200 Subject: [PATCH] feat: Add message for when API Mediation Layer starts (#3523) * Add message for when API Mediation Layer starts Signed-off-by: Jakub Balhar * use apiml logger Signed-off-by: achmelo * Add correct API ML Log message Signed-off-by: Jakub Balhar * Issue correct message Signed-off-by: Jakub Balhar * Merge unnecessary conditions Signed-off-by: Jakub Balhar * Clean messages Signed-off-by: Jakub Balhar * Improve reason Signed-off-by: Jakub Balhar --------- Signed-off-by: Jakub Balhar Signed-off-by: achmelo Co-authored-by: achmelo --- .../main/resources/utility-log-messages.yml | 7 +++++++ .../gateway/health/GatewayHealthIndicator.java | 11 +++++++++++ .../health/GatewayHealthIndicatorTest.java | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/apiml-utility/src/main/resources/utility-log-messages.yml b/apiml-utility/src/main/resources/utility-log-messages.yml index bacb0cce8a..4da68aae30 100644 --- a/apiml-utility/src/main/resources/utility-log-messages.yml +++ b/apiml-utility/src/main/resources/utility-log-messages.yml @@ -10,6 +10,13 @@ messages: reason: "The service started." action: "No action required." + - key: org.zowe.apiml.common.mediationLayerStarted + number: ZWEAM001 + type: INFO + text: "started" + reason: "All API ML services started." + action: "No action required." + # General messages # 100-199 diff --git a/gateway-service/src/main/java/org/zowe/apiml/gateway/health/GatewayHealthIndicator.java b/gateway-service/src/main/java/org/zowe/apiml/gateway/health/GatewayHealthIndicator.java index b6b206b539..6430f305a5 100644 --- a/gateway-service/src/main/java/org/zowe/apiml/gateway/health/GatewayHealthIndicator.java +++ b/gateway-service/src/main/java/org/zowe/apiml/gateway/health/GatewayHealthIndicator.java @@ -18,6 +18,8 @@ import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.stereotype.Component; import org.zowe.apiml.gateway.security.login.Providers; +import org.zowe.apiml.message.log.ApimlLogger; +import org.zowe.apiml.message.yaml.YamlMessageServiceInstance; import org.zowe.apiml.product.constants.CoreService; import static org.springframework.boot.actuate.health.Status.DOWN; @@ -31,6 +33,10 @@ public class GatewayHealthIndicator extends AbstractHealthIndicator { private final DiscoveryClient discoveryClient; private final Providers loginProviders; private String apiCatalogServiceId; + + private final ApimlLogger apimlLog = ApimlLogger.of(GatewayHealthIndicator.class, + YamlMessageServiceInstance.getInstance()); + boolean startedInformationPublished = false; public GatewayHealthIndicator(DiscoveryClient discoveryClient, Providers providers, @@ -69,6 +75,11 @@ protected void doHealthCheck(Health.Builder builder) { if (anyCatalogIsAvailable) { builder.withDetail(CoreService.API_CATALOG.getServiceId(), toStatus(apiCatalogUp).getCode()); } + + if (!startedInformationPublished && discoveryUp && apiCatalogUp && authUp) { + apimlLog.log("org.zowe.apiml.common.mediationLayerStarted"); + startedInformationPublished = true; + } } private Status toStatus(boolean up) { diff --git a/gateway-service/src/test/java/org/zowe/apiml/gateway/health/GatewayHealthIndicatorTest.java b/gateway-service/src/test/java/org/zowe/apiml/gateway/health/GatewayHealthIndicatorTest.java index ed0c34efd4..0347b68f14 100644 --- a/gateway-service/src/test/java/org/zowe/apiml/gateway/health/GatewayHealthIndicatorTest.java +++ b/gateway-service/src/test/java/org/zowe/apiml/gateway/health/GatewayHealthIndicatorTest.java @@ -124,4 +124,22 @@ void givenCustomCatalogProvider_whenHealthIsRequested_thenStatusIsUp() { String code = (String) builder.build().getDetails().get(CoreService.API_CATALOG.getServiceId()); assertThat(code, is("UP")); } + + @Test + void givenEverythingIsHealthy_whenHealthRequested_onceLogMessageAboutStartup() { + when(providers.isZosfmUsed()).thenReturn(true); + when(providers.isZosmfAvailableAndOnline()).thenReturn(true); + + DiscoveryClient discoveryClient = mock(DiscoveryClient.class); + when(discoveryClient.getInstances(CoreService.API_CATALOG.getServiceId())).thenReturn( + Collections.singletonList(getDefaultServiceInstance(CoreService.API_CATALOG.getServiceId(), "host", 10014))); + when(discoveryClient.getInstances(CoreService.DISCOVERY.getServiceId())).thenReturn( + Collections.singletonList(getDefaultServiceInstance(CoreService.DISCOVERY.getServiceId(), "host", 10011))); + + GatewayHealthIndicator gatewayHealthIndicator = new GatewayHealthIndicator(discoveryClient, providers, CoreService.API_CATALOG.getServiceId()); + Health.Builder builder = new Health.Builder(); + gatewayHealthIndicator.doHealthCheck(builder); + + assertThat(gatewayHealthIndicator.startedInformationPublished, is(true)); + } }