Search in sources :

Example 1 with KubernetesSupportedVersionVO

use of com.cloud.kubernetes.version.KubernetesSupportedVersionVO in project cloudstack by apache.

the class KubernetesClusterManagerImpl method validateKubernetesClusterUpgradeParameters.

private void validateKubernetesClusterUpgradeParameters(UpgradeKubernetesClusterCmd cmd) {
    // Validate parameters
    validateEndpointUrl();
    final Long kubernetesClusterId = cmd.getId();
    final Long upgradeVersionId = cmd.getKubernetesVersionId();
    if (kubernetesClusterId == null || kubernetesClusterId < 1L) {
        throw new InvalidParameterValueException("Invalid Kubernetes cluster ID");
    }
    if (upgradeVersionId == null || upgradeVersionId < 1L) {
        throw new InvalidParameterValueException("Invalid Kubernetes version ID");
    }
    KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(kubernetesClusterId);
    if (kubernetesCluster == null || kubernetesCluster.getRemoved() != null) {
        throw new InvalidParameterValueException("Invalid Kubernetes cluster ID");
    }
    accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.OperateEntry, false, kubernetesCluster);
    if (!KubernetesCluster.State.Running.equals(kubernetesCluster.getState())) {
        throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s is not in running state", kubernetesCluster.getName()));
    }
    final DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
    if (zone == null) {
        logAndThrow(Level.WARN, String.format("Unable to find zone for Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
    KubernetesSupportedVersionVO upgradeVersion = kubernetesSupportedVersionDao.findById(upgradeVersionId);
    if (upgradeVersion == null || upgradeVersion.getRemoved() != null) {
        throw new InvalidParameterValueException("Invalid Kubernetes version ID");
    }
    if (!KubernetesSupportedVersion.State.Enabled.equals(upgradeVersion.getState())) {
        throw new InvalidParameterValueException(String.format("Kubernetes version ID: %s for upgrade is in %s state", upgradeVersion.getUuid(), upgradeVersion.getState()));
    }
    KubernetesSupportedVersionVO clusterVersion = kubernetesSupportedVersionDao.findById(kubernetesCluster.getKubernetesVersionId());
    if (clusterVersion == null || clusterVersion.getRemoved() != null) {
        throw new InvalidParameterValueException(String.format("Invalid Kubernetes version associated with cluster : %s", kubernetesCluster.getName()));
    }
    final ServiceOffering serviceOffering = serviceOfferingDao.findByIdIncludingRemoved(kubernetesCluster.getServiceOfferingId());
    if (serviceOffering == null) {
        throw new CloudRuntimeException(String.format("Invalid service offering associated with Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
    if (serviceOffering.getCpu() < upgradeVersion.getMinimumCpu()) {
        throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s cannot be upgraded with Kubernetes version : %s which needs minimum %d vCPUs while associated service offering : %s offers only %d vCPUs", kubernetesCluster.getName(), upgradeVersion.getName(), upgradeVersion.getMinimumCpu(), serviceOffering.getName(), serviceOffering.getCpu()));
    }
    if (serviceOffering.getRamSize() < upgradeVersion.getMinimumRamSize()) {
        throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s cannot be upgraded with Kubernetes version : %s which needs minimum %d MB RAM while associated service offering : %s offers only %d MB RAM", kubernetesCluster.getName(), upgradeVersion.getName(), upgradeVersion.getMinimumRamSize(), serviceOffering.getName(), serviceOffering.getRamSize()));
    }
    // Check upgradeVersion is either patch upgrade or immediate minor upgrade
    try {
        KubernetesVersionManagerImpl.canUpgradeKubernetesVersion(clusterVersion.getSemanticVersion(), upgradeVersion.getSemanticVersion());
    } catch (IllegalArgumentException e) {
        throw new InvalidParameterValueException(e.getMessage());
    }
    VMTemplateVO iso = templateDao.findById(upgradeVersion.getIsoId());
    if (iso == null) {
        throw new InvalidParameterValueException(String.format("Invalid ISO associated with version : %s", upgradeVersion.getName()));
    }
    if (CollectionUtils.isEmpty(templateJoinDao.newTemplateView(iso, zone.getId(), true))) {
        throw new InvalidParameterValueException(String.format("ISO associated with version : %s is not in Ready state for datacenter : %s", upgradeVersion.getName(), zone.getName()));
    }
}
Also used : DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) KubernetesSupportedVersionVO(com.cloud.kubernetes.version.KubernetesSupportedVersionVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 2 with KubernetesSupportedVersionVO

use of com.cloud.kubernetes.version.KubernetesSupportedVersionVO in project cloudstack by apache.

the class KubernetesClusterManagerImpl method createKubernetesClusterResponse.

@Override
public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetesClusterId) {
    KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(kubernetesClusterId);
    KubernetesClusterResponse response = new KubernetesClusterResponse();
    response.setObjectName(KubernetesCluster.class.getSimpleName().toLowerCase());
    response.setId(kubernetesCluster.getUuid());
    response.setName(kubernetesCluster.getName());
    response.setDescription(kubernetesCluster.getDescription());
    DataCenterVO zone = ApiDBUtils.findZoneById(kubernetesCluster.getZoneId());
    response.setZoneId(zone.getUuid());
    response.setZoneName(zone.getName());
    response.setMasterNodes(kubernetesCluster.getControlNodeCount());
    response.setControlNodes(kubernetesCluster.getControlNodeCount());
    response.setClusterSize(kubernetesCluster.getNodeCount());
    VMTemplateVO template = ApiDBUtils.findTemplateById(kubernetesCluster.getTemplateId());
    response.setTemplateId(template.getUuid());
    ServiceOfferingVO offering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
    response.setServiceOfferingId(offering.getUuid());
    response.setServiceOfferingName(offering.getName());
    KubernetesSupportedVersionVO version = kubernetesSupportedVersionDao.findById(kubernetesCluster.getKubernetesVersionId());
    if (version != null) {
        response.setKubernetesVersionId(version.getUuid());
        response.setKubernetesVersionName(version.getName());
    }
    Account account = ApiDBUtils.findAccountById(kubernetesCluster.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
        response.setProjectId(project.getUuid());
        response.setProjectName(project.getName());
    } else {
        response.setAccountName(account.getAccountName());
    }
    Domain domain = ApiDBUtils.findDomainById(kubernetesCluster.getDomainId());
    response.setDomainId(domain.getUuid());
    response.setDomainName(domain.getName());
    response.setKeypair(kubernetesCluster.getKeyPair());
    response.setState(kubernetesCluster.getState().toString());
    response.setCores(String.valueOf(kubernetesCluster.getCores()));
    response.setMemory(String.valueOf(kubernetesCluster.getMemory()));
    NetworkVO ntwk = networkDao.findByIdIncludingRemoved(kubernetesCluster.getNetworkId());
    response.setEndpoint(kubernetesCluster.getEndpoint());
    response.setNetworkId(ntwk.getUuid());
    response.setAssociatedNetworkName(ntwk.getName());
    if (ntwk.getGuestType() == Network.GuestType.Isolated) {
        List<IPAddressVO> ipAddresses = ipAddressDao.listByAssociatedNetwork(ntwk.getId(), true);
        if (ipAddresses != null && ipAddresses.size() == 1) {
            response.setIpAddress(ipAddresses.get(0).getAddress().addr());
            response.setIpAddressId(ipAddresses.get(0).getUuid());
        }
    }
    List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
    List<KubernetesClusterVmMapVO> vmList = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
    ResponseView respView = ResponseView.Restricted;
    Account caller = CallContext.current().getCallingAccount();
    if (accountService.isRootAdmin(caller.getId())) {
        respView = ResponseView.Full;
    }
    final String responseName = "virtualmachine";
    if (vmList != null && !vmList.isEmpty()) {
        for (KubernetesClusterVmMapVO vmMapVO : vmList) {
            UserVmJoinVO userVM = userVmJoinDao.findById(vmMapVO.getVmId());
            if (userVM != null) {
                UserVmResponse vmResponse = ApiDBUtils.newUserVmResponse(respView, responseName, userVM, EnumSet.of(VMDetails.nics), caller);
                vmResponses.add(vmResponse);
            }
        }
    }
    response.setHasAnnotation(annotationDao.hasAnnotations(kubernetesCluster.getUuid(), AnnotationService.EntityType.KUBERNETES_CLUSTER.name(), accountService.isRootAdmin(caller.getId())));
    response.setVirtualMachines(vmResponses);
    response.setAutoscalingEnabled(kubernetesCluster.getAutoscalingEnabled());
    response.setMinSize(kubernetesCluster.getMinSize());
    response.setMaxSize(kubernetesCluster.getMaxSize());
    return response;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) KubernetesClusterResponse(org.apache.cloudstack.api.response.KubernetesClusterResponse) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) Project(com.cloud.projects.Project) ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) KubernetesSupportedVersionVO(com.cloud.kubernetes.version.KubernetesSupportedVersionVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) Domain(com.cloud.domain.Domain)

Aggregations

KubernetesSupportedVersionVO (com.cloud.kubernetes.version.KubernetesSupportedVersionVO)2 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)1 DataCenter (com.cloud.dc.DataCenter)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 Domain (com.cloud.domain.Domain)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 Project (com.cloud.projects.Project)1 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 KubernetesClusterResponse (org.apache.cloudstack.api.response.KubernetesClusterResponse)1 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)1