@Test public void testIsServiceReady_WhenComponentStatusHealthyConditionNotFound_ServiceNotReady() throws Exception { ComponentStatus componentStatus = newComponentStatus("other_condition", "True"); mockComponentStatus(componentStatus); boolean isServiceReady = this.api.isServiceReady(); assertFalse(isServiceReady); }
public boolean isServiceReady() throws VmidcException { boolean result = false; try { ComponentStatus status = getKubernetesClient().componentstatuses().withName(K8S_CONTROLLER_COMPONENT_NAME).get(); if (status == null) { LOG.warn(String.format("Kubernetes returned a null component for %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } if (status.getConditions() == null) { LOG.warn(String.format("Kubernetes returned null conditions for the component %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } Optional<ComponentCondition> healthyCondition = status.getConditions().stream().filter(condition -> condition.getType().equals(K8S_HEALTHY_STATUS_NAME)).findFirst(); if (!healthyCondition.isPresent()) { LOG.warn(String.format("Kubernetes did not returned a condition with name %s for the component %s. Count of returned conditions: %s.", K8S_HEALTHY_STATUS_NAME, K8S_CONTROLLER_COMPONENT_NAME, status.getConditions().size())); return result; } if (healthyCondition.get().getStatus().equals(K8S_HEALTHY_STATUS_TRUE)) { result = true; } else { LOG.warn(String.format("Kubernetes returned a health status %s for the component %s.", healthyCondition.get().getStatus(), K8S_CONTROLLER_COMPONENT_NAME)); } } catch (KubernetesClientException e) { throw new VmidcException("Failed to get the Kubernetes controller health status."); } return result; }
KubernetesStatusApi extends KubernetesApi { public boolean isServiceReady() throws VmidcException { boolean result = false; try { ComponentStatus status = getKubernetesClient().componentstatuses().withName(K8S_CONTROLLER_COMPONENT_NAME).get(); if (status == null) { LOG.warn(String.format("Kubernetes returned a null component for %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } if (status.getConditions() == null) { LOG.warn(String.format("Kubernetes returned null conditions for the component %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } Optional<ComponentCondition> healthyCondition = status.getConditions().stream().filter(condition -> condition.getType().equals(K8S_HEALTHY_STATUS_NAME)).findFirst(); if (!healthyCondition.isPresent()) { LOG.warn(String.format("Kubernetes did not returned a condition with name %s for the component %s. Count of returned conditions: %s.", K8S_HEALTHY_STATUS_NAME, K8S_CONTROLLER_COMPONENT_NAME, status.getConditions().size())); return result; } if (healthyCondition.get().getStatus().equals(K8S_HEALTHY_STATUS_TRUE)) { result = true; } else { LOG.warn(String.format("Kubernetes returned a health status %s for the component %s.", healthyCondition.get().getStatus(), K8S_CONTROLLER_COMPONENT_NAME)); } } catch (KubernetesClientException e) { throw new VmidcException("Failed to get the Kubernetes controller health status."); } return result; } }
KubernetesStatusApi extends KubernetesApi { public boolean isServiceReady() throws VmidcException { boolean result = false; try { ComponentStatus status = getKubernetesClient().componentstatuses().withName(K8S_CONTROLLER_COMPONENT_NAME).get(); if (status == null) { LOG.warn(String.format("Kubernetes returned a null component for %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } if (status.getConditions() == null) { LOG.warn(String.format("Kubernetes returned null conditions for the component %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } Optional<ComponentCondition> healthyCondition = status.getConditions().stream().filter(condition -> condition.getType().equals(K8S_HEALTHY_STATUS_NAME)).findFirst(); if (!healthyCondition.isPresent()) { LOG.warn(String.format("Kubernetes did not returned a condition with name %s for the component %s. Count of returned conditions: %s.", K8S_HEALTHY_STATUS_NAME, K8S_CONTROLLER_COMPONENT_NAME, status.getConditions().size())); return result; } if (healthyCondition.get().getStatus().equals(K8S_HEALTHY_STATUS_TRUE)) { result = true; } else { LOG.warn(String.format("Kubernetes returned a health status %s for the component %s.", healthyCondition.get().getStatus(), K8S_CONTROLLER_COMPONENT_NAME)); } } catch (KubernetesClientException e) { throw new VmidcException("Failed to get the Kubernetes controller health status."); } return result; } KubernetesStatusApi(KubernetesClient client); }
KubernetesStatusApi extends KubernetesApi { public boolean isServiceReady() throws VmidcException { boolean result = false; try { ComponentStatus status = getKubernetesClient().componentstatuses().withName(K8S_CONTROLLER_COMPONENT_NAME).get(); if (status == null) { LOG.warn(String.format("Kubernetes returned a null component for %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } if (status.getConditions() == null) { LOG.warn(String.format("Kubernetes returned null conditions for the component %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } Optional<ComponentCondition> healthyCondition = status.getConditions().stream().filter(condition -> condition.getType().equals(K8S_HEALTHY_STATUS_NAME)).findFirst(); if (!healthyCondition.isPresent()) { LOG.warn(String.format("Kubernetes did not returned a condition with name %s for the component %s. Count of returned conditions: %s.", K8S_HEALTHY_STATUS_NAME, K8S_CONTROLLER_COMPONENT_NAME, status.getConditions().size())); return result; } if (healthyCondition.get().getStatus().equals(K8S_HEALTHY_STATUS_TRUE)) { result = true; } else { LOG.warn(String.format("Kubernetes returned a health status %s for the component %s.", healthyCondition.get().getStatus(), K8S_CONTROLLER_COMPONENT_NAME)); } } catch (KubernetesClientException e) { throw new VmidcException("Failed to get the Kubernetes controller health status."); } return result; } KubernetesStatusApi(KubernetesClient client); boolean isServiceReady(); }
KubernetesStatusApi extends KubernetesApi { public boolean isServiceReady() throws VmidcException { boolean result = false; try { ComponentStatus status = getKubernetesClient().componentstatuses().withName(K8S_CONTROLLER_COMPONENT_NAME).get(); if (status == null) { LOG.warn(String.format("Kubernetes returned a null component for %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } if (status.getConditions() == null) { LOG.warn(String.format("Kubernetes returned null conditions for the component %s.", K8S_CONTROLLER_COMPONENT_NAME)); return result; } Optional<ComponentCondition> healthyCondition = status.getConditions().stream().filter(condition -> condition.getType().equals(K8S_HEALTHY_STATUS_NAME)).findFirst(); if (!healthyCondition.isPresent()) { LOG.warn(String.format("Kubernetes did not returned a condition with name %s for the component %s. Count of returned conditions: %s.", K8S_HEALTHY_STATUS_NAME, K8S_CONTROLLER_COMPONENT_NAME, status.getConditions().size())); return result; } if (healthyCondition.get().getStatus().equals(K8S_HEALTHY_STATUS_TRUE)) { result = true; } else { LOG.warn(String.format("Kubernetes returned a health status %s for the component %s.", healthyCondition.get().getStatus(), K8S_CONTROLLER_COMPONENT_NAME)); } } catch (KubernetesClientException e) { throw new VmidcException("Failed to get the Kubernetes controller health status."); } return result; } KubernetesStatusApi(KubernetesClient client); boolean isServiceReady();  }