@Test public void testContainerHealthWithSeveralContainerOneUnhealthy () throws ApiException { V1PodStatus status = new V1PodStatusBuilder().addNewContainerStatus() .withReady(true) .endContainerStatus() .addNewContainerStatus() .withReady(false) .endContainerStatus() .addNewContainerStatus() .withReady(true) .endContainerStatus() .build(); assertEquals(3, status.getContainerStatuses().size()); V1Pod pod = getV1PodList(true).getItems().get(0); pod.setStatus(status); when(coreV1Api.listNamespacedPod(anyString(), anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString(), anyInt(), anyBoolean())).thenReturn(getV1PodList(true)); when(coreV1Api.readNamespacedPodStatus(any(), any(), any())).thenReturn(pod); assertEquals(ContainerHealth.RUNNING_EXPERIMENT, platform.checkHealth((KubernetesPodContainer) platform.getRoster().get(0))); }
public ContainerHealth checkHealth (KubernetesPodContainer kubernetesPodContainer) { try { Optional<Boolean> podExists = podExists(kubernetesPodContainer); if (podExists.isEmpty()) { return ContainerHealth.RUNNING_EXPERIMENT; } else if (!podExists.get()) { return ContainerHealth.DOES_NOT_EXIST; } V1Pod result = getCoreV1Api().readNamespacedPodStatus(kubernetesPodContainer.getPodName(), kubernetesPodContainer.getNamespace(), "true"); return Optional.ofNullable(result) .map(V1Pod::getStatus) .map(V1PodStatus::getContainerStatuses) .map(Collection::stream) .map(s -> s.allMatch(V1ContainerStatus::getReady)) .map(aBoolean -> aBoolean ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT) .orElse(ContainerHealth.DOES_NOT_EXIST); } catch (ApiException e) { log.debug("Exception when checking container health", e); if (HttpStatus.SC_NOT_FOUND == e.getCode()) { return ContainerHealth.DOES_NOT_EXIST; } } return ContainerHealth.RUNNING_EXPERIMENT; }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { public ContainerHealth checkHealth (KubernetesPodContainer kubernetesPodContainer) { try { Optional<Boolean> podExists = podExists(kubernetesPodContainer); if (podExists.isEmpty()) { return ContainerHealth.RUNNING_EXPERIMENT; } else if (!podExists.get()) { return ContainerHealth.DOES_NOT_EXIST; } V1Pod result = getCoreV1Api().readNamespacedPodStatus(kubernetesPodContainer.getPodName(), kubernetesPodContainer.getNamespace(), "true"); return Optional.ofNullable(result) .map(V1Pod::getStatus) .map(V1PodStatus::getContainerStatuses) .map(Collection::stream) .map(s -> s.allMatch(V1ContainerStatus::getReady)) .map(aBoolean -> aBoolean ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT) .orElse(ContainerHealth.DOES_NOT_EXIST); } catch (ApiException e) { log.debug("Exception when checking container health", e); if (HttpStatus.SC_NOT_FOUND == e.getCode()) { return ContainerHealth.DOES_NOT_EXIST; } } return ContainerHealth.RUNNING_EXPERIMENT; } }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { public ContainerHealth checkHealth (KubernetesPodContainer kubernetesPodContainer) { try { Optional<Boolean> podExists = podExists(kubernetesPodContainer); if (podExists.isEmpty()) { return ContainerHealth.RUNNING_EXPERIMENT; } else if (!podExists.get()) { return ContainerHealth.DOES_NOT_EXIST; } V1Pod result = getCoreV1Api().readNamespacedPodStatus(kubernetesPodContainer.getPodName(), kubernetesPodContainer.getNamespace(), "true"); return Optional.ofNullable(result) .map(V1Pod::getStatus) .map(V1PodStatus::getContainerStatuses) .map(Collection::stream) .map(s -> s.allMatch(V1ContainerStatus::getReady)) .map(aBoolean -> aBoolean ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT) .orElse(ContainerHealth.DOES_NOT_EXIST); } catch (ApiException e) { log.debug("Exception when checking container health", e); if (HttpStatus.SC_NOT_FOUND == e.getCode()) { return ContainerHealth.DOES_NOT_EXIST; } } return ContainerHealth.RUNNING_EXPERIMENT; } @Autowired  KubernetesPlatform(ApiClient apiClient); }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { public ContainerHealth checkHealth (KubernetesPodContainer kubernetesPodContainer) { try { Optional<Boolean> podExists = podExists(kubernetesPodContainer); if (podExists.isEmpty()) { return ContainerHealth.RUNNING_EXPERIMENT; } else if (!podExists.get()) { return ContainerHealth.DOES_NOT_EXIST; } V1Pod result = getCoreV1Api().readNamespacedPodStatus(kubernetesPodContainer.getPodName(), kubernetesPodContainer.getNamespace(), "true"); return Optional.ofNullable(result) .map(V1Pod::getStatus) .map(V1PodStatus::getContainerStatuses) .map(Collection::stream) .map(s -> s.allMatch(V1ContainerStatus::getReady)) .map(aBoolean -> aBoolean ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT) .orElse(ContainerHealth.DOES_NOT_EXIST); } catch (ApiException e) { log.debug("Exception when checking container health", e); if (HttpStatus.SC_NOT_FOUND == e.getCode()) { return ContainerHealth.DOES_NOT_EXIST; } } return ContainerHealth.RUNNING_EXPERIMENT; } @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> { public ContainerHealth checkHealth (KubernetesPodContainer kubernetesPodContainer) { try { Optional<Boolean> podExists = podExists(kubernetesPodContainer); if (podExists.isEmpty()) { return ContainerHealth.RUNNING_EXPERIMENT; } else if (!podExists.get()) { return ContainerHealth.DOES_NOT_EXIST; } V1Pod result = getCoreV1Api().readNamespacedPodStatus(kubernetesPodContainer.getPodName(), kubernetesPodContainer.getNamespace(), "true"); return Optional.ofNullable(result) .map(V1Pod::getStatus) .map(V1PodStatus::getContainerStatuses) .map(Collection::stream) .map(s -> s.allMatch(V1ContainerStatus::getReady)) .map(aBoolean -> aBoolean ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT) .orElse(ContainerHealth.DOES_NOT_EXIST); } catch (ApiException e) { log.debug("Exception when checking container health", e); if (HttpStatus.SC_NOT_FOUND == e.getCode()) { return ContainerHealth.DOES_NOT_EXIST; } } return ContainerHealth.RUNNING_EXPERIMENT; } @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);  }