use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.
the class ImplicitPlannerTest method checkStrictModeNoHostsAvailable.
@Test
public void checkStrictModeNoHostsAvailable() throws InsufficientServerCapacityException {
@SuppressWarnings("unchecked") VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
DataCenterDeployment plan = mock(DataCenterDeployment.class);
ExcludeList avoids = new ExcludeList();
initializeForTest(vmProfile, plan);
initializeForImplicitPlannerTest(false);
// Mark the host 5 and 6 to be in avoid list.
avoids.addHost(5L);
avoids.addHost(6L);
List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
// Validations.
// Check cluster list is empty.
assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
}
use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.
the class ImplicitPlannerTest method checkWhenDcInAvoidList.
@Test
public void checkWhenDcInAvoidList() throws InsufficientServerCapacityException {
DataCenterVO mockDc = mock(DataCenterVO.class);
ExcludeList avoids = mock(ExcludeList.class);
VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
VMInstanceVO vm = mock(VMInstanceVO.class);
DataCenterDeployment plan = mock(DataCenterDeployment.class);
when(avoids.shouldAvoid(mockDc)).thenReturn(true);
when(vmProfile.getVirtualMachine()).thenReturn(vm);
when(vm.getDataCenterId()).thenReturn(1L);
when(dcDao.findById(1L)).thenReturn(mockDc);
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.DataCenterDeployment in project cloudstack by apache.
the class ImplicitPlannerTest method checkStrictModeHostWithCurrentAccountVmsFull.
@Test
public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientServerCapacityException {
@SuppressWarnings("unchecked") VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
DataCenterDeployment plan = mock(DataCenterDeployment.class);
ExcludeList avoids = new ExcludeList();
initializeForTest(vmProfile, plan);
initializeForImplicitPlannerTest(false);
// Mark the host 5 with current account vms to be in avoid list.
avoids.addHost(5L);
List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
// Validations.
// Check cluster 1 and 3 are not in the cluster list.
// Host 5 and 7 should also be in avoid list.
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
boolean foundNeededCluster = false;
for (Long cluster : clusterList) {
if (cluster != 2) {
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
} else {
foundNeededCluster = true;
}
}
assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
assertFalse("Host 6 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(6L));
Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
hostsThatShouldBeInAvoidList.add(5L);
hostsThatShouldBeInAvoidList.add(7L);
assertTrue("Hosts 5 and 7 that should have been present were not found in avoid list", hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
}
use of com.cloud.deploy.DataCenterDeployment in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method orchestrateMigrateAway.
private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (vm == null) {
s_logger.debug("Unable to find a VM for " + vmUuid);
throw new CloudRuntimeException("Unable to find " + vmUuid);
}
final ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
final Long hostId = vm.getHostId();
if (hostId == null) {
s_logger.debug("Unable to migrate because the VM doesn't have a host id: " + vm);
throw new CloudRuntimeException("Unable to migrate " + vmUuid);
}
final Host host = _hostDao.findById(hostId);
Long poolId = null;
final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
for (final VolumeVO rootVolumeOfVm : vols) {
final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
if (rootDiskPool != null) {
poolId = rootDiskPool.getId();
}
}
final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, poolId, null);
final ExcludeList excludes = new ExcludeList();
excludes.addHost(hostId);
DeployDestination dest = null;
while (true) {
dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
if (dest != null) {
s_logger.debug("Found destination " + dest + " for migrating to.");
} else {
s_logger.debug("Unable to find destination for migrating the vm " + profile);
throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", host.getClusterId());
}
excludes.addHost(dest.getHost().getId());
try {
migrate(vm, srcHostId, dest);
return;
} catch (final ResourceUnavailableException e) {
s_logger.debug("Unable to migrate to unavailable " + dest);
} catch (final ConcurrentOperationException e) {
s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
}
try {
advanceStop(vmUuid, true);
throw new CloudRuntimeException("Unable to migrate " + vm);
} catch (final ResourceUnavailableException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
throw new CloudRuntimeException("Unable to migrate " + vm);
} catch (final ConcurrentOperationException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
throw new CloudRuntimeException("Unable to migrate " + vm);
} catch (final OperationTimedoutException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
throw new CloudRuntimeException("Unable to migrate " + vm);
}
}
}
use of com.cloud.deploy.DataCenterDeployment in project cosmic by MissionCriticalCloud.
the class VmWorkStart method getPlan.
public DeploymentPlan getPlan() {
if (podId != null || clusterId != null || hostId != null || poolId != null || physicalNetworkId != null || avoids != null) {
// this is ugly, to work with legacy code, we need to re-construct the DeploymentPlan hard-codely
// this has to be refactored together with migrating legacy code into the new way
ReservationContext context = null;
if (reservationId != null) {
final Journal journal = new Journal.LogJournal("VmWorkStart", s_logger);
context = new ReservationContextImpl(reservationId, journal, CallContext.current().getCallingUser(), CallContext.current().getCallingAccount());
}
final DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, hostId, poolId, physicalNetworkId, context);
plan.setAvoids(avoids);
return plan;
}
return null;
}
Aggregations