@Test public void testBadPodFetch() throws KeyManagementException, ClientProtocolException, NoSuchAlgorithmException, KeyStoreException, MalformedURLException, IOException { registerBadResponse(); KubeConfig kubeConfig = new KubeConfig(); KubeService kubeService = new KubeService(kubeConfig); Set<String> fetchPodIdsFromMetadata = kubeService.fetchPodNamesFromMetadata(); assertEquals(0, fetchPodIdsFromMetadata.size()); }
public Set<String> fetchPodNamesFromMetadata() throws IOException { LOG.debug("Attempting to make pod md request"); String response = SingerUtils.makeGetRequest(PODS_MD_URL); LOG.debug("Received pod md response:" + response); Gson gson = new Gson(); JsonObject obj = gson.fromJson(response, JsonObject.class); LOG.debug("Finished parsing kubelet response for PODs; now extracting POD names"); Set<String> podNames = new HashSet<>(); if (obj != null && obj.has("items")) { JsonArray ary = obj.get("items").getAsJsonArray(); for (int i = 0; i < ary.size(); i++) { JsonObject metadata = ary.get(i).getAsJsonObject().get("metadata").getAsJsonObject(); String name = metadata.get("name").getAsString(); podNames.add(name); String namespace = metadata.get("namespace").getAsString(); podNames.add(namespace + "_" + name); LOG.debug("Found active POD name in JSON:" + name); } } LOG.debug("Pod names from kubelet:" + podNames); return podNames; }
KubeService implements Runnable { public Set<String> fetchPodNamesFromMetadata() throws IOException { LOG.debug("Attempting to make pod md request"); String response = SingerUtils.makeGetRequest(PODS_MD_URL); LOG.debug("Received pod md response:" + response); Gson gson = new Gson(); JsonObject obj = gson.fromJson(response, JsonObject.class); LOG.debug("Finished parsing kubelet response for PODs; now extracting POD names"); Set<String> podNames = new HashSet<>(); if (obj != null && obj.has("items")) { JsonArray ary = obj.get("items").getAsJsonArray(); for (int i = 0; i < ary.size(); i++) { JsonObject metadata = ary.get(i).getAsJsonObject().get("metadata").getAsJsonObject(); String name = metadata.get("name").getAsString(); podNames.add(name); String namespace = metadata.get("namespace").getAsString(); podNames.add(namespace + "_" + name); LOG.debug("Found active POD name in JSON:" + name); } } LOG.debug("Pod names from kubelet:" + podNames); return podNames; } }
KubeService implements Runnable { public Set<String> fetchPodNamesFromMetadata() throws IOException { LOG.debug("Attempting to make pod md request"); String response = SingerUtils.makeGetRequest(PODS_MD_URL); LOG.debug("Received pod md response:" + response); Gson gson = new Gson(); JsonObject obj = gson.fromJson(response, JsonObject.class); LOG.debug("Finished parsing kubelet response for PODs; now extracting POD names"); Set<String> podNames = new HashSet<>(); if (obj != null && obj.has("items")) { JsonArray ary = obj.get("items").getAsJsonArray(); for (int i = 0; i < ary.size(); i++) { JsonObject metadata = ary.get(i).getAsJsonObject().get("metadata").getAsJsonObject(); String name = metadata.get("name").getAsString(); podNames.add(name); String namespace = metadata.get("namespace").getAsString(); podNames.add(namespace + "_" + name); LOG.debug("Found active POD name in JSON:" + name); } } LOG.debug("Pod names from kubelet:" + podNames); return podNames; } private  KubeService(); @VisibleForTesting protected  KubeService(KubeConfig kubeConfig); }
KubeService implements Runnable { public Set<String> fetchPodNamesFromMetadata() throws IOException { LOG.debug("Attempting to make pod md request"); String response = SingerUtils.makeGetRequest(PODS_MD_URL); LOG.debug("Received pod md response:" + response); Gson gson = new Gson(); JsonObject obj = gson.fromJson(response, JsonObject.class); LOG.debug("Finished parsing kubelet response for PODs; now extracting POD names"); Set<String> podNames = new HashSet<>(); if (obj != null && obj.has("items")) { JsonArray ary = obj.get("items").getAsJsonArray(); for (int i = 0; i < ary.size(); i++) { JsonObject metadata = ary.get(i).getAsJsonObject().get("metadata").getAsJsonObject(); String name = metadata.get("name").getAsString(); podNames.add(name); String namespace = metadata.get("namespace").getAsString(); podNames.add(namespace + "_" + name); LOG.debug("Found active POD name in JSON:" + name); } } LOG.debug("Pod names from kubelet:" + podNames); return podNames; } private  KubeService(); @VisibleForTesting protected  KubeService(KubeConfig kubeConfig); synchronized static KubeService getInstance(); @Override void run(); void updatePodNames(); void updatePodWatchers(String podName, boolean isDelete); Set<String> fetchPodNamesFromMetadata(); int getPollFrequency(); Set<String> getActivePodSet(); synchronized void addWatcher(PodWatcher watcher); synchronized void removeWatcher(PodWatcher watcher); void start(); void stop(); void checkAndProcessFsEvents(); static void reset(); }
KubeService implements Runnable { public Set<String> fetchPodNamesFromMetadata() throws IOException { LOG.debug("Attempting to make pod md request"); String response = SingerUtils.makeGetRequest(PODS_MD_URL); LOG.debug("Received pod md response:" + response); Gson gson = new Gson(); JsonObject obj = gson.fromJson(response, JsonObject.class); LOG.debug("Finished parsing kubelet response for PODs; now extracting POD names"); Set<String> podNames = new HashSet<>(); if (obj != null && obj.has("items")) { JsonArray ary = obj.get("items").getAsJsonArray(); for (int i = 0; i < ary.size(); i++) { JsonObject metadata = ary.get(i).getAsJsonObject().get("metadata").getAsJsonObject(); String name = metadata.get("name").getAsString(); podNames.add(name); String namespace = metadata.get("namespace").getAsString(); podNames.add(namespace + "_" + name); LOG.debug("Found active POD name in JSON:" + name); } } LOG.debug("Pod names from kubelet:" + podNames); return podNames; } private  KubeService(); @VisibleForTesting protected  KubeService(KubeConfig kubeConfig); synchronized static KubeService getInstance(); @Override void run(); void updatePodNames(); void updatePodWatchers(String podName, boolean isDelete); Set<String> fetchPodNamesFromMetadata(); int getPollFrequency(); Set<String> getActivePodSet(); synchronized void addWatcher(PodWatcher watcher); synchronized void removeWatcher(PodWatcher watcher); void start(); void stop(); void checkAndProcessFsEvents(); static void reset();  }