Search in sources :

Example 56 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse 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

UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)56 UserVm (com.cloud.uservm.UserVm)49 ServerApiException (org.apache.cloudstack.api.ServerApiException)43 ArrayList (java.util.ArrayList)19 VMDetails (org.apache.cloudstack.api.ApiConstants.VMDetails)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)7 Account (com.cloud.user.Account)7 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)6 VirtualMachine (com.cloud.vm.VirtualMachine)6 List (java.util.List)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)4 ManagementServerException (com.cloud.exception.ManagementServerException)4 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)4 Host (com.cloud.host.Host)4 ServiceOffering (com.cloud.offering.ServiceOffering)4 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)4 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)4