@Test public void testPodExists () throws ApiException { V1PodList v1PodList = getV1PodList(true); V1Pod pod = v1PodList.getItems().get(0); KubernetesPodContainer kubernetesPodContainer = platform.fromKubernetesAPIPod(pod); when(coreV1Api.listNamespacedPod(anyString(), anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString(), anyInt(), anyBoolean())).thenReturn(v1PodList) .thenReturn(new V1PodList()) .thenThrow(new ApiException(new IOException())); assertTrue("POD exists", platform.podExists(kubernetesPodContainer).orElseThrow()); assertFalse("POD does not exist", platform.podExists(kubernetesPodContainer).orElseThrow()); assertTrue("IO Exception", platform.podExists(kubernetesPodContainer).isEmpty()); }
Optional<Boolean> podExists (KubernetesPodContainer kubernetesPodContainer) { String podUuid = kubernetesPodContainer.getUuid(); if (podUuid == null) return Optional.empty(); try { Boolean podExists = listAllPodsInNamespace().getItems() .stream() .map(V1Pod::getMetadata) .filter(Objects::nonNull) .map(V1ObjectMeta::getUid) .anyMatch(podUuid::equals); log.debug("Kubernetes POD {} exists = {}", kubernetesPodContainer.getPodName(), podExists); return Optional.of(podExists); } catch (ApiException e) { log.debug("Exception when checking container existence", e); return Optional.empty(); } }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { Optional<Boolean> podExists (KubernetesPodContainer kubernetesPodContainer) { String podUuid = kubernetesPodContainer.getUuid(); if (podUuid == null) return Optional.empty(); try { Boolean podExists = listAllPodsInNamespace().getItems() .stream() .map(V1Pod::getMetadata) .filter(Objects::nonNull) .map(V1ObjectMeta::getUid) .anyMatch(podUuid::equals); log.debug("Kubernetes POD {} exists = {}", kubernetesPodContainer.getPodName(), podExists); return Optional.of(podExists); } catch (ApiException e) { log.debug("Exception when checking container existence", e); return Optional.empty(); } } }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { Optional<Boolean> podExists (KubernetesPodContainer kubernetesPodContainer) { String podUuid = kubernetesPodContainer.getUuid(); if (podUuid == null) return Optional.empty(); try { Boolean podExists = listAllPodsInNamespace().getItems() .stream() .map(V1Pod::getMetadata) .filter(Objects::nonNull) .map(V1ObjectMeta::getUid) .anyMatch(podUuid::equals); log.debug("Kubernetes POD {} exists = {}", kubernetesPodContainer.getPodName(), podExists); return Optional.of(podExists); } catch (ApiException e) { log.debug("Exception when checking container existence", e); return Optional.empty(); } } @Autowired  KubernetesPlatform(ApiClient apiClient); }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { Optional<Boolean> podExists (KubernetesPodContainer kubernetesPodContainer) { String podUuid = kubernetesPodContainer.getUuid(); if (podUuid == null) return Optional.empty(); try { Boolean podExists = listAllPodsInNamespace().getItems() .stream() .map(V1Pod::getMetadata) .filter(Objects::nonNull) .map(V1ObjectMeta::getUid) .anyMatch(podUuid::equals); log.debug("Kubernetes POD {} exists = {}", kubernetesPodContainer.getPodName(), podExists); return Optional.of(podExists); } catch (ApiException e) { log.debug("Exception when checking container existence", e); return Optional.empty(); } } @Autowired  KubernetesPlatform(ApiClient apiClient); String getNamespace(); void setNamespace(String namespace); ContainerHealth checkHealth(KubernetesPodContainer kubernetesPodContainer); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override boolean isContainerRecycled(Container container); ContainerHealth replicaSetRecovered(KubernetesPodContainer kubernetesPodContainer); boolean isDesiredReplicas(KubernetesPodContainer instance); @Override void recycleContainer(KubernetesPodContainer container); boolean deletePod(KubernetesPodContainer instance); @Override ShellClient getConnectedShellClient(KubernetesPodContainer container); }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { Optional<Boolean> podExists (KubernetesPodContainer kubernetesPodContainer) { String podUuid = kubernetesPodContainer.getUuid(); if (podUuid == null) return Optional.empty(); try { Boolean podExists = listAllPodsInNamespace().getItems() .stream() .map(V1Pod::getMetadata) .filter(Objects::nonNull) .map(V1ObjectMeta::getUid) .anyMatch(podUuid::equals); log.debug("Kubernetes POD {} exists = {}", kubernetesPodContainer.getPodName(), podExists); return Optional.of(podExists); } catch (ApiException e) { log.debug("Exception when checking container existence", e); return Optional.empty(); } } @Autowired  KubernetesPlatform(ApiClient apiClient); String getNamespace(); void setNamespace(String namespace); ContainerHealth checkHealth(KubernetesPodContainer kubernetesPodContainer); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override boolean isContainerRecycled(Container container); ContainerHealth replicaSetRecovered(KubernetesPodContainer kubernetesPodContainer); boolean isDesiredReplicas(KubernetesPodContainer instance); @Override void recycleContainer(KubernetesPodContainer container); boolean deletePod(KubernetesPodContainer instance); @Override ShellClient getConnectedShellClient(KubernetesPodContainer container);  }