Search in sources :

Example 6 with KubernetesClusterResponse

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

Example 7 with KubernetesClusterResponse

use of org.apache.cloudstack.api.response.KubernetesClusterResponse in project cloudstack by apache.

the class KubernetesClusterManagerImpl method listKubernetesClusters.

@Override
public ListResponse<KubernetesClusterResponse> listKubernetesClusters(ListKubernetesClustersCmd cmd) {
    if (!KubernetesServiceEnabled.value()) {
        logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled");
    }
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final Long clusterId = cmd.getId();
    final String state = cmd.getState();
    final String name = cmd.getName();
    final String keyword = cmd.getKeyword();
    List<KubernetesClusterResponse> responsesList = new ArrayList<KubernetesClusterResponse>();
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, Project.ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, Project.ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
    accountManager.buildACLSearchParameters(caller, clusterId, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
    Long domainId = domainIdRecursiveListProject.first();
    Boolean isRecursive = domainIdRecursiveListProject.second();
    Project.ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    Filter searchFilter = new Filter(KubernetesClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    SearchBuilder<KubernetesClusterVO> sb = kubernetesClusterDao.createSearchBuilder();
    accountManager.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
    sb.and("keyword", sb.entity().getName(), SearchCriteria.Op.LIKE);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.IN);
    SearchCriteria<KubernetesClusterVO> sc = sb.create();
    accountManager.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (state != null) {
        sc.setParameters("state", state);
    }
    if (keyword != null) {
        sc.setParameters("keyword", "%" + keyword + "%");
    }
    if (clusterId != null) {
        sc.setParameters("id", clusterId);
    }
    if (name != null) {
        sc.setParameters("name", name);
    }
    List<KubernetesClusterVO> kubernetesClusters = kubernetesClusterDao.search(sc, searchFilter);
    for (KubernetesClusterVO cluster : kubernetesClusters) {
        KubernetesClusterResponse clusterResponse = createKubernetesClusterResponse(cluster.getId());
        responsesList.add(clusterResponse);
    }
    ListResponse<KubernetesClusterResponse> response = new ListResponse<KubernetesClusterResponse>();
    response.setResponses(responsesList);
    return response;
}
Also used : UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) KubernetesClusterResponse(org.apache.cloudstack.api.response.KubernetesClusterResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) CallContext(org.apache.cloudstack.context.CallContext) Project(com.cloud.projects.Project) Filter(com.cloud.utils.db.Filter)

Aggregations

KubernetesClusterResponse (org.apache.cloudstack.api.response.KubernetesClusterResponse)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 Project (com.cloud.projects.Project)2 Account (com.cloud.user.Account)2 UserAccount (com.cloud.user.UserAccount)2 ArrayList (java.util.ArrayList)2 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 Domain (com.cloud.domain.Domain)1 KubernetesCluster (com.cloud.kubernetes.cluster.KubernetesCluster)1 KubernetesSupportedVersionVO (com.cloud.kubernetes.version.KubernetesSupportedVersionVO)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 Ternary (com.cloud.utils.Ternary)1 Filter (com.cloud.utils.db.Filter)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1