Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public static List<Pod> findPods(KubernetesClient client, Filter<Pod> filter)
     throws MultiException {
   List<Pod> pods = new ArrayList<>();
   for (Pod pod : client.getPods().getItems()) {
     if (filter.matches(pod)) {
       pods.add(pod);
     }
   }
   return pods;
 }
Esempio n. 3
0
 public static List<ReplicationController> findReplicationControllers(
     KubernetesClient client, Filter<ReplicationController> filter) throws MultiException {
   List<ReplicationController> replicationControllers = new ArrayList<>();
   for (ReplicationController replicationController :
       client.getReplicationControllers().getItems()) {
     if (filter.matches(replicationController)) {
       replicationControllers.add(replicationController);
     }
   }
   return replicationControllers;
 }
Esempio n. 4
0
  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));
      }
    }
  }
Esempio n. 5
0
 @Override
 public void entityChanged(String podId, Pod pod) {
   if (filter.matches(pod)) {
     try {
       List<ContainerService> services = new ArrayList<>();
       for (ServicePort port : servicePorts) {
         ContainerService containerService = new ContainerService(port, pod);
         services.add(containerService);
       }
       containerServices.replaceValues(podId, services);
     } catch (Exception e) {
       LOG.info("Ignored bad pod: " + podId + ". " + e, e);
     }
   }
 }
Esempio n. 6
0
 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);
   }
 }
Esempio n. 7
0
 public static void deletePods(KubernetesClient client, Logger logger, Filter<Pod> filter)
     throws MultiException {
   List<Throwable> errors = new ArrayList<>();
   for (Pod pod : client.getPods().getItems()) {
     if (filter.matches(pod)) {
       try {
         logger.info("Deleting pod:" + getId(pod));
         client.deletePod(getId(pod));
       } catch (Exception e) {
         errors.add(e);
       }
     }
   }
   if (!errors.isEmpty()) {
     throw new MultiException("Error while deleting pods", errors);
   }
 }
Esempio n. 8
0
  public static void deleteReplicationControllers(
      KubernetesClient client, Logger logger, Filter<ReplicationController> filter)
      throws MultiException {
    List<Throwable> errors = new ArrayList<>();
    for (ReplicationController replicationController :
        client.getReplicationControllers().getItems()) {
      if (filter.matches(replicationController)) {
        try {
          logger.info("Deleting replication controller:" + getId(replicationController));
          client.deleteReplicationController(getId(replicationController));
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

    if (!errors.isEmpty()) {
      throw new MultiException("Error while deleting replication controllers", errors);
    }
  }