From 9adab63a6e6723b9cf2e766df559b3c49b25923c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jare=C5=A1?= Date: Fri, 29 Nov 2024 12:46:23 +0100 Subject: [PATCH 1/4] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel Jareš --- .../gateway/services/ServicesInfoService.java | 11 +++++-- .../services/ServicesInfoServiceTest.java | 31 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/gateway-service/src/main/java/org/zowe/apiml/gateway/services/ServicesInfoService.java b/gateway-service/src/main/java/org/zowe/apiml/gateway/services/ServicesInfoService.java index f627eb0a09..4d877ef25b 100644 --- a/gateway-service/src/main/java/org/zowe/apiml/gateway/services/ServicesInfoService.java +++ b/gateway-service/src/main/java/org/zowe/apiml/gateway/services/ServicesInfoService.java @@ -19,6 +19,7 @@ import org.springframework.util.ObjectUtils; import org.zowe.apiml.auth.Authentication; import org.zowe.apiml.config.ApiInfo; +import org.zowe.apiml.constants.EurekaMetadataDefinition; import org.zowe.apiml.eurekaservice.client.util.EurekaMetadataParser; import org.zowe.apiml.product.gateway.GatewayClient; import org.zowe.apiml.product.instance.ServiceAddress; @@ -90,10 +91,16 @@ private String getBaseUrl(ApiInfo apiInfo, InstanceInfo instanceInfo) { gatewayAddress.getScheme(), gatewayAddress.getHostname(), getBasePath(apiInfo, instanceInfo)); } + static List getPrimaryInstances(Application application) { + return application.getInstances() + .stream() + .filter(instanceInfo -> EurekaMetadataDefinition.RegistrationType.of(instanceInfo.getMetadata()).isPrimary()) + .toList(); + } + private ServiceInfo getServiceInfo(Application application) { String serviceId = application.getName().toLowerCase(); - - List appInstances = application.getInstances(); + List appInstances = getPrimaryInstances(application); if (ObjectUtils.isEmpty(appInstances)) { return ServiceInfo.builder() .serviceId(serviceId) diff --git a/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java b/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java index 29f1156867..a00dda5f9f 100644 --- a/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java +++ b/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java @@ -17,12 +17,14 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.zowe.apiml.auth.AuthenticationScheme; import org.zowe.apiml.config.ApiInfo; +import org.zowe.apiml.constants.EurekaMetadataDefinition; import org.zowe.apiml.eurekaservice.client.util.EurekaMetadataParser; import org.zowe.apiml.product.gateway.GatewayClient; import org.zowe.apiml.product.instance.ServiceAddress; @@ -372,4 +374,31 @@ private InstanceInfo createFullTestInstance() { .build(); } -} \ No newline at end of file + @Nested + class Multitenancy { + + private static final InstanceInfo PRIMARY_WITH_METADATA = InstanceInfo.Builder.newBuilder() + .setMetadata(Collections.singletonMap(EurekaMetadataDefinition.REGISTRATION_TYPE, RegistrationType.PRIMARY.getValue())) + .build(); + private static final InstanceInfo PRIMARY_WITHOUT_METADATA = InstanceInfo.Builder.newBuilder() + .build(); + private static final InstanceInfo ADDITIONAL = InstanceInfo.Builder.newBuilder() + .setMetadata(Collections.singletonMap(EurekaMetadataDefinition.REGISTRATION_TYPE, RegistrationType.ADDITIONAL.getValue())) + .build(); + + @Test + void givenApplication_whenGetPrimaryInstances_thenAdditionalWereRemoved() { + Application application = new Application("test"); + application.addInstance(PRIMARY_WITH_METADATA); + application.addInstance(PRIMARY_WITHOUT_METADATA); + application.addInstance(ADDITIONAL); + + List instances = ServicesInfoService.getPrimaryInstances(application); + assertEquals(2, instances.size()); + assertSame(PRIMARY_WITH_METADATA, instances.get(0)); + assertSame(PRIMARY_WITHOUT_METADATA, instances.get(1)); + } + + } + +} From f203310ac1cd9fb26f15a7baa13eefe047e7dc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jare=C5=A1?= Date: Fri, 29 Nov 2024 16:13:04 +0100 Subject: [PATCH 2/4] add log message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel Jareš --- .../org/zowe/apiml/integration/zos/ServicesInfoTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integration-tests/src/test/java/org/zowe/apiml/integration/zos/ServicesInfoTest.java b/integration-tests/src/test/java/org/zowe/apiml/integration/zos/ServicesInfoTest.java index 8160386a73..af3de2a475 100644 --- a/integration-tests/src/test/java/org/zowe/apiml/integration/zos/ServicesInfoTest.java +++ b/integration-tests/src/test/java/org/zowe/apiml/integration/zos/ServicesInfoTest.java @@ -202,9 +202,10 @@ void givenValidTokenWithAuthorizedUserAndValidServiceId(URI uri, String serviceI //@formatter:off given() .cookie(GATEWAY_TOKEN_COOKIE_NAME, token) - .when() + .when() .get(uri) - .then() + .then() + .log().ifValidationFails() .statusCode(is(SC_OK)) .header(VERSION_HEADER, CURRENT_VERSION) From 0995073b5bd92e40fadb7c914b6977fc7986cb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jare=C5=A1?= Date: Fri, 29 Nov 2024 17:20:32 +0100 Subject: [PATCH 3/4] attempt to fix citests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel Jareš --- .github/workflows/integration-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 93325c9df2..9d9209dc68 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -57,6 +57,7 @@ jobs: image: ghcr.io/balhar-jakub/discovery-service:${{ github.run_id }}-${{ github.run_number }} env: APIML_SERVICE_HOSTNAME: discovery-service-2 + APIML_DISCOVERY_ALLPEERSURLS: https://discovery-service-2:10011/eureka gateway-service: image: ghcr.io/balhar-jakub/gateway-service:${{ github.run_id }}-${{ github.run_number }} env: From f555f0a6af5764fbcd69d568bac731211a2c7ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jare=C5=A1?= Date: Fri, 29 Nov 2024 19:04:57 +0100 Subject: [PATCH 4/4] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel Jareš --- .../apiml/gateway/services/ServicesInfoServiceTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java b/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java index a00dda5f9f..1efbde957b 100644 --- a/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java +++ b/gateway-service/src/test/java/org/zowe/apiml/gateway/services/ServicesInfoServiceTest.java @@ -378,17 +378,24 @@ private InstanceInfo createFullTestInstance() { class Multitenancy { private static final InstanceInfo PRIMARY_WITH_METADATA = InstanceInfo.Builder.newBuilder() + .setInstanceId("primary-with-metadata") + .setAppName("primary-with-metadata") .setMetadata(Collections.singletonMap(EurekaMetadataDefinition.REGISTRATION_TYPE, RegistrationType.PRIMARY.getValue())) .build(); private static final InstanceInfo PRIMARY_WITHOUT_METADATA = InstanceInfo.Builder.newBuilder() + .setInstanceId("primary-without-metadata") + .setAppName("primary-without-metadata") .build(); private static final InstanceInfo ADDITIONAL = InstanceInfo.Builder.newBuilder() + .setInstanceId("additional") + .setAppName("additional") .setMetadata(Collections.singletonMap(EurekaMetadataDefinition.REGISTRATION_TYPE, RegistrationType.ADDITIONAL.getValue())) .build(); @Test void givenApplication_whenGetPrimaryInstances_thenAdditionalWereRemoved() { Application application = new Application("test"); + application.setName("test"); application.addInstance(PRIMARY_WITH_METADATA); application.addInstance(PRIMARY_WITHOUT_METADATA); application.addInstance(ADDITIONAL);