use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.
the class ImplicitPlannerTest method checkStrictModeWithCurrentAccountVmsPresent.
@Test
public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientServerCapacityException {
VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
DataCenterDeployment plan = mock(DataCenterDeployment.class);
ExcludeList avoids = new ExcludeList();
initializeForTest(vmProfile, plan);
initializeForImplicitPlannerTest(false);
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 (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);
Set<Long> hostsInAvoidList = avoids.getHostsToAvoid();
assertFalse("Host 5 shouldn't have be in the avoid list, but it is present", hostsInAvoidList.contains(5L));
Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
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.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 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 LoadBalanceRuleHandler method deployELBVm.
private DomainRouterVO deployELBVm(Network guestNetwork, final DeployDestination dest, Account owner, final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException {
final long dcId = dest.getDataCenter().getId();
// lock guest network
final Long guestNetworkId = guestNetwork.getId();
guestNetwork = _networkDao.acquireInLockTable(guestNetworkId);
if (guestNetwork == null) {
throw new ConcurrentOperationException("Unable to acquire network lock: " + guestNetworkId);
}
try {
if (_networkModel.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) {
owner = _accountService.getSystemAccount();
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest);
}
assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
DataCenterDeployment plan = null;
DomainRouterVO elbVm = null;
plan = new DataCenterDeployment(dcId, dest.getPod().getId(), null, null, null, null);
if (elbVm == null) {
final long id = _routerDao.getNextInSequence(Long.class, "id");
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating the ELB vm " + id);
}
final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
final NetworkOffering controlOffering = offerings.get(0);
final Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(2);
final NicProfile guestNic = new NicProfile();
guestNic.setDefaultNic(true);
networks.put(controlConfig, new ArrayList<NicProfile>());
networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
final VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
final String typeString = "ElasticLoadBalancerVm";
final Long physicalNetworkId = _networkModel.getPhysicalNetworkId(guestNetwork);
final PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, typeString);
if (provider == null) {
throw new CloudRuntimeException("Cannot find service provider " + typeString + " in physical network " + physicalNetworkId);
}
final VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), Type.ElasticLoadBalancerVm);
if (vrProvider == null) {
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
}
long userId = CallContext.current().getCallingUserId();
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
if (!userVOs.isEmpty()) {
userId = userVOs.get(0).getId();
}
}
ServiceOfferingVO elasticLbVmOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.elbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
elbVm = new DomainRouterVO(id, elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, elasticLbVmOffering.isOfferHA(), false, null);
elbVm.setRole(Role.LB);
elbVm = _routerDao.persist(elbVm);
_itMgr.allocate(elbVm.getInstanceName(), template, elasticLbVmOffering, networks, plan, null);
elbVm = _routerDao.findById(elbVm.getId());
// TODO: create usage stats
}
final State state = elbVm.getState();
if (state != State.Running) {
elbVm = start(elbVm, params);
}
return elbVm;
} finally {
_networkDao.releaseFromLockTable(guestNetworkId);
}
}
Aggregations