Skip to content

Commit

Permalink
feat: Add message for when API Mediation Layer starts (#3523)
Browse files Browse the repository at this point in the history
* Add message for when API Mediation Layer starts

Signed-off-by: Jakub Balhar <[email protected]>

* use apiml logger

Signed-off-by: achmelo <[email protected]>

* Add correct API ML Log message

Signed-off-by: Jakub Balhar <[email protected]>

* Issue correct message

Signed-off-by: Jakub Balhar <[email protected]>

* Merge unnecessary conditions

Signed-off-by: Jakub Balhar <[email protected]>

* Clean messages

Signed-off-by: Jakub Balhar <[email protected]>

* Improve reason

Signed-off-by: Jakub Balhar <[email protected]>

---------

Signed-off-by: Jakub Balhar <[email protected]>
Signed-off-by: achmelo <[email protected]>
Co-authored-by: achmelo <[email protected]>
  • Loading branch information
balhar-jakub and achmelo authored Apr 30, 2024
1 parent 2fce9c2 commit b734662
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apiml-utility/src/main/resources/utility-log-messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit b734662

Please sign in to comment.