diff --git a/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java b/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java index b3c7b2b302e..9b7671b46e0 100644 --- a/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java +++ b/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java @@ -94,168 +94,171 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement DataCenter dc = _dcDao.findById(vm.getDataCenterId()); List resourceList = new ArrayList(); - for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { - if (vmGroupMapping != null) { + if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) { + + for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { + if (vmGroupMapping != null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + + "of type 'ExplicitDedication' for VM Id: " + vm.getId()); + } + + long affinityGroupId = vmGroupMapping.getAffinityGroupId(); + + // List dr = + // _dedicatedDao.listByAccountId(accountId); + // List drOfDomain = + // searchInDomainResources(domainId); + // List drOfParentDomain = + // searchInParentDomainResources(domainId); + + List dr = _dedicatedDao.listByAffinityGroupId(affinityGroupId); + resourceList.addAll(dr); + + } + } + + boolean canUse = false; + + if (plan.getHostId() != null) { + HostVO host = _hostDao.findById(plan.getHostId()); + ClusterVO clusterofHost = _clusterDao.findById(host.getClusterId()); + HostPodVO podOfHost = _podDao.findById(host.getPodId()); + DataCenterVO zoneOfHost = _dcDao.findById(host.getDataCenterId()); + if (resourceList != null && resourceList.size() != 0) { + for (DedicatedResourceVO resource : resourceList) { + if ((resource.getHostId() != null && resource.getHostId() == plan.getHostId()) + || (resource.getClusterId() != null && resource.getClusterId() == clusterofHost.getId()) + || (resource.getPodId() != null && resource.getPodId() == podOfHost.getId()) + || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfHost + .getId())) { + canUse = true; + } + } + } + if (!canUse) { + throw new CloudRuntimeException("Cannot use this host " + host.getName() + + " for explicit dedication"); + } + } else if (plan.getClusterId() != null) { + ClusterVO cluster = _clusterDao.findById(plan.getClusterId()); + HostPodVO podOfCluster = _podDao.findById(cluster.getPodId()); + DataCenterVO zoneOfCluster = _dcDao.findById(cluster.getDataCenterId()); + List hostToUse = new ArrayList(); + // check whether this cluster or its pod is dedicated + if (resourceList != null && resourceList.size() != 0) { + for (DedicatedResourceVO resource : resourceList) { + if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) + || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) + || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster + .getId())) { + canUse = true; + } + + // check for all dedicated host; if it belongs to this + // cluster + if (!canUse) { + if (resource.getHostId() != null) { + HostVO dHost = _hostDao.findById(resource.getHostId()); + if (dHost.getClusterId() == cluster.getId()) { + hostToUse.add(dHost); + } + } + } + + } + } + + if (hostToUse.isEmpty() && !canUse) { + throw new CloudRuntimeException("Cannot use this cluster " + cluster.getName() + + " for explicit dedication"); + } + + if (hostToUse != null && hostToUse.size() != 0) { + // add other non-dedicated hosts to avoid list + List hostList = _hostDao.findByClusterId(cluster.getId()); + for (HostVO host : hostList) { + if (!hostToUse.contains(host)) { + avoid.addHost(host.getId()); + } + } + } + + } else if (plan.getPodId() != null) { + HostPodVO pod = _podDao.findById(plan.getPodId()); + DataCenterVO zoneOfPod = _dcDao.findById(pod.getDataCenterId()); + List clustersToUse = new ArrayList(); + List hostsToUse = new ArrayList(); + // check whether this cluster or its pod is dedicated + if (resourceList != null && resourceList.size() != 0) { + for (DedicatedResourceVO resource : resourceList) { + if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) + || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod + .getId())) { + canUse = true; + } + + // check for all dedicated cluster/host; if it belongs + // to + // this pod + if (!canUse) { + if (resource.getClusterId() != null) { + ClusterVO dCluster = _clusterDao.findById(resource.getClusterId()); + if (dCluster.getPodId() == pod.getId()) { + clustersToUse.add(dCluster); + } + } + if (resource.getHostId() != null) { + HostVO dHost = _hostDao.findById(resource.getHostId()); + if (dHost.getPodId() == pod.getId()) { + hostsToUse.add(dHost); + } + } + } + + } + } + + if (hostsToUse.isEmpty() && clustersToUse.isEmpty() && !canUse) { + throw new CloudRuntimeException("Cannot use this pod " + pod.getName() + " for explicit dedication"); + } + + if (clustersToUse != null && clustersToUse.size() != 0) { + // add other non-dedicated clusters to avoid list + List clusterList = _clusterDao.listByPodId(pod.getId()); + for (ClusterVO cluster : clusterList) { + if (!clustersToUse.contains(cluster)) { + avoid.addCluster(cluster.getId()); + } + } + } + + if (hostsToUse != null && hostsToUse.size() != 0) { + // add other non-dedicated hosts to avoid list + List hostList = _hostDao.findByPodId(pod.getId()); + for (HostVO host : hostList) { + if (!hostsToUse.contains(host)) { + avoid.addHost(host.getId()); + } + } + } + + } else { + // check all resources under this zone + if (resourceList != null && resourceList.size() != 0) { + avoid = updateAvoidList(resourceList, avoid, dc); + } else { + avoid.addDataCenter(dc.getId()); + if (s_logger.isDebugEnabled()) { + s_logger.debug("No dedicated resources available for this domain or account under this group"); + } + } + if (s_logger.isDebugEnabled()) { - s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() - + "of type 'ExplicitDedication' for VM Id: " + vm.getId()); + s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " + + avoid.getHostsToAvoid()); } - - long affinityGroupId = vmGroupMapping.getAffinityGroupId(); - - // List dr = _dedicatedDao.listByAccountId(accountId); - // List drOfDomain = - // searchInDomainResources(domainId); - // List drOfParentDomain = - // searchInParentDomainResources(domainId); - - List dr = _dedicatedDao.listByAffinityGroupId(affinityGroupId); - resourceList.addAll(dr); - - } - } - - boolean canUse = false; - - if (plan.getHostId() != null) { - HostVO host = _hostDao.findById(plan.getHostId()); - ClusterVO clusterofHost = _clusterDao.findById(host.getClusterId()); - HostPodVO podOfHost = _podDao.findById(host.getPodId()); - DataCenterVO zoneOfHost = _dcDao.findById(host.getDataCenterId()); - if (resourceList != null && resourceList.size() != 0) { - for (DedicatedResourceVO resource : resourceList) { - if ((resource.getHostId() != null && resource.getHostId() == plan.getHostId()) - || (resource.getClusterId() != null && resource.getClusterId() == clusterofHost.getId()) - || (resource.getPodId() != null && resource.getPodId() == podOfHost.getId()) - || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfHost.getId())) { - canUse = true; - } - } - } - if (!canUse) { - throw new CloudRuntimeException("Cannot use this host " + host.getName() + " for explicit dedication"); - } - } else if (plan.getClusterId() != null) { - ClusterVO cluster = _clusterDao.findById(plan.getClusterId()); - HostPodVO podOfCluster = _podDao.findById(cluster.getPodId()); - DataCenterVO zoneOfCluster = _dcDao.findById(cluster.getDataCenterId()); - List hostToUse = new ArrayList(); - // check whether this cluster or its pod is dedicated - if (resourceList != null && resourceList.size() != 0) { - for (DedicatedResourceVO resource : resourceList) { - if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) - || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) - || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster - .getId())) { - canUse = true; - } - - // check for all dedicated host; if it belongs to this - // cluster - if (!canUse) { - if (resource.getHostId() != null) { - HostVO dHost = _hostDao.findById(resource.getHostId()); - if (dHost.getClusterId() == cluster.getId()) { - hostToUse.add(dHost); - } - } - } - - } - } - - if (hostToUse.isEmpty() && !canUse) { - throw new CloudRuntimeException("Cannot use this cluster " + cluster.getName() - + " for explicit dedication"); - } - - if (hostToUse != null && hostToUse.size() != 0) { - // add other non-dedicated hosts to avoid list - List hostList = _hostDao.findByClusterId(cluster.getId()); - for (HostVO host : hostList) { - if (!hostToUse.contains(host)) { - avoid.addHost(host.getId()); - } - } - } - - } else if (plan.getPodId() != null) { - HostPodVO pod = _podDao.findById(plan.getPodId()); - DataCenterVO zoneOfPod = _dcDao.findById(pod.getDataCenterId()); - List clustersToUse = new ArrayList(); - List hostsToUse = new ArrayList(); - // check whether this cluster or its pod is dedicated - if (resourceList != null && resourceList.size() != 0) { - for (DedicatedResourceVO resource : resourceList) { - if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) - || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod.getId())) { - canUse = true; - } - - // check for all dedicated cluster/host; if it belongs to - // this pod - if (!canUse) { - if (resource.getClusterId() != null) { - ClusterVO dCluster = _clusterDao.findById(resource.getClusterId()); - if (dCluster.getPodId() == pod.getId()) { - clustersToUse.add(dCluster); - } - } - if (resource.getHostId() != null) { - HostVO dHost = _hostDao.findById(resource.getHostId()); - if (dHost.getPodId() == pod.getId()) { - hostsToUse.add(dHost); - } - } - } - - } - } - - if (hostsToUse.isEmpty() && clustersToUse.isEmpty() && !canUse) { - throw new CloudRuntimeException("Cannot use this pod " + pod.getName() + " for explicit dedication"); - } - - if (clustersToUse != null && clustersToUse.size() != 0) { - // add other non-dedicated clusters to avoid list - List clusterList = _clusterDao.listByPodId(pod.getId()); - for (ClusterVO cluster : clusterList) { - if (!clustersToUse.contains(cluster)) { - avoid.addCluster(cluster.getId()); - } - } - } - - if (hostsToUse != null && hostsToUse.size() != 0) { - // add other non-dedicated hosts to avoid list - List hostList = _hostDao.findByPodId(pod.getId()); - for (HostVO host : hostList) { - if (!hostsToUse.contains(host)) { - avoid.addHost(host.getId()); - } - } - } - - } else { - // check all resources under this zone - if (resourceList != null && resourceList.size() != 0) { - avoid = updateAvoidList(resourceList, avoid, dc); - } /* - * else if(drOfDomain != null && drOfDomain.size() != 0){ avoid = - * updateAvoidList(drOfDomain, avoid, dc); } else - * if(drOfParentDomain != null && drOfParentDomain.size() != 0){ - * avoid = updateAvoidList(drOfParentDomain, avoid, dc); } - */else { - avoid.addDataCenter(dc.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("No dedicated resources available for this domain or account under this group"); - } - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " - + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " - + avoid.getHostsToAvoid()); } }