Search in sources :

Example 1 with KubernetesClusterStopWorker

use of com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterStopWorker in project cloudstack by apache.

the class KubernetesClusterManagerImpl method stopKubernetesCluster.

@Override
public boolean stopKubernetesCluster(long kubernetesClusterId) throws CloudRuntimeException {
    if (!KubernetesServiceEnabled.value()) {
        logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled");
    }
    final KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(kubernetesClusterId);
    if (kubernetesCluster == null) {
        throw new InvalidParameterValueException("Failed to find Kubernetes cluster with given ID");
    }
    if (kubernetesCluster.getRemoved() != null) {
        throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s is already deleted", kubernetesCluster.getName()));
    }
    accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.OperateEntry, false, kubernetesCluster);
    if (kubernetesCluster.getState().equals(KubernetesCluster.State.Stopped)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(String.format("Kubernetes cluster : %s is already stopped", kubernetesCluster.getName()));
        }
        return true;
    }
    if (kubernetesCluster.getState().equals(KubernetesCluster.State.Stopping)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(String.format("Kubernetes cluster : %s is getting stopped", kubernetesCluster.getName()));
        }
        return true;
    }
    KubernetesClusterStopWorker stopWorker = new KubernetesClusterStopWorker(kubernetesCluster, this);
    stopWorker = ComponentContext.inject(stopWorker);
    return stopWorker.stop();
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) KubernetesClusterStopWorker(com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterStopWorker)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 KubernetesClusterStopWorker (com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterStopWorker)1