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

fix: Fix services endpoint to show correct list of onboarded services #3919

Draft
wants to merge 4 commits into
base: v3.x.x
Choose a base branch
from
Draft
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
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
Loading