Search in sources :

Example 16 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class FirstFitAllocator method allocateTo.

protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, VMTemplateVO template, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo, boolean considerReservedCapacity, Account account) {
    if (_allocationAlgorithm.equals("random") || _allocationAlgorithm.equals("userconcentratedpod_random")) {
        // Shuffle this so that we don't check the hosts in the same order.
        Collections.shuffle(hosts);
    } else if (_allocationAlgorithm.equals("userdispersing")) {
        hosts = reorderHostsByNumberOfVms(plan, hosts, account);
    } else if (_allocationAlgorithm.equals("firstfitleastconsumed")) {
        hosts = reorderHostsByCapacity(plan, hosts);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("FirstFitAllocator has " + hosts.size() + " hosts to check for allocation: " + hosts);
    }
    // We will try to reorder the host lists such that we give priority to hosts that have
    // the minimums to support a VM's requirements
    hosts = prioritizeHosts(template, offering, hosts);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Found " + hosts.size() + " hosts for allocation after prioritization: " + hosts);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Looking for speed=" + (offering.getCpu() * offering.getSpeed()) + "Mhz, Ram=" + offering.getRamSize() + " MB");
    }
    long serviceOfferingId = offering.getId();
    List<Host> suitableHosts = new ArrayList<Host>();
    ServiceOfferingDetailsVO offeringDetails = null;
    for (Host host : hosts) {
        if (suitableHosts.size() == returnUpTo) {
            break;
        }
        if (avoid.shouldAvoid(host)) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, skipping this and trying other available hosts");
            }
            continue;
        }
        // find number of guest VMs occupying capacity on this host.
        if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " already has max Running VMs(count includes system VMs), skipping this and trying other available hosts");
            }
            avoid.addHost(host.getId());
            continue;
        }
        // Check if GPU device is required by offering and host has the availability
        if ((offeringDetails = _serviceOfferingDetailsDao.findDetail(serviceOfferingId, GPU.Keys.vgpuType.toString())) != null) {
            ServiceOfferingDetailsVO groupName = _serviceOfferingDetailsDao.findDetail(serviceOfferingId, GPU.Keys.pciDevice.toString());
            if (!_resourceMgr.isGPUDeviceAvailable(host.getId(), groupName.getValue(), offeringDetails.getValue())) {
                s_logger.info("Host name: " + host.getName() + ", hostId: " + host.getId() + " does not have required GPU devices available");
                avoid.addHost(host.getId());
                continue;
            }
        }
        Pair<Boolean, Boolean> cpuCapabilityAndCapacity = _capacityMgr.checkIfHostHasCpuCapabilityAndCapacity(host, offering, considerReservedCapacity);
        if (cpuCapabilityAndCapacity.first() && cpuCapabilityAndCapacity.second()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Found a suitable host, adding to list: " + host.getId());
            }
            suitableHosts.add(host);
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Not using host " + host.getId() + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity?" + cpuCapabilityAndCapacity.second());
            }
            avoid.addHost(host.getId());
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Host Allocator returning " + suitableHosts.size() + " suitable hosts");
    }
    return suitableHosts;
}
Also used : ArrayList(java.util.ArrayList) ServiceOfferingDetailsVO(com.cloud.service.ServiceOfferingDetailsVO) Host(com.cloud.host.Host)

Example 17 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class FirstFitAllocator method reorderHostsByNumberOfVms.

private List<? extends Host> reorderHostsByNumberOfVms(DeploymentPlan plan, List<? extends Host> hosts, Account account) {
    if (account == null) {
        return hosts;
    }
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    List<Long> hostIdsByVmCount = _vmInstanceDao.listHostIdsByVmCount(dcId, podId, clusterId, account.getAccountId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("List of hosts in ascending order of number of VMs: " + hostIdsByVmCount);
    }
    // now filter the given list of Hosts by this ordered list
    Map<Long, Host> hostMap = new HashMap<Long, Host>();
    for (Host host : hosts) {
        hostMap.put(host.getId(), host);
    }
    List<Long> matchingHostIds = new ArrayList<Long>(hostMap.keySet());
    hostIdsByVmCount.retainAll(matchingHostIds);
    List<Host> reorderedHosts = new ArrayList<Host>();
    for (Long id : hostIdsByVmCount) {
        reorderedHosts.add(hostMap.get(id));
    }
    return reorderedHosts;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Example 18 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class CommandSetupHelper method createVmDataCommand.

public void createVmDataCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final String publicKey, final Commands cmds) {
    if (vm != null && router != null && nic != null) {
        final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
        final String zoneName = _dcDao.findById(router.getDataCenterId()).getName();
        final IPAddressVO staticNatIp = _ipAddressDao.findByVmIdAndNetworkId(nic.getNetworkId(), vm.getId());
        Host host = _hostDao.findById(vm.getHostId());
        String destHostname = VirtualMachineManager.getHypervisorHostname(host != null ? host.getName() : "");
        cmds.addCommand("vmdata", generateVmDataCommand(router, nic.getIPv4Address(), vm.getUserData(), serviceOffering, zoneName, staticNatIp == null || staticNatIp.getState() != IpAddress.State.Allocated ? null : staticNatIp.getAddress().addr(), vm.getHostName(), vm.getInstanceName(), vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId(), destHostname));
    }
}
Also used : IPAddressVO(com.cloud.network.dao.IPAddressVO) Host(com.cloud.host.Host)

Example 19 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class ConfigureHAForHostCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final Host host = _resourceService.getHost(getHostId());
    if (host == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
    }
    final boolean result = haConfigManager.configureHA(host.getId(), HAResource.ResourceType.Host, getHaProvider());
    if (!result) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure HA provider for the host");
    }
    CallContext.current().setEventDetails("Host Id:" + host.getId() + " HA configured with provider: " + getHaProvider());
    CallContext.current().putContextParameter(Host.class, host.getUuid());
    setupResponse(result, host.getUuid());
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) Host(com.cloud.host.Host)

Example 20 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class ListHostsCmd method getHostResponses.

protected ListResponse<HostResponse> getHostResponses() {
    ListResponse<HostResponse> response = new ListResponse<>();
    if (getVirtualMachineId() == null) {
        response = _queryService.searchForServers(this);
    } else {
        Pair<List<? extends Host>, Integer> result;
        Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal(), null);
        result = hostsForMigration.first();
        List<? extends Host> hostsWithCapacity = hostsForMigration.second();
        List<HostResponse> hostResponses = new ArrayList<HostResponse>();
        for (Host host : result.first()) {
            HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails());
            Boolean suitableForMigration = false;
            if (hostsWithCapacity.contains(host)) {
                suitableForMigration = true;
            }
            hostResponse.setSuitableForMigration(suitableForMigration);
            hostResponse.setObjectName("host");
            hostResponses.add(hostResponse);
        }
        response.setResponses(hostResponses, result.second());
    }
    return response;
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) HostResponse(org.apache.cloudstack.api.response.HostResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Aggregations

Host (com.cloud.host.Host)226 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)77 ArrayList (java.util.ArrayList)67 HashMap (java.util.HashMap)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)42 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 ServerApiException (org.apache.cloudstack.api.ServerApiException)30 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)28 Answer (com.cloud.agent.api.Answer)25 ConfigurationException (javax.naming.ConfigurationException)25 Pair (com.cloud.utils.Pair)24 Map (java.util.Map)24 StoragePool (com.cloud.storage.StoragePool)23 DeployDestination (com.cloud.deploy.DeployDestination)22 HostVO (com.cloud.host.HostVO)22 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)21 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)21 VolumeVO (com.cloud.storage.VolumeVO)21 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)20 List (java.util.List)20