Search in sources :

Example 11 with KubernetesClusterVmMapVO

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

the class KubernetesClusterScaleWorker method removeNodesFromCluster.

private void removeNodesFromCluster(List<KubernetesClusterVmMapVO> vmMaps) throws CloudRuntimeException {
    for (KubernetesClusterVmMapVO vmMapVO : vmMaps) {
        UserVmVO userVM = userVmDao.findById(vmMapVO.getVmId());
        LOGGER.info(String.format("Removing vm : %s from cluster %s", userVM.getDisplayName(), kubernetesCluster.getName()));
        if (!removeKubernetesClusterNode(publicIpAddress, sshPort, userVM, 3, 30000)) {
            logTransitStateAndThrow(Level.ERROR, String.format("Scaling failed for Kubernetes cluster : %s, failed to remove Kubernetes node: %s running on VM : %s", kubernetesCluster.getName(), userVM.getHostName(), userVM.getDisplayName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
        }
        try {
            UserVm vm = userVmService.destroyVm(userVM.getId(), true);
            if (!userVmManager.expunge(userVM, CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount())) {
                logTransitStateAndThrow(Level.ERROR, String.format("Scaling Kubernetes cluster %s failed, unable to expunge VM '%s'.", kubernetesCluster.getName(), vm.getDisplayName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
            }
        } catch (ResourceUnavailableException e) {
            logTransitStateAndThrow(Level.ERROR, String.format("Scaling Kubernetes cluster %s failed, unable to remove VM ID: %s", kubernetesCluster.getName(), userVM.getDisplayName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed, e);
        }
        kubernetesClusterVmMapDao.expunge(vmMapVO.getId());
        if (System.currentTimeMillis() > scaleTimeoutTime) {
            logTransitStateAndThrow(Level.WARN, String.format("Scaling Kubernetes cluster %s failed, scaling action timed out", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
        }
    }
    // Scale network rules to update firewall rule
    try {
        List<Long> clusterVMIds = getKubernetesClusterVMMaps().stream().map(KubernetesClusterVmMapVO::getVmId).collect(Collectors.toList());
        scaleKubernetesClusterNetworkRules(clusterVMIds);
    } catch (ManagementServerException e) {
        logTransitStateAndThrow(Level.ERROR, String.format("Scaling failed for Kubernetes cluster : %s, unable to update network rules", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed, e);
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 12 with KubernetesClusterVmMapVO

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

the class KubernetesClusterScaleWorker method validateKubernetesClusterScaleSizeParameters.

private void validateKubernetesClusterScaleSizeParameters() throws CloudRuntimeException {
    final long originalClusterSize = kubernetesCluster.getNodeCount();
    if (network == null) {
        logTransitStateToFailedIfNeededAndThrow(Level.WARN, String.format("Scaling failed for Kubernetes cluster : %s, cluster network not found", kubernetesCluster.getName()));
    }
    // Check capacity and transition state
    final long newVmRequiredCount = clusterSize - originalClusterSize;
    final ServiceOffering clusterServiceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
    if (clusterServiceOffering == null) {
        logTransitStateToFailedIfNeededAndThrow(Level.WARN, String.format("Scaling failed for Kubernetes cluster : %s, cluster service offering not found", kubernetesCluster.getName()));
    }
    if (newVmRequiredCount > 0) {
        final DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
        try {
            if (originalState.equals(KubernetesCluster.State.Running)) {
                plan(newVmRequiredCount, zone, clusterServiceOffering);
            } else {
                plan(kubernetesCluster.getTotalNodeCount() + newVmRequiredCount, zone, clusterServiceOffering);
            }
        } catch (InsufficientCapacityException e) {
            logTransitStateToFailedIfNeededAndThrow(Level.WARN, String.format("Scaling failed for Kubernetes cluster : %s in zone : %s, insufficient capacity", kubernetesCluster.getName(), zone.getName()));
        }
    }
    List<KubernetesClusterVmMapVO> vmList = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
    if (CollectionUtils.isEmpty(vmList) || vmList.size() < kubernetesCluster.getTotalNodeCount()) {
        logTransitStateToFailedIfNeededAndThrow(Level.ERROR, String.format("Scaling failed for Kubernetes cluster : %s, it is in unstable state as not enough existing VM instances found", kubernetesCluster.getName()));
    }
}
Also used : DataCenter(com.cloud.dc.DataCenter) ServiceOffering(com.cloud.offering.ServiceOffering) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Aggregations

KubernetesClusterVmMapVO (com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 UserVmVO (com.cloud.vm.UserVmVO)4 ManagementServerException (com.cloud.exception.ManagementServerException)3 UserVm (com.cloud.uservm.UserVm)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ArrayList (java.util.ArrayList)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 File (java.io.File)2 IOException (java.io.IOException)2 DataCenter (com.cloud.dc.DataCenter)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)1 IpAddress (com.cloud.network.IpAddress)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 FirewallRule (com.cloud.network.rules.FirewallRule)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 Filter (com.cloud.utils.db.Filter)1 UserVmDetailVO (com.cloud.vm.UserVmDetailVO)1