Skip to content

Commit

Permalink
fix: Fix services endpoint to show correct list of onboarded services (
Browse files Browse the repository at this point in the history
…#3919)

Signed-off-by: Pavel Jareš <[email protected]>
  • Loading branch information
pj892031 authored Dec 13, 2024
1 parent 1106cb9 commit 3d20320
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,10 +91,16 @@ private String getBaseUrl(ApiInfo apiInfo, InstanceInfo instanceInfo) {
gatewayAddress.getScheme(), gatewayAddress.getHostname(), getBasePath(apiInfo, instanceInfo));
}

static List<InstanceInfo> 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<InstanceInfo> appInstances = application.getInstances();
List<InstanceInfo> appInstances = getPrimaryInstances(application);
if (ObjectUtils.isEmpty(appInstances)) {
return ServiceInfo.builder()
.serviceId(serviceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -372,4 +374,38 @@ private InstanceInfo createFullTestInstance() {
.build();
}

}
@Nested
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);

List<InstanceInfo> instances = ServicesInfoService.getPrimaryInstances(application);
assertEquals(2, instances.size());
assertSame(PRIMARY_WITH_METADATA, instances.get(0));
assertSame(PRIMARY_WITHOUT_METADATA, instances.get(1));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3d20320

Please sign in to comment.