示例#1
0
文件: Util.java 项目: pires/fabric8
 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;
 }
示例#2
0
文件: Util.java 项目: pires/fabric8
 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;
 }
示例#3
0
文件: Util.java 项目: pires/fabric8
 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;
 }
示例#4
0
文件: Util.java 项目: pires/fabric8
  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));
      }
    }
  }
示例#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);
     }
   }
 }
示例#6
0
文件: Util.java 项目: pires/fabric8
 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);
   }
 }
示例#7
0
文件: Util.java 项目: pires/fabric8
 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);
   }
 }
示例#8
0
文件: Util.java 项目: pires/fabric8
  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);
    }
  }