Search in sources :

Example 96 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class FirstFitAllocator method allocateTo.

@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    ServiceOffering offering = vmProfile.getServiceOffering();
    VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
    Account account = vmProfile.getOwner();
    List<Host> suitableHosts = new ArrayList<Host>();
    List<Host> hostsCopy = new ArrayList<Host>(hosts);
    if (type == Host.Type.Storage) {
        // routing or not.
        return suitableHosts;
    }
    String hostTagOnOffering = offering.getHostTag();
    String hostTagOnTemplate = template.getTemplateTag();
    boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
    boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
    String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
    if (haVmTag != null) {
        hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
    } else {
        if (hostTagOnOffering == null && hostTagOnTemplate == null) {
            hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
        } else {
            if (hasSvcOfferingTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
                }
                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy);
                }
            }
            if (hasTemplateTag) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
                }
                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy);
                }
            }
        }
    }
    if (!hostsCopy.isEmpty()) {
        suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
    }
    return suitableHosts;
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Example 97 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class KubernetesClusterResourceModifierActionWorker method createKubernetesNode.

protected UserVm createKubernetesNode(String joinIp) throws ManagementServerException, ResourceUnavailableException, InsufficientCapacityException {
    UserVm nodeVm = null;
    DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
    ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
    List<Long> networkIds = new ArrayList<Long>();
    networkIds.add(kubernetesCluster.getNetworkId());
    Account owner = accountDao.findById(kubernetesCluster.getAccountId());
    Network.IpAddresses addrs = new Network.IpAddresses(null, null);
    long rootDiskSize = kubernetesCluster.getNodeRootDiskSize();
    Map<String, String> customParameterMap = new HashMap<String, String>();
    if (rootDiskSize > 0) {
        customParameterMap.put("rootdisksize", String.valueOf(rootDiskSize));
    }
    if (Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType())) {
        customParameterMap.put(VmDetailConstants.ROOT_DISK_CONTROLLER, "scsi");
    }
    String suffix = Long.toHexString(System.currentTimeMillis());
    String hostName = String.format("%s-node-%s", kubernetesClusterNodeNamePrefix, suffix);
    String k8sNodeConfig = null;
    try {
        k8sNodeConfig = getKubernetesNodeConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType()));
    } catch (IOException e) {
        logAndThrow(Level.ERROR, "Failed to read Kubernetes node configuration file", e);
    }
    String base64UserData = Base64.encodeBase64String(k8sNodeConfig.getBytes(com.cloud.utils.StringUtils.getPreferredCharset()));
    nodeVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, owner, hostName, hostName, null, null, null, Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(), null, addrs, null, null, null, customParameterMap, null, null, null, null, true, UserVmManager.CKS_NODE, null);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Created node VM : %s, %s in the Kubernetes cluster : %s", hostName, nodeVm.getUuid(), kubernetesCluster.getName()));
    }
    return nodeVm;
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network)

Example 98 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class KubernetesClusterResourceModifierActionWorker method plan.

protected DeployDestination plan() throws InsufficientServerCapacityException {
    ServiceOffering offering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
    DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Checking deployment destination for Kubernetes cluster : %s in zone : %s", kubernetesCluster.getName(), zone.getName()));
    }
    return plan(kubernetesCluster.getTotalNodeCount(), zone, offering);
}
Also used : DataCenter(com.cloud.dc.DataCenter) ServiceOffering(com.cloud.offering.ServiceOffering)

Example 99 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class KubernetesClusterStartWorker method createKubernetesAdditionalControlNode.

private UserVm createKubernetesAdditionalControlNode(final String joinIp, final int additionalControlNodeInstance) throws ManagementServerException, ResourceUnavailableException, InsufficientCapacityException {
    UserVm additionalControlVm = null;
    DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
    ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
    List<Long> networkIds = new ArrayList<Long>();
    networkIds.add(kubernetesCluster.getNetworkId());
    Network.IpAddresses addrs = new Network.IpAddresses(null, null);
    long rootDiskSize = kubernetesCluster.getNodeRootDiskSize();
    Map<String, String> customParameterMap = new HashMap<String, String>();
    if (rootDiskSize > 0) {
        customParameterMap.put("rootdisksize", String.valueOf(rootDiskSize));
    }
    if (Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType())) {
        customParameterMap.put(VmDetailConstants.ROOT_DISK_CONTROLLER, "scsi");
    }
    String suffix = Long.toHexString(System.currentTimeMillis());
    String hostName = String.format("%s-control-%s", kubernetesClusterNodeNamePrefix, suffix);
    String k8sControlNodeConfig = null;
    try {
        k8sControlNodeConfig = getKubernetesAdditionalControlNodeConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType()));
    } catch (IOException e) {
        logAndThrow(Level.ERROR, "Failed to read Kubernetes control configuration file", e);
    }
    String base64UserData = Base64.encodeBase64String(k8sControlNodeConfig.getBytes(com.cloud.utils.StringUtils.getPreferredCharset()));
    additionalControlVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, owner, hostName, hostName, null, null, null, Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(), null, addrs, null, null, null, customParameterMap, null, null, null, null, true, UserVmManager.CKS_NODE, null);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Created control VM ID : %s, %s in the Kubernetes cluster : %s", additionalControlVm.getUuid(), hostName, kubernetesCluster.getName()));
    }
    return additionalControlVm;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network)

Example 100 with ServiceOffering

use of com.cloud.offering.ServiceOffering in project cloudstack by apache.

the class KubernetesClusterManagerImpl method createKubernetesCluster.

@Override
public KubernetesCluster createKubernetesCluster(CreateKubernetesClusterCmd cmd) throws CloudRuntimeException {
    if (!KubernetesServiceEnabled.value()) {
        logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled");
    }
    validateKubernetesClusterCreateParameters(cmd);
    final DataCenter zone = dataCenterDao.findById(cmd.getZoneId());
    final long controlNodeCount = cmd.getControlNodes();
    final long clusterSize = cmd.getClusterSize();
    final long totalNodeCount = controlNodeCount + clusterSize;
    final ServiceOffering serviceOffering = serviceOfferingDao.findById(cmd.getServiceOfferingId());
    final Account owner = accountService.getActiveAccountById(cmd.getEntityOwnerId());
    final KubernetesSupportedVersion clusterKubernetesVersion = kubernetesSupportedVersionDao.findById(cmd.getKubernetesVersionId());
    DeployDestination deployDestination = null;
    try {
        deployDestination = plan(totalNodeCount, zone, serviceOffering);
    } catch (InsufficientCapacityException e) {
        logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to insufficient capacity for %d nodes cluster in zone : %s with service offering : %s", totalNodeCount, zone.getName(), serviceOffering.getName()));
    }
    if (deployDestination == null || deployDestination.getCluster() == null) {
        logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to error while finding suitable deployment plan for cluster in zone : %s", zone.getName()));
    }
    final Network defaultNetwork = getKubernetesClusterNetworkIfMissing(cmd.getName(), zone, owner, (int) controlNodeCount, (int) clusterSize, cmd.getExternalLoadBalancerIpAddress(), cmd.getNetworkId());
    final VMTemplateVO finalTemplate = getKubernetesServiceTemplate(zone, deployDestination.getCluster().getHypervisorType());
    final long cores = serviceOffering.getCpu() * (controlNodeCount + clusterSize);
    final long memory = serviceOffering.getRamSize() * (controlNodeCount + clusterSize);
    final KubernetesClusterVO cluster = Transaction.execute(new TransactionCallback<KubernetesClusterVO>() {

        @Override
        public KubernetesClusterVO doInTransaction(TransactionStatus status) {
            KubernetesClusterVO newCluster = new KubernetesClusterVO(cmd.getName(), cmd.getDisplayName(), zone.getId(), clusterKubernetesVersion.getId(), serviceOffering.getId(), finalTemplate.getId(), defaultNetwork.getId(), owner.getDomainId(), owner.getAccountId(), controlNodeCount, clusterSize, KubernetesCluster.State.Created, cmd.getSSHKeyPairName(), cores, memory, cmd.getNodeRootDiskSize(), "");
            kubernetesClusterDao.persist(newCluster);
            return newCluster;
        }
    });
    addKubernetesClusterDetails(cluster, defaultNetwork, cmd);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Kubernetes cluster name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid()));
    }
    return cluster;
}
Also used : KubernetesSupportedVersion(com.cloud.kubernetes.version.KubernetesSupportedVersion) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Aggregations

ServiceOffering (com.cloud.offering.ServiceOffering)103 ArrayList (java.util.ArrayList)34 Account (com.cloud.user.Account)30 DataCenter (com.cloud.dc.DataCenter)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 HashMap (java.util.HashMap)18 VirtualMachine (com.cloud.vm.VirtualMachine)17 VMTemplateVO (com.cloud.storage.VMTemplateVO)14 UserVm (com.cloud.uservm.UserVm)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 Map (java.util.Map)14 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)13 ServerApiException (com.cloud.api.ServerApiException)12 HostVO (com.cloud.host.HostVO)12 DiskOffering (com.cloud.offering.DiskOffering)11 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)11 Host (com.cloud.host.Host)10 Network (com.cloud.network.Network)10 List (java.util.List)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9