private List<Service> filterServices(List<Service> services, List<String> selectedIds) { if (selectedIds != null && !selectedIds.isEmpty()) { List<Service> result = new ArrayList<>(); for (Service s : services) { if (selectedIds.contains(s.getId())) { result.add(s); } } return result; } else { return services; } }
private boolean qualifies(Service s, Annotation... qualifiers) { for (Annotation annotation : qualifiers) { if (annotation instanceof ServiceName) { String id = ((ServiceName) annotation).value(); return id.equals(s.getId()); } } return false; } }
/** * Checks if there is an endpoint for the service available. * @param s The target service. * @return Returns true if a connection to at least one of the endpoints is possible. */ private boolean isEndpointAvailable(Service s) { String serviceStatus = null; boolean result = false; for (String endpoit : kubernetesClient.endpointsForService(s.getId(), s.getNamespace()).getEndpoints()) { String addr = endpoit.substring(0, endpoit.indexOf(":")); Integer port = Integer.parseInt(endpoit.substring(endpoit.indexOf(":") + 1)); try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(addr, port), configuration.getServiceConnectionTimeout()); serviceStatus = "Service: " + s.getId() + " is ready. Provider:"+ addr+"."; return true; } catch (Exception e) { serviceStatus = "Service: " + s.getId() + " is not ready! Error: " + e.getMessage(); } finally { session.getLogger().warn(serviceStatus); } } return result; }
public static void deleteServices(KubernetesClient client, Session session) throws MultiException { List<Throwable> errors = new ArrayList<>(); for (Service service : client.getServices(session.getNamespace()).getItems()) { try { session.getLogger().info("Deleting service:" + getId(service)); client.deleteService(service.getId(), session.getNamespace()); } catch (Exception e) { e.printStackTrace(); } } if (!errors.isEmpty()) { throw new MultiException("Error while deleting services", errors); } }
} else if (entity instanceof Service) { Service service = (Service) entity; log.status("Applying service:" + service.getId()); controller.applyService(service, session.getId()); conditions.put(2, servicesReady);