use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cosmic by MissionCriticalCloud.
the class NetworkHelperImpl method getExcludeLists.
private ExcludeList[] getExcludeLists(final DomainRouterVO routerToBeAvoid, final int retryIndex) {
final ExcludeList[] avoids = new ExcludeList[retryIndex];
avoids[0] = new ExcludeList();
avoids[0].addPod(routerToBeAvoid.getPodIdToDeployIn());
avoids[1] = new ExcludeList();
avoids[1].addCluster(_hostDao.findById(routerToBeAvoid.getHostId()).getClusterId());
avoids[2] = new ExcludeList();
final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
if (volumes != null && volumes.size() != 0) {
avoids[2].addPool(volumes.get(0).getPoolId());
}
avoids[2].addHost(routerToBeAvoid.getHostId());
avoids[3] = new ExcludeList();
avoids[3].addHost(routerToBeAvoid.getHostId());
avoids[4] = new ExcludeList();
return avoids;
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cosmic by MissionCriticalCloud.
the class ImplicitPlannerTest method checkWhenDcInAvoidList.
@Test
public void checkWhenDcInAvoidList() throws InsufficientServerCapacityException {
final Zone zone = mock(Zone.class);
final ExcludeList avoids = mock(ExcludeList.class);
final VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
final VMInstanceVO vm = mock(VMInstanceVO.class);
final DataCenterDeployment plan = mock(DataCenterDeployment.class);
when(avoids.shouldAvoid(zone)).thenReturn(true);
when(vmProfile.getVirtualMachine()).thenReturn(vm);
when(vm.getDataCenterId()).thenReturn(1L);
when(zoneRepository.findOne(1L)).thenReturn(zone);
final List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
assertTrue("Cluster list should be null/empty if the dc is in avoid list", (clusterList == null || clusterList.isEmpty()));
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cosmic by MissionCriticalCloud.
the class ImplicitPlannerTest method checkPreferredModePreferredHostAvailable.
@Test
public void checkPreferredModePreferredHostAvailable() throws InsufficientServerCapacityException {
final VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
final DataCenterDeployment plan = mock(DataCenterDeployment.class);
final ExcludeList avoids = new ExcludeList();
initializeForTest(vmProfile, plan);
initializeForImplicitPlannerTest(true);
// Mark the host 5 and 6 to be in avoid list.
avoids.addHost(5L);
avoids.addHost(6L);
final List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
// Validations.
// Check cluster 1 and 2 are not in the cluster list.
// Host 5 and 6 should also be in avoid list.
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
boolean foundNeededCluster = false;
for (final Long cluster : clusterList) {
if (cluster != 3) {
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
} else {
foundNeededCluster = true;
}
}
assertTrue("Didn't find cluster 3 in the list. It should have been present", foundNeededCluster);
final Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
assertFalse("Host 7 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(7L));
final Set<Long> hostsThatShouldBeInAvoidList = new HashSet<>();
hostsThatShouldBeInAvoidList.add(5L);
hostsThatShouldBeInAvoidList.add(6L);
assertTrue("Hosts 5 and 6 that should have been present were not found in avoid list", hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cosmic by MissionCriticalCloud.
the class ImplicitPlannerTest method checkStrictModeWithCurrentAccountVmsPresent.
@Test
public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientServerCapacityException {
final VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
final DataCenterDeployment plan = mock(DataCenterDeployment.class);
final ExcludeList avoids = new ExcludeList();
initializeForTest(vmProfile, plan);
initializeForImplicitPlannerTest(false);
final List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
// Validations.
// Check cluster 2 and 3 are not in the cluster list.
// Host 6 and 7 should also be in avoid list.
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
boolean foundNeededCluster = false;
for (final Long cluster : clusterList) {
if (cluster != 1) {
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
} else {
foundNeededCluster = true;
}
}
assertTrue("Didn't find cluster 1 in the list. It should have been present", foundNeededCluster);
final Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
assertFalse("Host 5 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(5L));
final Set<Long> hostsThatShouldBeInAvoidList = new HashSet<>();
hostsThatShouldBeInAvoidList.add(6L);
hostsThatShouldBeInAvoidList.add(7L);
assertTrue("Hosts 6 and 7 that should have been present were not found in avoid list", hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
}
use of com.cloud.deploy.DeploymentPlanner.ExcludeList in project cosmic by MissionCriticalCloud.
the class DeploymentPlanningManagerImpl method planDeployment.
@Override
public DeployDestination planDeployment(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoids, DeploymentPlanner planner) throws InsufficientServerCapacityException, AffinityConflictException {
// call affinitygroup chain
final VirtualMachine vm = vmProfile.getVirtualMachine();
final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
final Zone zone = zoneRepository.findOne(vm.getDataCenterId());
if (vmGroupCount > 0) {
for (final AffinityGroupProcessor processor : _affinityProcessors) {
processor.process(vmProfile, plan, avoids);
}
}
if (vm.getType() == VirtualMachine.Type.User || vm.getType() == VirtualMachine.Type.DomainRouter) {
checkForNonDedicatedResources(vmProfile, zone, avoids);
}
s_logger.debug("Deployment will {}", avoids.toString());
// check if datacenter is in avoid set
if (avoids.shouldAvoid(zone)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("DataCenter id = '" + zone.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
}
return null;
}
final ServiceOffering offering = vmProfile.getServiceOffering();
if (planner == null) {
String plannerName = offering.getDeploymentPlanner();
if (plannerName == null) {
plannerName = _configDao.getValue(Config.VmDeploymentPlanner.key());
}
planner = getDeploymentPlannerByName(plannerName);
}
final int cpu_requested = offering.getCpu();
final long ram_requested = offering.getRamSize() * 1024L * 1024L;
if (s_logger.isDebugEnabled()) {
s_logger.debug("DeploymentPlanner allocation algorithm: " + planner);
s_logger.debug("Trying to allocate a host and storage pools from zone:" + plan.getDataCenterId() + ", pod:" + plan.getPodId() + ",cluster:" + plan.getClusterId() + ", requested cpu: " + cpu_requested + ", requested ram: " + ram_requested);
s_logger.debug("Is ROOT volume READY (pool already allocated)?: " + (plan.getPoolId() != null ? "Yes" : "No"));
}
final String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (plan.getHostId() != null && haVmTag == null) {
final Long hostIdSpecified = plan.getHostId();
if (s_logger.isDebugEnabled()) {
s_logger.debug("DeploymentPlan has host_id specified, choosing this host and making no checks on this host: " + hostIdSpecified);
}
final HostVO host = _hostDao.findById(hostIdSpecified);
if (host == null) {
s_logger.debug("The specified host cannot be found");
} else if (avoids.shouldAvoid(host)) {
s_logger.debug("The specified host is in avoid set");
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for suitable pools for this host under zone: " + host.getDataCenterId() + ", pod: " + host.getPodId() + ", cluster: " + host.getClusterId());
}
Pod pod = _podDao.findById(host.getPodId());
Cluster cluster = _clusterDao.findById(host.getClusterId());
// search for storage under the zone, pod, cluster of the host.
final DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
final Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
final Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
final List<Volume> readyAndReusedVolumes = result.second();
// choose the potential pool for this VM for this host
if (!suitableVolumeStoragePools.isEmpty()) {
final List<Host> suitableHosts = new ArrayList<>();
suitableHosts.add(host);
final Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner, vmProfile, plan, avoids), readyAndReusedVolumes);
if (potentialResources != null) {
pod = _podDao.findById(host.getPodId());
cluster = _clusterDao.findById(host.getClusterId());
final Map<Volume, StoragePool> storageVolMap = potentialResources.second();
// we don't have to prepare this volume.
for (final Volume vol : readyAndReusedVolumes) {
storageVolMap.remove(vol);
}
final DeployDestination dest = new DeployDestination(zone, pod, cluster, host, storageVolMap);
s_logger.debug("Returning Deployment Destination: " + dest);
return dest;
}
}
}
s_logger.debug("Cannot deploy to specified host, returning.");
return null;
}
DeployDestination dest = null;
List<Long> clusterList = null;
if (planner != null && planner.canHandle(vmProfile, plan, avoids)) {
while (true) {
if (planner instanceof DeploymentClusterPlanner) {
final ExcludeList plannerAvoidInput = new ExcludeList(avoids.getZonesToAvoid(), avoids.getPodsToAvoid(), avoids.getClustersToAvoid(), avoids.getHostsToAvoid(), avoids.getPoolsToAvoid());
clusterList = ((DeploymentClusterPlanner) planner).orderClusters(vmProfile, plan, avoids);
if (clusterList != null && !clusterList.isEmpty()) {
// planner refactoring. call allocators to list hosts
final ExcludeList plannerAvoidOutput = new ExcludeList(avoids.getZonesToAvoid(), avoids.getPodsToAvoid(), avoids.getClustersToAvoid(), avoids.getHostsToAvoid(), avoids.getPoolsToAvoid());
resetAvoidSet(plannerAvoidOutput, plannerAvoidInput);
dest = checkClustersforDestination(clusterList, vmProfile, plan, avoids, zone, getPlannerUsage(planner, vmProfile, plan, avoids), plannerAvoidOutput);
if (dest != null) {
return dest;
}
// reset the avoid input to the planners
resetAvoidSet(avoids, plannerAvoidOutput);
} else {
return null;
}
} else {
dest = planner.plan(vmProfile, plan, avoids);
if (dest != null) {
final long hostId = dest.getHost().getId();
avoids.addHost(dest.getHost().getId());
if (checkIfHostFitsPlannerUsage(hostId, DeploymentPlanner.PlannerResourceUsage.Shared)) {
// found destination
return dest;
} else {
// deployment picked it up for dedicated access
continue;
}
} else {
return null;
}
}
}
}
return dest;
}
Aggregations