예제 #1
0
 @Override
 public List<Pod> getPods() throws KubernetesClientException {
   try {
     return kubernetesClient.getPods().getItems();
   } catch (Exception e) {
     String msg = "Error while retrieving kubernetes pods.";
     log.error(msg, e);
     throw new KubernetesClientException(msg, e);
   }
 }
예제 #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 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);
   }
 }
예제 #4
0
파일: Util.java 프로젝트: pires/fabric8
  public static void cleanupAllMatching(
      KubernetesClient client, String key, Session session, List<Throwable> errors)
      throws MultiException {
    Map<String, String> labels = Collections.singletonMap(key, session.getId());
    Filter<Pod> podFilter = KubernetesHelper.createPodFilter(labels);
    Filter<Service> serviceFilter = KubernetesHelper.createServiceFilter(labels);
    Filter<ReplicationController> replicationControllerFilter =
        KubernetesHelper.createReplicationControllerFilter(labels);

    /** Lets use a loop to ensure we really do delete all the matching resources */
    for (int i = 0; i < 10; i++) {
      try {
        deleteReplicationControllers(client, session.getLogger(), replicationControllerFilter);
      } catch (MultiException e) {
        errors.addAll(Arrays.asList(e.getCauses()));
      }

      try {
        deletePods(client, session.getLogger(), podFilter);
      } catch (MultiException e) {
        errors.addAll(Arrays.asList(e.getCauses()));
      }

      try {
        deleteServices(client, session.getLogger(), serviceFilter);
      } catch (MultiException e) {
        errors.addAll(Arrays.asList(e.getCauses()));
      }

      // lets see if there are any matching podList left
      PodList podList = client.getPods();
      List<Pod> filteredPods = Filters.filter(notNullList(podList.getItems()), podFilter);
      if (filteredPods.isEmpty()) {
        return;
      } else {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
예제 #5
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));
      }
    }
  }