Search in sources :

Example 31 with InsufficientServerCapacityException

use of com.cloud.exception.InsufficientServerCapacityException in project cloudstack by apache.

the class AutoScaleManagerImpl method startNewVM.

private boolean startNewVM(long vmId) {
    try {
        CallContext.current().setEventDetails("Vm Id: " + vmId);
        _userVmManager.startVirtualMachine(vmId, null, null, null);
    } catch (final ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ResourceAllocationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        StringBuilder message = new StringBuilder(ex.getMessage());
        if (ex instanceof InsufficientServerCapacityException) {
            if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
                message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
            }
        }
        s_logger.info(ex);
        s_logger.info(message.toString(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
    }
    return true;
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 32 with InsufficientServerCapacityException

use of com.cloud.exception.InsufficientServerCapacityException in project cloudstack by apache.

the class NetworkHelperImpl method getHypervisors.

protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition) throws InsufficientServerCapacityException {
    final DeployDestination dest = routerDeploymentDefinition.getDest();
    List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
    if (dest.getCluster() != null) {
        if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) {
            hypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId()));
        } else {
            hypervisors.add(dest.getCluster().getHypervisorType());
        }
    } else {
        final HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
        if (defaults != HypervisorType.None) {
            hypervisors.add(defaults);
        } else {
            // if there is no default hypervisor, get it from the cluster
            hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, routerDeploymentDefinition.getPlan().getPodId());
        }
    }
    filterSupportedHypervisors(hypervisors);
    if (hypervisors.isEmpty()) {
        if (routerDeploymentDefinition.getPodId() != null) {
            throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the pod." + getNoHypervisorsErrMsgDetails(), Pod.class, routerDeploymentDefinition.getPodId());
        }
        throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the zone." + getNoHypervisorsErrMsgDetails(), DataCenter.class, dest.getDataCenter().getId());
    }
    return hypervisors;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) DeployDestination(com.cloud.deploy.DeployDestination) ArrayList(java.util.ArrayList) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

Example 33 with InsufficientServerCapacityException

use of com.cloud.exception.InsufficientServerCapacityException in project cloudstack by apache.

the class KubernetesClusterResourceModifierActionWorker method plan.

protected DeployDestination plan(final long nodesCount, final DataCenter zone, final ServiceOffering offering) throws InsufficientServerCapacityException {
    final int cpu_requested = offering.getCpu() * offering.getSpeed();
    final long ram_requested = offering.getRamSize() * 1024L * 1024L;
    List<HostVO> hosts = resourceManager.listAllHostsInOneZoneByType(Host.Type.Routing, zone.getId());
    final Map<String, Pair<HostVO, Integer>> hosts_with_resevered_capacity = new ConcurrentHashMap<String, Pair<HostVO, Integer>>();
    for (HostVO h : hosts) {
        hosts_with_resevered_capacity.put(h.getUuid(), new Pair<HostVO, Integer>(h, 0));
    }
    boolean suitable_host_found = false;
    for (int i = 1; i <= nodesCount; i++) {
        suitable_host_found = false;
        for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
            Pair<HostVO, Integer> hp = hostEntry.getValue();
            HostVO h = hp.first();
            if (!h.getHypervisorType().equals(clusterTemplate.getHypervisorType())) {
                continue;
            }
            hostDao.loadHostTags(h);
            if (StringUtils.isNotEmpty(offering.getHostTag()) && !(h.getHostTags() != null && h.getHostTags().contains(offering.getHostTag()))) {
                continue;
            }
            int reserved = hp.second();
            reserved++;
            ClusterVO cluster = clusterDao.findById(h.getClusterId());
            ClusterDetailsVO cluster_detail_cpu = clusterDetailsDao.findDetail(cluster.getId(), "cpuOvercommitRatio");
            ClusterDetailsVO cluster_detail_ram = clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio");
            Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
            Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(String.format("Checking host : %s for capacity already reserved %d", h.getName(), reserved));
            }
            if (capacityManager.checkIfHostHasCapacity(h.getId(), cpu_requested * reserved, ram_requested * reserved, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(String.format("Found host : %s for with enough capacity, CPU=%d RAM=%s", h.getName(), cpu_requested * reserved, toHumanReadableSize(ram_requested * reserved)));
                }
                hostEntry.setValue(new Pair<HostVO, Integer>(h, reserved));
                suitable_host_found = true;
                break;
            }
        }
        if (!suitable_host_found) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info(String.format("Suitable hosts not found in datacenter : %s for node %d, with offering : %s and hypervisor: %s", zone.getName(), i, offering.getName(), clusterTemplate.getHypervisorType().toString()));
            }
            break;
        }
    }
    if (suitable_host_found) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Suitable hosts found in datacenter : %s, creating deployment destination", zone.getName()));
        }
        return new DeployDestination(zone, null, null, null);
    }
    String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%s) with offering : %s and hypervisor: %s", cpu_requested * nodesCount, toHumanReadableSize(ram_requested * nodesCount), offering.getName(), clusterTemplate.getHypervisorType().toString());
    LOGGER.warn(msg);
    throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId());
}
Also used : KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO) ClusterVO(com.cloud.dc.ClusterVO) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) HostVO(com.cloud.host.HostVO) DeployDestination(com.cloud.deploy.DeployDestination) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KubernetesClusterDetailsVO(com.cloud.kubernetes.cluster.KubernetesClusterDetailsVO) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) Pair(com.cloud.utils.Pair)

Aggregations

InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)33 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)21 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 DeployDestination (com.cloud.deploy.DeployDestination)14 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)14 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)12 AffinityConflictException (com.cloud.exception.AffinityConflictException)11 Host (com.cloud.host.Host)8 UserVm (com.cloud.uservm.UserVm)8 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)7 VolumeVO (com.cloud.storage.VolumeVO)7 ExecutionException (com.cloud.utils.exception.ExecutionException)7 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)6 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ServerApiException (com.cloud.api.ServerApiException)4 UserVmResponse (com.cloud.api.response.UserVmResponse)4 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)4 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4