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;
}
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;
}
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));
}
}
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());
}
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;
}
Aggregations