Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Jareš <[email protected]>
  • Loading branch information
pj892031 committed Nov 29, 2024
1 parent 2e028cb commit 9adab63
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
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,31 @@ private InstanceInfo createFullTestInstance() {
.build();
}

}
@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<InstanceInfo> instances = ServicesInfoService.getPrimaryInstances(application);
assertEquals(2, instances.size());
assertSame(PRIMARY_WITH_METADATA, instances.get(0));
assertSame(PRIMARY_WITHOUT_METADATA, instances.get(1));
}

}

}

0 comments on commit 9adab63

Please sign in to comment.