Source:
public Map<String, ? extends Server> getServers() { try (OpenShiftClient client = clientFactory.create()) { List<Service> services = client.services() .inNamespace(projectName) .list() .getItems(); List<Service> matchedServices = new ArrayList<>(); for (Service service : services) { if (isMachineExposedByService(service)) { matchedServices.add(service); } } Container cointaner = getCointaner(); ArrayListMultimap<String, ServicePort> matchedServicesPorts = ArrayListMultimap.create(); for (ContainerPort containerPort : cointaner.getPorts()) { Integer port = containerPort.getContainerPort(); for (Service service : matchedServices) { for (ServicePort servicePort : service.getSpec().getPorts()) { if (port.equals(servicePort.getPort())) { matchedServicesPorts.put(service.getMetadata().getName(), servicePort); } } } } List<Route> routes = client.routes() .inNamespace(projectName) .list() .getItems(); Map<String, ServerImpl> servers = new HashMap<>(); for (Route route : routes) { String serviceName = route.getSpec().getTo().getName(); List<ServicePort> servicePorts = matchedServicesPorts.get(serviceName); if (servicePorts != null) { RoutePort routePort = route.getSpec().getPort(); for (ServicePort servicePort : servicePorts) { String portReference = routePort.getTargetPort().getStrVal(); if (portReference != null) { if (portReference.equals(servicePort.getName())) { servers.put(portReference, new ServerImpl("http://" + route.getSpec().getHost(), ServerStatus.UNKNOWN)); } continue; } Integer portNumber = routePort.getTargetPort().getIntVal(); if (portNumber != null) { if (portNumber.equals(servicePort.getPort())) { servers.put(Integer.toString(portNumber), new ServerImpl("http://" + route.getSpec().getHost(), ServerStatus.UNKNOWN)); } continue; } } } } return servers; } }

Target:
public Map<String, ? extends Server> getServers() { try (OpenShiftClient client = clientFactory.create()) { List<Service> matchedServices = client.services() .inNamespace(projectName) .list() .getItems() .stream() .filter(this::isMachineExposedByService) .collect(Collectors.toList()); Container cointaner = getContainer(); ArrayListMultimap<String, ServicePort> matchedServicesPorts = ArrayListMultimap.create(); for (ContainerPort containerPort : cointaner.getPorts()) { Integer port = containerPort.getContainerPort(); for (Service service : matchedServices) { for (ServicePort servicePort : service.getSpec().getPorts()) { if (port.equals(servicePort.getPort())) { matchedServicesPorts.put(service.getMetadata().getName(), servicePort); } } } } List<Route> routes = client.routes() .inNamespace(projectName) .list() .getItems(); Map<String, ServerImpl> servers = new HashMap<>(); for (Route route : routes) { String serviceName = route.getSpec().getTo().getName(); List<ServicePort> servicePorts = matchedServicesPorts.get(serviceName); if (servicePorts != null) { RoutePort routePort = route.getSpec().getPort(); for (ServicePort servicePort : servicePorts) { String portReference = routePort.getTargetPort().getStrVal(); if (portReference != null) { if (portReference.equals(servicePort.getName())) { servers.put(portReference, new ServerImpl("http://" + route.getSpec().getHost(), ServerStatus.UNKNOWN)); } continue; } Integer portNumber = routePort.getTargetPort().getIntVal(); if (portNumber != null) { if (portNumber.equals(servicePort.getPort())) { servers.put(Integer.toString(portNumber), new ServerImpl("http://" + route.getSpec().getHost(), ServerStatus.UNKNOWN)); } continue; } } } } return servers; } }