@Override public List<Service> getServices() throws KubernetesClientException { try { return kubernetesClient.getServices().getItems(); } catch (Exception e) { String msg = "Could not retrieve kubernetes services"; log.error(msg, e); throw new KubernetesClientException(msg, e); } }
public static List<Service> findServices(KubernetesClient client, Filter<Service> filter) throws MultiException { List<Service> services = new ArrayList<>(); for (Service service : client.getServices().getItems()) { if (filter.matches(service)) { services.add(service); } } return services; }
public static void deleteServices(KubernetesClient client, Logger logger, Filter<Service> filter) throws MultiException { List<Throwable> errors = new ArrayList<>(); for (Service service : client.getServices().getItems()) { if (filter.matches(service)) { try { logger.info("Deleting service:" + getId(service)); client.deleteService(getId(service)); } catch (Exception e) { e.printStackTrace(); } } } if (!errors.isEmpty()) { throw new MultiException("Error while deleting services", errors); } }
public static void displaySessionStatus(KubernetesClient client, Session session) throws MultiException { Map<String, String> labels = Collections.singletonMap(Constants.ARQ_KEY, session.getId()); Filter<Pod> podFilter = KubernetesHelper.createPodFilter(labels); Filter<Service> serviceFilter = KubernetesHelper.createServiceFilter(labels); Filter<ReplicationController> replicationControllerFilter = KubernetesHelper.createReplicationControllerFilter(labels); for (ReplicationController replicationController : client.getReplicationControllers().getItems()) { if (replicationControllerFilter.matches(replicationController)) { session.getLogger().info("Replication controller:" + getId(replicationController)); } } for (Pod pod : client.getPods().getItems()) { if (podFilter.matches(pod)) { session .getLogger() .info("Pod:" + getId(pod) + " Status:" + pod.getCurrentState().getStatus()); } } for (Service service : client.getServices().getItems()) { if (serviceFilter.matches(service)) { session .getLogger() .info( "Service:" + getId(service) + " IP:" + getPortalIP(service) + " Port:" + getPort(service)); } } }