diff --git a/server/src/com/cloud/agent/manager/allocator/HostAllocator.java b/api/src/com/cloud/agent/manager/allocator/HostAllocator.java similarity index 86% rename from server/src/com/cloud/agent/manager/allocator/HostAllocator.java rename to api/src/com/cloud/agent/manager/allocator/HostAllocator.java index 6700f2227d9..fcd1fc10072 100755 --- a/server/src/com/cloud/agent/manager/allocator/HostAllocator.java +++ b/api/src/com/cloud/agent/manager/allocator/HostAllocator.java @@ -21,7 +21,6 @@ import java.util.List; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.host.Host; -import com.cloud.host.HostVO; import com.cloud.host.Host.Type; import com.cloud.offering.ServiceOffering; import com.cloud.utils.component.Adapter; @@ -36,9 +35,9 @@ public interface HostAllocator extends Adapter { **/ boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering); - /** - * Determines which physical hosts are suitable to - * allocate the guest virtual machines on + /** + * Determines which physical hosts are suitable to + * allocate the guest virtual machines on * * @param VirtualMachineProfile vmProfile * @param DeploymentPlan plan @@ -46,13 +45,13 @@ public interface HostAllocator extends Adapter { * @param ExcludeList avoid * @param int returnUpTo (use -1 to return all possible hosts) * @return List List of hosts that are suitable for VM allocation - **/ + **/ public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo); - /** - * Determines which physical hosts are suitable to - * allocate the guest virtual machines on + /** + * Determines which physical hosts are suitable to + * allocate the guest virtual machines on * * @param VirtualMachineProfile vmProfile * @param DeploymentPlan plan @@ -61,7 +60,7 @@ public interface HostAllocator extends Adapter { * @param int returnUpTo (use -1 to return all possible hosts) * @param boolean considerReservedCapacity (default should be true, set to false if host capacity calculation should not look at reserved capacity) * @return List List of hosts that are suitable for VM allocation - **/ + **/ public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity); @@ -78,7 +77,8 @@ public interface HostAllocator extends Adapter { * @param boolean considerReservedCapacity (default should be true, set to false if host capacity calculation should not look at reserved capacity) * @return List List of hosts that are suitable for VM allocation **/ - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity); + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, + int returnUpTo, boolean considerReservedCapacity); public static int RETURN_UPTO_ALL = -1; diff --git a/server/src/com/cloud/agent/manager/allocator/PodAllocator.java b/api/src/com/cloud/agent/manager/allocator/PodAllocator.java similarity index 82% rename from server/src/com/cloud/agent/manager/allocator/PodAllocator.java rename to api/src/com/cloud/agent/manager/allocator/PodAllocator.java index eb5a9db8242..44cf640a7b3 100755 --- a/server/src/com/cloud/agent/manager/allocator/PodAllocator.java +++ b/api/src/com/cloud/agent/manager/allocator/PodAllocator.java @@ -19,17 +19,15 @@ package com.cloud.agent.manager.allocator; import java.util.Set; import com.cloud.dc.DataCenter; -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.HostPodVO; import com.cloud.dc.Pod; -import com.cloud.service.ServiceOfferingVO; +import com.cloud.offering.ServiceOffering; import com.cloud.template.VirtualMachineTemplate; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapter; import com.cloud.vm.VirtualMachineProfile; public interface PodAllocator extends Adapter { - Pair allocateTo(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long userId, Set avoids); + Pair allocateTo(VirtualMachineTemplate template, ServiceOffering offering, DataCenter dc, long userId, Set avoids); Pod allocateTo(VirtualMachineProfile vm, DataCenter dc, Set avoids); } diff --git a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java index 8243f3a46ad..303e438419a 100755 --- a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java +++ b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.agent.manager.allocator.impl; @@ -19,7 +19,6 @@ package com.cloud.agent.manager.allocator.impl; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import javax.ejb.Local; import javax.inject.Inject; @@ -55,7 +54,7 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { @Override public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, - ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { + ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { long dcId = plan.getDataCenterId(); Long podId = plan.getPodId(); Long clusterId = plan.getClusterId(); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java index b6286aab8da..4329c7017e6 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java @@ -26,16 +26,15 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.dc.ClusterDetailsDao; -import com.cloud.dc.ClusterDetailsVO; -import com.cloud.dc.dao.ClusterDao; -import com.cloud.org.Cluster; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.manager.allocator.HostAllocator; import com.cloud.capacity.CapacityManager; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.ClusterDetailsDao; +import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.dao.ClusterDao; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.host.DetailVO; @@ -45,6 +44,7 @@ import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDetailsDao; import com.cloud.offering.ServiceOffering; +import com.cloud.org.Cluster; import com.cloud.resource.ResourceManager; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.GuestOSCategoryVO; @@ -67,52 +67,67 @@ import com.cloud.vm.dao.VMInstanceDao; * An allocator that tries to find a fit on a computing host. This allocator does not care whether or not the host supports routing. */ @Component -@Local(value={HostAllocator.class}) +@Local(value = {HostAllocator.class}) public class FirstFitAllocator extends AdapterBase implements HostAllocator { private static final Logger s_logger = Logger.getLogger(FirstFitAllocator.class); - @Inject HostDao _hostDao = null; - @Inject HostDetailsDao _hostDetailsDao = null; - @Inject UserVmDao _vmDao = null; - @Inject ServiceOfferingDao _offeringDao = null; - @Inject DomainRouterDao _routerDao = null; - @Inject ConsoleProxyDao _consoleProxyDao = null; - @Inject SecondaryStorageVmDao _secStorgaeVmDao = null; - @Inject ConfigurationDao _configDao = null; - @Inject GuestOSDao _guestOSDao = null; - @Inject GuestOSCategoryDao _guestOSCategoryDao = null; - @Inject VMInstanceDao _vmInstanceDao = null; - @Inject ResourceManager _resourceMgr; - @Inject ClusterDao _clusterDao; - @Inject ClusterDetailsDao _clusterDetailsDao; + @Inject + HostDao _hostDao = null; + @Inject + HostDetailsDao _hostDetailsDao = null; + @Inject + UserVmDao _vmDao = null; + @Inject + ServiceOfferingDao _offeringDao = null; + @Inject + DomainRouterDao _routerDao = null; + @Inject + ConsoleProxyDao _consoleProxyDao = null; + @Inject + SecondaryStorageVmDao _secStorgaeVmDao = null; + @Inject + ConfigurationDao _configDao = null; + @Inject + GuestOSDao _guestOSDao = null; + @Inject + GuestOSCategoryDao _guestOSCategoryDao = null; + @Inject + VMInstanceDao _vmInstanceDao = null; + @Inject + ResourceManager _resourceMgr; + @Inject + ClusterDao _clusterDao; + @Inject + ClusterDetailsDao _clusterDetailsDao; float _factor = 1; boolean _checkHvm = true; protected String _allocationAlgorithm = "random"; - @Inject CapacityManager _capacityMgr; - - - @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, - ExcludeList avoid, int returnUpTo) { - return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true); - } + @Inject + CapacityManager _capacityMgr; @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) { + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + ExcludeList avoid, int returnUpTo) { + return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true); + } - 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(); + @Override + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, 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(); if (type == Host.Type.Storage) { // FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not - return new ArrayList(); + return new ArrayList(); } - if(s_logger.isDebugEnabled()){ - s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId ); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId); } String hostTagOnOffering = offering.getHostTag(); @@ -127,40 +142,40 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { if (haVmTag != null) { clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag); } else { - if (hostTagOnOffering == null && hostTagOnTemplate == null){ + if (hostTagOnOffering == null && hostTagOnTemplate == null) { clusterHosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId); } else { List hostsMatchingOfferingTag = new ArrayList(); List hostsMatchingTemplateTag = new ArrayList(); - if (hasSvcOfferingTag){ - if (s_logger.isDebugEnabled()){ + if (hasSvcOfferingTag) { + if (s_logger.isDebugEnabled()) { s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering); } hostsMatchingOfferingTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering); - if (s_logger.isDebugEnabled()){ + if (s_logger.isDebugEnabled()) { s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsMatchingOfferingTag); } } - if (hasTemplateTag){ - if (s_logger.isDebugEnabled()){ + if (hasTemplateTag) { + if (s_logger.isDebugEnabled()) { s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate); } hostsMatchingTemplateTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate); - if (s_logger.isDebugEnabled()){ - s_logger.debug("Hosts with tag '" + hostTagOnTemplate+"' are:" + hostsMatchingTemplateTag); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsMatchingTemplateTag); } } - if (hasSvcOfferingTag && hasTemplateTag){ + if (hasSvcOfferingTag && hasTemplateTag) { hostsMatchingOfferingTag.retainAll(hostsMatchingTemplateTag); clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate); - if (s_logger.isDebugEnabled()){ - s_logger.debug("Found "+ hostsMatchingOfferingTag.size() +" Hosts satisfying both tags, host ids are:" + hostsMatchingOfferingTag); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Found " + hostsMatchingOfferingTag.size() + " Hosts satisfying both tags, host ids are:" + hostsMatchingOfferingTag); } clusterHosts = hostsMatchingOfferingTag; } else { - if (hasSvcOfferingTag){ + if (hasSvcOfferingTag) { clusterHosts = hostsMatchingOfferingTag; } else { clusterHosts = hostsMatchingTemplateTag; @@ -181,7 +196,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { @Override public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, - Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { + Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { long dcId = plan.getDataCenterId(); Long podId = plan.getPodId(); Long clusterId = plan.getClusterId(); @@ -205,7 +220,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { if (haVmTag != null) { hosts.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag)); } else { - if (hostTagOnOffering == null && hostTagOnTemplate == null){ + if (hostTagOnOffering == null && hostTagOnTemplate == null) { hosts.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId)); } else { if (hasSvcOfferingTag) { @@ -226,16 +241,17 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { return suitableHosts; } - protected List allocateTo(DeploymentPlan plan, ServiceOffering offering, VMTemplateVO template, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity, Account account) { + protected List allocateTo(DeploymentPlan plan, ServiceOffering offering, VMTemplateVO template, ExcludeList avoid, List 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. + // Shuffle this so that we don't check the hosts in the same order. Collections.shuffle(hosts); - }else if(_allocationAlgorithm.equals("userdispersing")){ + } else if (_allocationAlgorithm.equals("userdispersing")) { hosts = reorderHostsByNumberOfVms(plan, hosts, account); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("FirstFitAllocator has " + hosts.size() + " hosts to check for allocation: "+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 @@ -243,7 +259,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { hosts = prioritizeHosts(template, hosts); if (s_logger.isDebugEnabled()) { - s_logger.debug("Found " + hosts.size() + " hosts for allocation after prioritization: "+ hosts); + s_logger.debug("Found " + hosts.size() + " hosts for allocation after prioritization: " + hosts); } if (s_logger.isDebugEnabled()) { @@ -252,36 +268,38 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { List suitableHosts = new ArrayList(); - for (HostVO host : hosts) { - if(suitableHosts.size() == returnUpTo){ - break; - } + 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"); + 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 (_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"); + 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"); } continue; } boolean numCpusGood = host.getCpus().intValue() >= offering.getCpu(); boolean cpuFreqGood = host.getSpeed().intValue() >= offering.getSpeed(); - int cpu_requested = offering.getCpu() * offering.getSpeed(); - long ram_requested = offering.getRamSize() * 1024L * 1024L; + int cpu_requested = offering.getCpu() * offering.getSpeed(); + long ram_requested = offering.getRamSize() * 1024L * 1024L; Cluster cluster = _clusterDao.findById(host.getClusterId()); - ClusterDetailsVO clusterDetailsCpuOvercommit = _clusterDetailsDao.findDetail(cluster.getId(),"cpuOvercommitRatio"); - ClusterDetailsVO clusterDetailsRamOvercommmt = _clusterDetailsDao.findDetail(cluster.getId(),"memoryOvercommitRatio"); + ClusterDetailsVO clusterDetailsCpuOvercommit = _clusterDetailsDao.findDetail(cluster.getId(), "cpuOvercommitRatio"); + ClusterDetailsVO clusterDetailsRamOvercommmt = _clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio"); Float cpuOvercommitRatio = Float.parseFloat(clusterDetailsCpuOvercommit.getValue()); Float memoryOvercommitRatio = Float.parseFloat(clusterDetailsRamOvercommmt.getValue()); - boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false,cpuOvercommitRatio,memoryOvercommitRatio, considerReservedCapacity); + boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, + considerReservedCapacity); if (numCpusGood && cpuFreqGood && hostHasCapacity) { if (s_logger.isDebugEnabled()) { @@ -297,14 +315,14 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { } if (s_logger.isDebugEnabled()) { - s_logger.debug("Host Allocator returning "+suitableHosts.size() +" suitable hosts"); + s_logger.debug("Host Allocator returning " + suitableHosts.size() + " suitable hosts"); } return suitableHosts; } - private List reorderHostsByNumberOfVms(DeploymentPlan plan, List hosts, Account account) { - if(account == null){ + private List reorderHostsByNumberOfVms(DeploymentPlan plan, List hosts, Account account) { + if (account == null) { return hosts; } long dcId = plan.getDataCenterId(); @@ -313,20 +331,20 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { List 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); + 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 hostMap = new HashMap(); - for (HostVO host : hosts) { + Map hostMap = new HashMap(); + for (Host host : hosts) { hostMap.put(host.getId(), host); } List matchingHostIds = new ArrayList(hostMap.keySet()); hostIdsByVmCount.retainAll(matchingHostIds); - List reorderedHosts = new ArrayList(); - for(Long id: hostIdsByVmCount){ + List reorderedHosts = new ArrayList(); + for (Long id : hostIdsByVmCount) { reorderedHosts.add(hostMap.get(id)); } @@ -340,133 +358,133 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { return true; } - protected List prioritizeHosts(VMTemplateVO template, List hosts) { - if (template == null) { - return hosts; - } + protected List prioritizeHosts(VMTemplateVO template, List hosts) { + if (template == null) { + return hosts; + } - // Determine the guest OS category of the template - String templateGuestOSCategory = getTemplateGuestOSCategory(template); + // Determine the guest OS category of the template + String templateGuestOSCategory = getTemplateGuestOSCategory(template); - List prioritizedHosts = new ArrayList(); - List noHvmHosts = new ArrayList(); + List prioritizedHosts = new ArrayList(); + List noHvmHosts = new ArrayList(); - // If a template requires HVM and a host doesn't support HVM, remove it from consideration - List hostsToCheck = new ArrayList(); - if (template.isRequiresHvm()) { - for (HostVO host : hosts) { - if (hostSupportsHVM(host)) { - hostsToCheck.add(host); - } else { - noHvmHosts.add(host); - } - } - } else { - hostsToCheck.addAll(hosts); - } + // If a template requires HVM and a host doesn't support HVM, remove it from consideration + List hostsToCheck = new ArrayList(); + if (template.isRequiresHvm()) { + for (Host host : hosts) { + if (hostSupportsHVM(host)) { + hostsToCheck.add(host); + } else { + noHvmHosts.add(host); + } + } + } else { + hostsToCheck.addAll(hosts); + } - if (s_logger.isDebugEnabled()) { - if (noHvmHosts.size() > 0) { - s_logger.debug("Not considering hosts: " + noHvmHosts + " to deploy template: " + template +" as they are not HVM enabled"); - } - } - // If a host is tagged with the same guest OS category as the template, move it to a high priority list - // If a host is tagged with a different guest OS category than the template, move it to a low priority list - List highPriorityHosts = new ArrayList(); - List lowPriorityHosts = new ArrayList(); - for (HostVO host : hostsToCheck) { - String hostGuestOSCategory = getHostGuestOSCategory(host); - if (hostGuestOSCategory == null) { - continue; - } else if (templateGuestOSCategory.equals(hostGuestOSCategory)) { - highPriorityHosts.add(host); - } else { - lowPriorityHosts.add(host); - } - } + if (s_logger.isDebugEnabled()) { + if (noHvmHosts.size() > 0) { + s_logger.debug("Not considering hosts: " + noHvmHosts + " to deploy template: " + template + " as they are not HVM enabled"); + } + } + // If a host is tagged with the same guest OS category as the template, move it to a high priority list + // If a host is tagged with a different guest OS category than the template, move it to a low priority list + List highPriorityHosts = new ArrayList(); + List lowPriorityHosts = new ArrayList(); + for (Host host : hostsToCheck) { + String hostGuestOSCategory = getHostGuestOSCategory(host); + if (hostGuestOSCategory == null) { + continue; + } else if (templateGuestOSCategory.equals(hostGuestOSCategory)) { + highPriorityHosts.add(host); + } else { + lowPriorityHosts.add(host); + } + } - hostsToCheck.removeAll(highPriorityHosts); - hostsToCheck.removeAll(lowPriorityHosts); + hostsToCheck.removeAll(highPriorityHosts); + hostsToCheck.removeAll(lowPriorityHosts); - // Prioritize the remaining hosts by HVM capability - for (HostVO host : hostsToCheck) { - if (!template.isRequiresHvm() && !hostSupportsHVM(host)) { - // Host and template both do not support hvm, put it as first consideration - prioritizedHosts.add(0, host); - } else { - // Template doesn't require hvm, but the machine supports it, make it last for consideration - prioritizedHosts.add(host); - } - } + // Prioritize the remaining hosts by HVM capability + for (Host host : hostsToCheck) { + if (!template.isRequiresHvm() && !hostSupportsHVM(host)) { + // Host and template both do not support hvm, put it as first consideration + prioritizedHosts.add(0, host); + } else { + // Template doesn't require hvm, but the machine supports it, make it last for consideration + prioritizedHosts.add(host); + } + } - // Merge the lists - prioritizedHosts.addAll(0, highPriorityHosts); - prioritizedHosts.addAll(lowPriorityHosts); + // Merge the lists + prioritizedHosts.addAll(0, highPriorityHosts); + prioritizedHosts.addAll(lowPriorityHosts); - return prioritizedHosts; + return prioritizedHosts; } - protected boolean hostSupportsHVM(HostVO host) { - if ( !_checkHvm ) { + protected boolean hostSupportsHVM(Host host) { + if (!_checkHvm) { return true; } - // Determine host capabilities - String caps = host.getCapabilities(); + // Determine host capabilities + String caps = host.getCapabilities(); - if (caps != null) { + if (caps != null) { String[] tokens = caps.split(","); for (String token : tokens) { - if (token.contains("hvm")) { - return true; - } + if (token.contains("hvm")) { + return true; + } } - } + } - return false; + return false; } - protected String getHostGuestOSCategory(HostVO host) { - DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id"); - if (hostDetail != null) { - String guestOSCategoryIdString = hostDetail.getValue(); - long guestOSCategoryId; + protected String getHostGuestOSCategory(Host host) { + DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id"); + if (hostDetail != null) { + String guestOSCategoryIdString = hostDetail.getValue(); + long guestOSCategoryId; - try { - guestOSCategoryId = Long.parseLong(guestOSCategoryIdString); - } catch (Exception e) { - return null; - } + try { + guestOSCategoryId = Long.parseLong(guestOSCategoryIdString); + } catch (Exception e) { + return null; + } - GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); + GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); - if (guestOSCategory != null) { - return guestOSCategory.getName(); - } else { - return null; - } - } else { - return null; - } + if (guestOSCategory != null) { + return guestOSCategory.getName(); + } else { + return null; + } + } else { + return null; + } } protected String getTemplateGuestOSCategory(VMTemplateVO template) { - long guestOSId = template.getGuestOSId(); - GuestOSVO guestOS = _guestOSDao.findById(guestOSId); - long guestOSCategoryId = guestOS.getCategoryId(); - GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); - return guestOSCategory.getName(); + long guestOSId = template.getGuestOSId(); + GuestOSVO guestOS = _guestOSDao.findById(guestOSId); + long guestOSCategoryId = guestOS.getCategoryId(); + GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId); + return guestOSCategory.getName(); } @Override public boolean configure(String name, Map params) throws ConfigurationException { - if (_configDao != null) { - Map configs = _configDao.getConfiguration(params); + if (_configDao != null) { + Map configs = _configDao.getConfiguration(params); String opFactor = configs.get("cpu.overprovisioning.factor"); _factor = NumbersUtil.parseFloat(opFactor, 1); String allocationAlgorithm = configs.get("vm.allocation.algorithm"); if (allocationAlgorithm != null) { - _allocationAlgorithm = allocationAlgorithm; + _allocationAlgorithm = allocationAlgorithm; } String value = configs.get("xen.check.hvm"); _checkHvm = value == null ? true : Boolean.parseBoolean(value); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java index 890c047de50..3c69694346c 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java @@ -23,13 +23,10 @@ import java.util.Map; import javax.ejb.Local; import javax.inject.Inject; -import org.springframework.stereotype.Component; - import com.cloud.agent.manager.allocator.HostAllocator; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.host.Host; -import com.cloud.host.HostVO; import com.cloud.host.Host.Type; import com.cloud.host.dao.HostDao; import com.cloud.offering.ServiceOffering; @@ -37,7 +34,6 @@ import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; -@Component @Local(value={HostAllocator.class}) public class TestingAllocator extends AdapterBase implements HostAllocator { @Inject HostDao _hostDao; @@ -53,7 +49,7 @@ public class TestingAllocator extends AdapterBase implements HostAllocator { @Override public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, - ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { + ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { return allocateTo(vmProfile, plan, type, avoid, returnUpTo, considerReservedCapacity); } @@ -61,7 +57,7 @@ public class TestingAllocator extends AdapterBase implements HostAllocator { public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) { List availableHosts = new ArrayList(); - Host host = null; + Host host = null; if (type == Host.Type.Routing && _routingHost != null) { host = _hostDao.findById(_routingHost); } else if (type == Host.Type.Storage && _storageHost != null) { diff --git a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java index af4e4110913..82548c916d4 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -34,15 +34,12 @@ import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenter; -import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.Pod; import com.cloud.dc.dao.HostPodDao; import com.cloud.offering.ServiceOffering; -import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.VolumeVO; -import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VMTemplatePoolDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.template.VirtualMachineTemplate; @@ -85,7 +82,7 @@ public class UserConcentratedAllocator extends AdapterBase implements PodAllocat private int _secondsToSkipDestroyedVMs = 0; @Override - public Pair allocateTo(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO zone, long accountId, + public Pair allocateTo(VirtualMachineTemplate template, ServiceOffering offering, DataCenter zone, long accountId, Set avoids) { long zoneId = zone.getId(); List podsInZone = _podDao.listByDataCenterId(zoneId); @@ -138,12 +135,12 @@ public class UserConcentratedAllocator extends AdapterBase implements PodAllocat // If the pod has VMs or volumes in it, return this pod List vmsInPod = _vmDao.listByAccountAndPod(accountId, pod.getId()); if (!vmsInPod.isEmpty()) { - return new Pair(pod, podHostCandidates.get(podId)); + return new Pair(pod, podHostCandidates.get(podId)); } List volumesInPod = _volumeDao.findByAccountAndPod(accountId, pod.getId()); if (!volumesInPod.isEmpty()) { - return new Pair(pod, podHostCandidates.get(podId)); + return new Pair(pod, podHostCandidates.get(podId)); } availablePods.add(pod); @@ -158,7 +155,7 @@ public class UserConcentratedAllocator extends AdapterBase implements PodAllocat int next = _rand.nextInt(availablePods.size()); HostPodVO selectedPod = availablePods.get(next); s_logger.debug("Found pod " + selectedPod.getName() + " in zone " + zone.getName()); - return new Pair(selectedPod, podHostCandidates.get(selectedPod.getId())); + return new Pair(selectedPod, podHostCandidates.get(selectedPod.getId())); } } @@ -319,25 +316,6 @@ public class UserConcentratedAllocator extends AdapterBase implements PodAllocat _secondsToSkipStoppedVMs = NumbersUtil.parseInt(stoppedValue, 86400); _secondsToSkipDestroyedVMs = NumbersUtil.parseInt(destroyedValue, 0); - /* - * ComponentLocator locator = ComponentLocator.getCurrentLocator(); _vmDao = locator.getDao(UserVmDao.class); if (_vmDao - * == null) { throw new ConfigurationException("Unable to find UserVMDao."); } - * - * _volumeDao = locator.getDao(VolumeDao.class); if (_volumeDao == null) { throw new - * ConfigurationException("Unable to find VolumeDao."); } - * - * _templateHostDao = locator.getDao(VMTemplateHostDao.class); if (_templateHostDao == null) { throw new - * ConfigurationException("Unable to get template host dao."); } - * - * _templatePoolDao = locator.getDao(VMTemplatePoolDao.class); if (_templatePoolDao == null) { throw new - * ConfigurationException("Unable to get template pool dao."); } - * - * _podDao = locator.getDao(HostPodDao.class); if (_podDao == null) { throw new - * ConfigurationException("Unable to find HostPodDao."); } - * - * _capacityDao = locator.getDao(CapacityDao.class); if (_capacityDao == null) { throw new - * ConfigurationException("Unable to retrieve " + CapacityDao.class); } - */ return true; } diff --git a/server/src/com/cloud/capacity/CapacityManager.java b/server/src/com/cloud/capacity/CapacityManager.java index ab02e77ac19..ded1f806b4a 100755 --- a/server/src/com/cloud/capacity/CapacityManager.java +++ b/server/src/com/cloud/capacity/CapacityManager.java @@ -19,7 +19,6 @@ package com.cloud.capacity; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import com.cloud.host.Host; -import com.cloud.host.HostVO; import com.cloud.storage.VMTemplateVO; import com.cloud.utils.component.Manager; import com.cloud.vm.VirtualMachine; @@ -46,7 +45,7 @@ public interface CapacityManager extends Manager { /** * @param pool storage pool - * @param templateForVmCreation template that will be used for vm creation + * @param templateForVmCreation template that will be used for vm creation * @return total allocated capacity for the storage pool */ long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation); @@ -56,5 +55,5 @@ public interface CapacityManager extends Manager { * @param host the host to be checked * @return true if the count of host's running VMs >= hypervisor limit */ - boolean checkIfHostReachMaxGuestLimit(HostVO host); + boolean checkIfHostReachMaxGuestLimit(Host host); } diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index b2f10f298a0..108de3bb077 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -27,11 +27,12 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.PublishScope; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -906,7 +907,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, } @Override - public boolean checkIfHostReachMaxGuestLimit(HostVO host) { + public boolean checkIfHostReachMaxGuestLimit(Host host) { Long vmCount = _vmDao.countRunningByHostId(host.getId()); HypervisorType hypervisorType = host.getHypervisorType(); String hypervisorVersion = host.getHypervisorVersion(); diff --git a/server/src/com/cloud/resource/ResourceManager.java b/server/src/com/cloud/resource/ResourceManager.java index b0ab9269529..e35e89a20c2 100755 --- a/server/src/com/cloud/resource/ResourceManager.java +++ b/server/src/com/cloud/resource/ResourceManager.java @@ -24,6 +24,7 @@ import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; import com.cloud.dc.PodCluster; import com.cloud.exception.AgentUnavailableException; import com.cloud.host.Host; @@ -42,7 +43,7 @@ import com.cloud.utils.fsm.NoTransitionException; * ResourceManager manages how physical resources are organized within the * CloudStack. It also manages the life cycle of the physical resources. */ -public interface ResourceManager extends ResourceService{ +public interface ResourceManager extends ResourceService { /** * Register a listener for different types of resource life cycle events. * There can only be one type of listener per type of host. @@ -51,69 +52,70 @@ public interface ResourceManager extends ResourceService{ * @param listener the listener to notify. */ public void registerResourceEvent(Integer event, ResourceListener listener); - + public void unregisterResourceEvent(ResourceListener listener); - + /** * * @param name of adapter * @param adapter - * @param hates, a list of names which will be eliminated by this adapter. Especially for the case where + * @param hates, a list of names which will be eliminated by this adapter. Especially for the case where * can be only one adapter responds to an event, e.g. startupCommand */ public void registerResourceStateAdapter(String name, ResourceStateAdapter adapter); - + public void unregisterResourceStateAdapter(String name); - - public Host createHostAndAgent(Long hostId, ServerResource resource, Map details, boolean old, List hostTags, - boolean forRebalance); - - public Host addHost(long zoneId, ServerResource resource, Type hostType, Map hostDetails); - - public HostVO createHostVOForConnectedAgent(StartupCommand[] cmds); - - public void checkCIDR(HostPodVO pod, DataCenterVO dc, String serverPrivateIP, String serverPrivateNetmask); - - public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, HypervisorType hyType, Map details, List hostTags); - - public void deleteRoutingHost(HostVO host, boolean isForced, boolean forceDestroyStorage) throws UnableDeleteHostException; - + + public Host createHostAndAgent(Long hostId, ServerResource resource, Map details, boolean old, List hostTags, + boolean forRebalance); + + public Host addHost(long zoneId, ServerResource resource, Type hostType, Map hostDetails); + + public HostVO createHostVOForConnectedAgent(StartupCommand[] cmds); + + public void checkCIDR(HostPodVO pod, DataCenterVO dc, String serverPrivateIP, String serverPrivateNetmask); + + public HostVO fillRoutingHostVO(HostVO host, StartupRoutingCommand ssCmd, HypervisorType hyType, Map details, List hostTags); + + public void deleteRoutingHost(HostVO host, boolean isForced, boolean forceDestroyStorage) throws UnableDeleteHostException; + public boolean executeUserRequest(long hostId, ResourceState.Event event) throws AgentUnavailableException; - boolean resourceStateTransitTo(Host host, Event event, long msId) throws NoTransitionException; + boolean resourceStateTransitTo(Host host, Event event, long msId) throws NoTransitionException; - boolean umanageHost(long hostId); + boolean umanageHost(long hostId); + + boolean maintenanceFailed(long hostId); + + public boolean maintain(final long hostId) throws AgentUnavailableException; - boolean maintenanceFailed(long hostId); - - public boolean maintain(final long hostId) throws AgentUnavailableException; - @Override public boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage); - + public List findDirectlyConnectedHosts(); - + public List listAllUpAndEnabledHosts(Host.Type type, Long clusterId, Long podId, long dcId); - + public List listAllHostsInCluster(long clusterId); - + public List listHostsInClusterByStatus(long clusterId, Status status); - + public List listAllUpAndEnabledHostsInOneZoneByType(Host.Type type, long dcId); + public List listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType type, long dcId); - + public List listAllHostsInOneZoneByType(Host.Type type, long dcId); - + public List listAllHostsInAllZonesByType(Type type); - + public List listAvailHypervisorInZone(Long hostId, Long zoneId); - + public HostVO findHostByGuid(String guid); - + public HostVO findHostByName(String name); - + public List listHostsByNameLike(String name); - + /** * Find a pod based on the user id, template, and data center. * @@ -122,25 +124,25 @@ public interface ResourceManager extends ResourceService{ * @param userId * @return */ - Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set avoids); - + Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set avoids); + HostStats getHostStatistics(long hostId); - + Long getGuestOSCategoryId(long hostId); - + String getHostTags(long hostId); - + List listByDataCenter(long dcId); - List listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId); + List listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId); - HypervisorType getDefaultHypervisor(long zoneId); + HypervisorType getDefaultHypervisor(long zoneId); - HypervisorType getAvailableHypervisor(long zoneId); + HypervisorType getAvailableHypervisor(long zoneId); Discoverer getMatchingDiscover(HypervisorType hypervisorType); - List findHostByGuid(long dcId, String guid); + List findHostByGuid(long dcId, String guid); /** * @param type diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index a0ea54e1e60..054ac40e01b 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -30,7 +30,9 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.dc.*; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; @@ -48,8 +50,6 @@ import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd; import org.apache.cloudstack.region.dao.RegionDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager.TapAgentsAction; @@ -78,9 +78,12 @@ import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterIpAddressVO; import com.cloud.dc.DataCenterVO; +import com.cloud.dc.DedicatedResourceVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; import com.cloud.dc.PodCluster; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.ClusterVSMMapDao; @@ -164,7 +167,6 @@ import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; -import com.cloud.dc.DataCenter.NetworkType; @Component @Local({ ResourceManager.class, ResourceService.class }) @@ -634,12 +636,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Override public S3 discoverS3(final AddS3Cmd cmd) throws DiscoveryException { - return this._s3Mgr.addS3(cmd); + return _s3Mgr.addS3(cmd); } @Override public List listS3s(final ListS3sCmd cmd) { - return this._s3Mgr.listS3s(cmd); + return _s3Mgr.listS3s(cmd); } @@ -704,7 +706,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, // already have a lot of information // in cluster object, to simplify user input, we will construct // neccessary information here - Map clusterDetails = this._clusterDetailsDao.findDetails(clusterId); + Map clusterDetails = _clusterDetailsDao.findDetails(clusterId); username = clusterDetails.get("username"); assert (username != null); @@ -1971,7 +1973,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, Map details = hostDetails; String guid = details.get("guid"); - List currentHosts = this.listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); + List currentHosts = listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId); for (HostVO currentHost : currentHosts) { if (currentHost.getGuid().equals(guid)) { return currentHost; @@ -2294,7 +2296,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, return doUpdateHostPassword(cmd.getHostId()); } else { // get agents for the cluster - List hosts = this.listAllHostsInCluster(cmd.getClusterId()); + List hosts = listAllHostsInCluster(cmd.getClusterId()); for (HostVO h : hosts) { try { /* @@ -2468,10 +2470,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } @Override - public Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, + public Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set avoids) { for (PodAllocator allocator : _podAllocators) { - final Pair pod = allocator.allocateTo(template, offering, dc, accountId, avoids); + final Pair pod = allocator.allocateTo(template, offering, dc, accountId, avoids); if (pod != null) { return pod; } diff --git a/server/src/com/cloud/storage/StorageManager.java b/server/src/com/cloud/storage/StorageManager.java index df690929f25..af4e8c2a815 100755 --- a/server/src/com/cloud/storage/StorageManager.java +++ b/server/src/com/cloud/storage/StorageManager.java @@ -30,13 +30,12 @@ import com.cloud.agent.api.StoragePoolInfo; import com.cloud.agent.manager.Commands; import com.cloud.capacity.CapacityVO; import com.cloud.dc.DataCenterVO; -import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; import com.cloud.exception.ConnectionException; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.service.ServiceOfferingVO; -import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.Storage.ImageFormat; import com.cloud.utils.Pair; import com.cloud.vm.DiskProfile; @@ -108,7 +107,7 @@ public interface StorageManager extends StorageService { boolean registerHostListener(String providerUuid, HypervisorHostListener listener); StoragePool findStoragePool(DiskProfile dskCh, DataCenterVO dc, - HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm, + Pod pod, Long clusterId, Long hostId, VMInstanceVO vm, Set avoid); void connectHostToSharedPool(long hostId, long poolId) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 9ddcb7866fd..d9ef853a743 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -41,6 +41,9 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd; import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd; import org.apache.cloudstack.api.command.admin.storage.CreateCacheStoreCmd; @@ -80,8 +83,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -103,7 +104,7 @@ import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenterVO; -import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.deploy.DataCenterDeployment; @@ -302,7 +303,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C private int _customDiskOfferingMinSize = 1; private int _customDiskOfferingMaxSize = 1024; - private Map hostListeners = new HashMap(); + private final Map hostListeners = new HashMap(); private boolean _recreateSystemVmEnabled; @@ -399,7 +400,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } @Override - public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO dc, HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm, + public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO dc, Pod pod, Long clusterId, Long hostId, VMInstanceVO vm, final Set avoid) { VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); @@ -413,7 +414,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C final List poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1); if (poolList != null && !poolList.isEmpty()) { - return (StoragePool) this.dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary); + return (StoragePool) dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary); } } return null; @@ -604,7 +605,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), "", pInfo.getUuid()); } } - DataStoreProvider provider = this.dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider(); + DataStoreProvider provider = dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider(); DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle(); if (pool == null) { Map params = new HashMap(); @@ -808,7 +809,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C // force expunge non-destroyed volumes List vols = _volsDao.listVolumesToBeDestroyed(); for (VolumeVO vol : vols) { - AsyncCallFuture future = this.volService.expungeVolumeAsync(this.volFactory.getVolume(vol.getId())); + AsyncCallFuture future = volService.expungeVolumeAsync(volFactory.getVolume(vol.getId())); try { future.get(); } catch (InterruptedException e) { @@ -847,7 +848,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C @Override public void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException { - StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary); + StoragePool pool = (StoragePool) dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary); assert (pool.isShared()) : "Now, did you actually read the name of this method?"; s_logger.debug("Adding pool " + pool.getName() + " to host " + hostId); @@ -1032,7 +1033,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C for (VolumeVO vol : vols) { try { - this.volService.expungeVolumeAsync(this.volFactory.getVolume(vol.getId())); + volService.expungeVolumeAsync(volFactory.getVolume(vol.getId())); } catch (Exception e) { s_logger.warn("Unable to destroy " + vol.getId(), e); @@ -1107,11 +1108,11 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C // so here we don't need to issue DeleteCommand to resource anymore, only need to remove db entry. try { // Cleanup templates in template_store_ref - List imageStores = this.dataStoreMgr.getImageStoresByScope(new ZoneScope(null)); + List imageStores = dataStoreMgr.getImageStoresByScope(new ZoneScope(null)); for (DataStore store : imageStores) { try { long storeId = store.getId(); - List destroyedTemplateStoreVOs = this._templateStoreDao.listDestroyed(storeId); + List destroyedTemplateStoreVOs = _templateStoreDao.listDestroyed(storeId); s_logger.debug("Secondary storage garbage collector found " + destroyedTemplateStoreVOs.size() + " templates to cleanup on template_store_ref for store: " + store.getName()); for (TemplateDataStoreVO destroyedTemplateStoreVO : destroyedTemplateStoreVOs) { @@ -1311,7 +1312,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C if (hostId != null) { hosts.add(hostId); } else { - List stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId)); + List stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId)); if (stores != null) { for (DataStore store : stores) { hosts.add(store.getId()); @@ -1699,16 +1700,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C if (((ImageStoreProvider) storeProvider).needDownloadSysTemplate()) { // trigger system vm template download - this._imageSrv.downloadBootstrapSysTemplate(store); + _imageSrv.downloadBootstrapSysTemplate(store); } else { // populate template_store_ref table - this._imageSrv.addSystemVMTemplatesToSecondary(store); + _imageSrv.addSystemVMTemplatesToSecondary(store); } // associate builtin template with zones associated with this image // store - this.associateCrosszoneTemplatesToZone(dcId); + associateCrosszoneTemplatesToZone(dcId); return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image); } @@ -1765,7 +1766,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } // search if there are user templates stored on this image store, excluding system, builtin templates - List templates = this._templateViewDao.listActiveTemplates(storeId); + List templates = _templateViewDao.listActiveTemplates(storeId); if (templates != null && templates.size() > 0) { throw new InvalidParameterValueException("Cannot delete image store with active templates backup!"); } diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index d90e79805c8..d63e6316f68 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -31,6 +31,7 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -41,10 +42,9 @@ import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd; import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd; import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.UpdateVolumeCmd; import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd; - -import com.cloud.storage.dao.*; -import org.apache.cloudstack.api.command.user.volume.*; +import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; @@ -55,7 +55,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; -import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; @@ -73,7 +72,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; -import org.apache.commons.lang.StringUtils; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -99,6 +97,7 @@ import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; @@ -142,6 +141,7 @@ import com.cloud.storage.dao.VMTemplatePoolDao; import com.cloud.storage.dao.VMTemplateS3Dao; import com.cloud.storage.dao.VMTemplateSwiftDao; import com.cloud.storage.dao.VolumeDao; +import com.cloud.storage.dao.VolumeDetailsDao; import com.cloud.storage.download.DownloadMonitor; import com.cloud.storage.s3.S3Manager; import com.cloud.storage.secondary.SecondaryStorageVmManager; @@ -154,8 +154,8 @@ import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.ResourceLimitService; -import com.cloud.user.VmDiskStatisticsVO; import com.cloud.user.UserContext; +import com.cloud.user.VmDiskStatisticsVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.user.dao.VmDiskStatisticsDao; @@ -534,8 +534,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { StoragePool pool = null; Set podsToAvoid = new HashSet(); - Pair pod = null; - + Pair pod = null; DiskOfferingVO diskOffering = _diskOfferingDao .findByIdIncludingRemoved(volume.getDiskOfferingId()); @@ -544,14 +543,12 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { snapshot.getHypervisorType()); // Determine what pod to store the volume in - while ((pod = _resourceMgr.findPod(null, null, dc, account.getId(), - podsToAvoid)) != null) { + while ((pod = _resourceMgr.findPod(null, null, dc, account.getId(), podsToAvoid)) != null) { podsToAvoid.add(pod.first().getId()); // Determine what storage pool to store the volume in while ((pool = storageMgr.findStoragePool(dskCh, dc, pod.first(), null, null, null, poolsToAvoid)) != null) { break; - } } @@ -1415,7 +1412,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { vol.setDeviceId(1l); } - vol.setFormat(this.getSupportedImageFormatForCluster(vm.getHypervisorType())); + vol.setFormat(getSupportedImageFormatForCluster(vm.getHypervisorType())); vol = _volsDao.persist(vol); // Save usage event and update resource count for user vm volumes @@ -1446,7 +1443,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), size, offering.getMinIops(), offering.getMaxIops(), null); - vol.setFormat(this.getSupportedImageFormatForCluster(template.getHypervisorType())); + vol.setFormat(getSupportedImageFormatForCluster(template.getHypervisorType())); if (vm != null) { vol.setInstanceId(vm.getId()); } @@ -1558,10 +1555,10 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } } - VolumeVO volVO = this._volsDao.findById(vol.getId()); - volVO.setFormat(this.getSupportedImageFormatForCluster(rootDiskHyperType)); - this._volsDao.update(volVO.getId(), volVO); - return this.volFactory.getVolume(volVO.getId()); + VolumeVO volVO = _volsDao.findById(vol.getId()); + volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType)); + _volsDao.update(volVO.getId(), volVO); + return volFactory.getVolume(volVO.getId()); } private boolean needMoveVolume(VolumeVO rootVolumeOfVm, VolumeInfo volume) { @@ -2768,15 +2765,15 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { // Clean up code to remove all those previous uploadVO and uploadMonitor code. Previous code is trying to fake an async operation purely in // db table with uploadVO and async_job entry, but internal implementation is actually synchronous. - StoragePool srcPool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId()); - ImageStoreEntity secStore = (ImageStoreEntity) this.dataStoreMgr.getImageStore(zoneId); + StoragePool srcPool = (StoragePool) dataStoreMgr.getPrimaryDataStore(volume.getPoolId()); + ImageStoreEntity secStore = (ImageStoreEntity) dataStoreMgr.getImageStore(zoneId); String secondaryStorageURL = secStore.getUri(); - String value = this._configDao.getValue(Config.CopyVolumeWait.toString()); + String value = _configDao.getValue(Config.CopyVolumeWait.toString()); int copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue())); // Copy volume from primary to secondary storage - VolumeInfo srcVol = this.volFactory.getVolume(volume.getId()); - AsyncCallFuture cvAnswer = this.volService.copyVolume(srcVol, secStore); + VolumeInfo srcVol = volFactory.getVolume(volume.getId()); + AsyncCallFuture cvAnswer = volService.copyVolume(srcVol, secStore); // Check if you got a valid answer. VolumeApiResult cvResult = null; try { diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index a1c52aa9dea..18cff80aff5 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -26,38 +26,42 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; -import org.apache.cloudstack.api.command.admin.host.*; -import org.apache.cloudstack.api.command.admin.storage.*; -import org.apache.cloudstack.api.command.admin.swift.*; +import org.apache.cloudstack.api.command.admin.host.AddHostCmd; +import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd; +import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd; +import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd; +import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd; +import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd; +import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd; +import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; +import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; +import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; +import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; - import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; +import com.cloud.dc.Pod; import com.cloud.dc.PodCluster; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.DiscoveryException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceInUseException; import com.cloud.host.Host; +import com.cloud.host.Host.Type; import com.cloud.host.HostStats; import com.cloud.host.HostVO; import com.cloud.host.Status; -import com.cloud.host.Host.Type; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.org.Cluster; import com.cloud.resource.ResourceState.Event; import com.cloud.service.ServiceOfferingVO; -import com.cloud.storage.ImageStore; import com.cloud.storage.S3; import com.cloud.storage.Swift; import com.cloud.template.VirtualMachineTemplate; import com.cloud.utils.Pair; import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.component.Manager; - - import com.cloud.utils.fsm.NoTransitionException; @Local(value = {ResourceManager.class}) @@ -470,7 +474,7 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana * @see com.cloud.resource.ResourceManager#findPod(com.cloud.template.VirtualMachineTemplate, com.cloud.service.ServiceOfferingVO, com.cloud.dc.DataCenterVO, long, java.util.Set) */ @Override - public Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, + public Pair findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set avoids) { // TODO Auto-generated method stub return null;