@Test public void testCheckDesiredReplicasUnsupportedKind () throws ApiException { V1PodList pods = getV1PodList(true); when(coreV1Api.listNamespacedPod(anyString(), anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString(), anyInt(), anyBoolean())).thenReturn(pods); pods.getItems().get(0).getMetadata().getOwnerReferences().get(0).setKind("Unsupported"); pods.getItems().get(0).getMetadata().getOwnerReferences().get(0).setName("dummy"); assertFalse(platform.isDesiredReplicas((KubernetesPodContainer) platform.getRoster().get(0))); }
public boolean isDesiredReplicas (KubernetesPodContainer instance) { try { switch (instance.getOwnerKind()) { case REPLICATION_CONTROLLER: V1ReplicationController rc = getCoreV1Api().readNamespacedReplicationControllerStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicationControllerStatus> controllerStatus = Optional.of(rc) .map(V1ReplicationController::getStatus); return controllerStatus.map(V1ReplicationControllerStatus::getReplicas) .equals(controllerStatus.map(V1ReplicationControllerStatus::getReadyReplicas)); case REPLICA_SET: V1ReplicaSet replicaSet = getAppsV1Api().readNamespacedReplicaSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicaSetStatus> replicaSetStatus = Optional.of(replicaSet) .map(V1ReplicaSet::getStatus); return replicaSetStatus.map(V1ReplicaSetStatus::getReplicas) .equals(replicaSetStatus.map(V1ReplicaSetStatus::getReadyReplicas)); case STATEFUL_SET: V1StatefulSet statefulSet = getAppsV1Api().readNamespacedStatefulSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1StatefulSetStatus> statefulSetStatus = Optional.of(statefulSet) .map(V1StatefulSet::getStatus); return statefulSetStatus.map(V1StatefulSetStatus::getReplicas) .equals(statefulSetStatus.map(V1StatefulSetStatus::getReadyReplicas)); case DAEMON_SET: V1DaemonSet daemonSet = getAppsV1Api().readNamespacedDaemonSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DaemonSetStatus> daemonSetStatus = Optional.of(daemonSet).map(V1DaemonSet::getStatus); return daemonSetStatus.map(V1DaemonSetStatus::getCurrentNumberScheduled) .equals(daemonSetStatus.map(V1DaemonSetStatus::getDesiredNumberScheduled)); case DEPLOYMENT: V1Deployment deployment = getAppsV1Api().readNamespacedDeploymentStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DeploymentStatus> deploymentStatus = Optional.of(deployment) .map(V1Deployment::getStatus); return deploymentStatus.map(V1DeploymentStatus::getReplicas) .equals(deploymentStatus.map(V1DeploymentStatus::getReadyReplicas)); case JOB: case CRON_JOB: log.warn("Job containers are not supported"); return false; default: log.error("Unsupported owner type"); return false; } } catch (ApiException e) { log.error("ApiException was thrown while checking desired replica count.", e); return false; } }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { public boolean isDesiredReplicas (KubernetesPodContainer instance) { try { switch (instance.getOwnerKind()) { case REPLICATION_CONTROLLER: V1ReplicationController rc = getCoreV1Api().readNamespacedReplicationControllerStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicationControllerStatus> controllerStatus = Optional.of(rc) .map(V1ReplicationController::getStatus); return controllerStatus.map(V1ReplicationControllerStatus::getReplicas) .equals(controllerStatus.map(V1ReplicationControllerStatus::getReadyReplicas)); case REPLICA_SET: V1ReplicaSet replicaSet = getAppsV1Api().readNamespacedReplicaSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicaSetStatus> replicaSetStatus = Optional.of(replicaSet) .map(V1ReplicaSet::getStatus); return replicaSetStatus.map(V1ReplicaSetStatus::getReplicas) .equals(replicaSetStatus.map(V1ReplicaSetStatus::getReadyReplicas)); case STATEFUL_SET: V1StatefulSet statefulSet = getAppsV1Api().readNamespacedStatefulSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1StatefulSetStatus> statefulSetStatus = Optional.of(statefulSet) .map(V1StatefulSet::getStatus); return statefulSetStatus.map(V1StatefulSetStatus::getReplicas) .equals(statefulSetStatus.map(V1StatefulSetStatus::getReadyReplicas)); case DAEMON_SET: V1DaemonSet daemonSet = getAppsV1Api().readNamespacedDaemonSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DaemonSetStatus> daemonSetStatus = Optional.of(daemonSet).map(V1DaemonSet::getStatus); return daemonSetStatus.map(V1DaemonSetStatus::getCurrentNumberScheduled) .equals(daemonSetStatus.map(V1DaemonSetStatus::getDesiredNumberScheduled)); case DEPLOYMENT: V1Deployment deployment = getAppsV1Api().readNamespacedDeploymentStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DeploymentStatus> deploymentStatus = Optional.of(deployment) .map(V1Deployment::getStatus); return deploymentStatus.map(V1DeploymentStatus::getReplicas) .equals(deploymentStatus.map(V1DeploymentStatus::getReadyReplicas)); case JOB: case CRON_JOB: log.warn("Job containers are not supported"); return false; default: log.error("Unsupported owner type"); return false; } } catch (ApiException e) { log.error("ApiException was thrown while checking desired replica count.", e); return false; } } }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { public boolean isDesiredReplicas (KubernetesPodContainer instance) { try { switch (instance.getOwnerKind()) { case REPLICATION_CONTROLLER: V1ReplicationController rc = getCoreV1Api().readNamespacedReplicationControllerStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicationControllerStatus> controllerStatus = Optional.of(rc) .map(V1ReplicationController::getStatus); return controllerStatus.map(V1ReplicationControllerStatus::getReplicas) .equals(controllerStatus.map(V1ReplicationControllerStatus::getReadyReplicas)); case REPLICA_SET: V1ReplicaSet replicaSet = getAppsV1Api().readNamespacedReplicaSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicaSetStatus> replicaSetStatus = Optional.of(replicaSet) .map(V1ReplicaSet::getStatus); return replicaSetStatus.map(V1ReplicaSetStatus::getReplicas) .equals(replicaSetStatus.map(V1ReplicaSetStatus::getReadyReplicas)); case STATEFUL_SET: V1StatefulSet statefulSet = getAppsV1Api().readNamespacedStatefulSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1StatefulSetStatus> statefulSetStatus = Optional.of(statefulSet) .map(V1StatefulSet::getStatus); return statefulSetStatus.map(V1StatefulSetStatus::getReplicas) .equals(statefulSetStatus.map(V1StatefulSetStatus::getReadyReplicas)); case DAEMON_SET: V1DaemonSet daemonSet = getAppsV1Api().readNamespacedDaemonSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DaemonSetStatus> daemonSetStatus = Optional.of(daemonSet).map(V1DaemonSet::getStatus); return daemonSetStatus.map(V1DaemonSetStatus::getCurrentNumberScheduled) .equals(daemonSetStatus.map(V1DaemonSetStatus::getDesiredNumberScheduled)); case DEPLOYMENT: V1Deployment deployment = getAppsV1Api().readNamespacedDeploymentStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DeploymentStatus> deploymentStatus = Optional.of(deployment) .map(V1Deployment::getStatus); return deploymentStatus.map(V1DeploymentStatus::getReplicas) .equals(deploymentStatus.map(V1DeploymentStatus::getReadyReplicas)); case JOB: case CRON_JOB: log.warn("Job containers are not supported"); return false; default: log.error("Unsupported owner type"); return false; } } catch (ApiException e) { log.error("ApiException was thrown while checking desired replica count.", e); return false; } } @Autowired  KubernetesPlatform(ApiClient apiClient); }
KubernetesPlatform extends Platform implements ShellBasedExperiment<KubernetesPodContainer> { public boolean isDesiredReplicas (KubernetesPodContainer instance) { try { switch (instance.getOwnerKind()) { case REPLICATION_CONTROLLER: V1ReplicationController rc = getCoreV1Api().readNamespacedReplicationControllerStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicationControllerStatus> controllerStatus = Optional.of(rc) .map(V1ReplicationController::getStatus); return controllerStatus.map(V1ReplicationControllerStatus::getReplicas) .equals(controllerStatus.map(V1ReplicationControllerStatus::getReadyReplicas)); case REPLICA_SET: V1ReplicaSet replicaSet = getAppsV1Api().readNamespacedReplicaSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicaSetStatus> replicaSetStatus = Optional.of(replicaSet) .map(V1ReplicaSet::getStatus); return replicaSetStatus.map(V1ReplicaSetStatus::getReplicas) .equals(replicaSetStatus.map(V1ReplicaSetStatus::getReadyReplicas)); case STATEFUL_SET: V1StatefulSet statefulSet = getAppsV1Api().readNamespacedStatefulSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1StatefulSetStatus> statefulSetStatus = Optional.of(statefulSet) .map(V1StatefulSet::getStatus); return statefulSetStatus.map(V1StatefulSetStatus::getReplicas) .equals(statefulSetStatus.map(V1StatefulSetStatus::getReadyReplicas)); case DAEMON_SET: V1DaemonSet daemonSet = getAppsV1Api().readNamespacedDaemonSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DaemonSetStatus> daemonSetStatus = Optional.of(daemonSet).map(V1DaemonSet::getStatus); return daemonSetStatus.map(V1DaemonSetStatus::getCurrentNumberScheduled) .equals(daemonSetStatus.map(V1DaemonSetStatus::getDesiredNumberScheduled)); case DEPLOYMENT: V1Deployment deployment = getAppsV1Api().readNamespacedDeploymentStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DeploymentStatus> deploymentStatus = Optional.of(deployment) .map(V1Deployment::getStatus); return deploymentStatus.map(V1DeploymentStatus::getReplicas) .equals(deploymentStatus.map(V1DeploymentStatus::getReadyReplicas)); case JOB: case CRON_JOB: log.warn("Job containers are not supported"); return false; default: log.error("Unsupported owner type"); return false; } } catch (ApiException e) { log.error("ApiException was thrown while checking desired replica count.", e); return false; } } @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 boolean isDesiredReplicas (KubernetesPodContainer instance) { try { switch (instance.getOwnerKind()) { case REPLICATION_CONTROLLER: V1ReplicationController rc = getCoreV1Api().readNamespacedReplicationControllerStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicationControllerStatus> controllerStatus = Optional.of(rc) .map(V1ReplicationController::getStatus); return controllerStatus.map(V1ReplicationControllerStatus::getReplicas) .equals(controllerStatus.map(V1ReplicationControllerStatus::getReadyReplicas)); case REPLICA_SET: V1ReplicaSet replicaSet = getAppsV1Api().readNamespacedReplicaSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1ReplicaSetStatus> replicaSetStatus = Optional.of(replicaSet) .map(V1ReplicaSet::getStatus); return replicaSetStatus.map(V1ReplicaSetStatus::getReplicas) .equals(replicaSetStatus.map(V1ReplicaSetStatus::getReadyReplicas)); case STATEFUL_SET: V1StatefulSet statefulSet = getAppsV1Api().readNamespacedStatefulSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1StatefulSetStatus> statefulSetStatus = Optional.of(statefulSet) .map(V1StatefulSet::getStatus); return statefulSetStatus.map(V1StatefulSetStatus::getReplicas) .equals(statefulSetStatus.map(V1StatefulSetStatus::getReadyReplicas)); case DAEMON_SET: V1DaemonSet daemonSet = getAppsV1Api().readNamespacedDaemonSetStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DaemonSetStatus> daemonSetStatus = Optional.of(daemonSet).map(V1DaemonSet::getStatus); return daemonSetStatus.map(V1DaemonSetStatus::getCurrentNumberScheduled) .equals(daemonSetStatus.map(V1DaemonSetStatus::getDesiredNumberScheduled)); case DEPLOYMENT: V1Deployment deployment = getAppsV1Api().readNamespacedDeploymentStatus(instance.getOwnerName(), instance.getNamespace(), "true"); Optional<V1DeploymentStatus> deploymentStatus = Optional.of(deployment) .map(V1Deployment::getStatus); return deploymentStatus.map(V1DeploymentStatus::getReplicas) .equals(deploymentStatus.map(V1DeploymentStatus::getReadyReplicas)); case JOB: case CRON_JOB: log.warn("Job containers are not supported"); return false; default: log.error("Unsupported owner type"); return false; } } catch (ApiException e) { log.error("ApiException was thrown while checking desired replica count.", e); return false; } } @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);  }