Skip to content

Commit

Permalink
GH2883 pull local services Infos from ServicesInfoService
Browse files Browse the repository at this point in the history
Signed-off-by: alexandr cumarav <[email protected]>
  • Loading branch information
cumarav committed Aug 31, 2023
1 parent 6d3e679 commit 005001b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
Expand All @@ -28,6 +29,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.zowe.apiml.constants.EurekaMetadataDefinition.APIML_ID;
Expand Down Expand Up @@ -56,6 +58,7 @@ public class GatewayScanJob {
private final GatewayIndexService gatewayIndexerService;
private final InstanceInfoService instanceInfoService;
private final ServicesInfoService servicesInfoService;
private final EurekaRegistration serviceRegistration;

@Value("${apiml.service.apimlId:#{null}}")
private String currentApimlId;
Expand All @@ -72,8 +75,9 @@ public void startScanExternalGatewayJob() {
}

private void addLocalServices() {
String apimlIdKey = Optional.ofNullable(currentApimlId).orElse(serviceRegistration.getInstanceId());
List<ServiceInfo> localServices = servicesInfoService.getServicesInfo();
gatewayIndexerService.putApimlServices(currentApimlId, localServices);
gatewayIndexerService.putApimlServices(apimlIdKey, localServices);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import reactor.netty.http.client.HttpClient;
import reactor.netty.tcp.SslProvider;

import javax.validation.constraints.NotNull;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Mono<List<ServiceInfo>> indexGatewayServices(ServiceInstance registration
* @param apimlId unique apimlId
* @param services List of the services
*/
public void putApimlServices(String apimlId, List<ServiceInfo> services) {
public void putApimlServices(@NotNull String apimlId, List<ServiceInfo> services) {
apimlServicesCache.put(apimlId, services);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public class InstanceInfoService {
public Mono<List<ServiceInstance>> getServiceInstance(String serviceId) {
return discoveryClient.getInstances(serviceId).collectList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration;
import org.springframework.test.util.ReflectionTestUtils;
import org.zowe.apiml.cloudgatewayservice.service.GatewayIndexService;
import org.zowe.apiml.cloudgatewayservice.service.InstanceInfoService;
Expand Down Expand Up @@ -54,6 +55,8 @@ class GatewayScanJobTest {
@Mock
private List<ServiceInfo> apimlServicesTwo;
@Mock
private EurekaRegistration eurekaRegistration;
@Mock
private GatewayIndexService gatewayIndexerService;
@Mock
private InstanceInfoService instanceInfoService;
Expand Down

0 comments on commit 005001b

Please sign in to comment.