use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ResourceCheckerTest method test_checkIfPodIsUsable_whenPodDoesNotBelongToDataCenter.
@Test(expected = InvalidParameterValueException.class)
public void test_checkIfPodIsUsable_whenPodDoesNotBelongToDataCenter() throws Exception {
final DataCenterVO dataCenter = new DataCenterVO();
dataCenter.setId(1L);
dataCenter.setUuid("DataCenterUUID");
final HostPodVO hostPod = new HostPodVO();
hostPod.setDataCenterId(2L);
hostPod.setUuid("HostPodUUID");
final ResourceChecker resourceChecker = buildResourceChecker();
resourceChecker.checkIfPodIsUsable(dataCenter, hostPod);
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method migrateVirtualMachine.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription = "migrating VM", async = true)
public VirtualMachine migrateVirtualMachine(final Long vmId, final Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
// access check - only root admin can migrate VM
final Account caller = CallContext.current().getCallingAccount();
if (!_accountMgr.isRootAdmin(caller.getId())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Caller is not a root admin, permission denied to migrate the VM");
}
throw new PermissionDeniedException("No permission to migrate VM, Only Root Admin can migrate a VM!");
}
final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
if (vm == null) {
throw new InvalidParameterValueException("Unable to find the VM by id=" + vmId);
}
// business logic
if (vm.getState() != State.Running) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM is not Running, unable to migrate the vm " + vm);
}
final InvalidParameterValueException ex = new InvalidParameterValueException("VM is not Running, unable to migrate the vm with specified id");
ex.addProxyObject(vm.getUuid(), "vmId");
throw ex;
}
if (serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.pciDevice.toString()) != null) {
throw new InvalidParameterValueException("Live Migration of GPU enabled VM is not supported");
}
if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.KVM)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(vm + " is not XenServer/KVM, cannot migrate this VM.");
}
throw new InvalidParameterValueException("Unsupported Hypervisor Type for VM migration, we support XenServer/KVM only");
}
if (isVMUsingLocalStorage(vm)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(vm + " is using Local Storage, cannot migrate this VM.");
}
throw new InvalidParameterValueException("Unsupported operation, VM uses Local storage, cannot migrate");
}
// check if migrating to same host
final long srcHostId = vm.getHostId();
if (destinationHost.getId() == srcHostId) {
throw new InvalidParameterValueException("Cannot migrate VM, VM is already presnt on this host, please specify valid destination host to migrate the VM");
}
// check if host is UP
if (destinationHost.getState() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) {
throw new InvalidParameterValueException("Cannot migrate VM, destination host is not in correct state, has status: " + destinationHost.getState() + ", state: " + destinationHost.getResourceState());
}
if (vm.getType() != VirtualMachine.Type.User) {
// for System VMs check that the destination host is within the same
// cluster
final HostVO srcHost = _hostDao.findById(srcHostId);
if (srcHost != null && srcHost.getClusterId() != null && destinationHost.getClusterId() != null) {
if (srcHost.getClusterId().longValue() != destinationHost.getClusterId().longValue()) {
throw new InvalidParameterValueException("Cannot migrate the VM, destination host is not in the same cluster as current host of the VM");
}
}
}
checkHostsDedication(vm, srcHostId, destinationHost.getId());
// call to core process
final Zone zone = zoneRepository.findOne(destinationHost.getDataCenterId());
final HostPodVO pod = _podDao.findById(destinationHost.getPodId());
final Cluster cluster = _clusterDao.findById(destinationHost.getClusterId());
final DeployDestination dest = new DeployDestination(zone, pod, cluster, destinationHost);
// check max guest vm limit for the destinationHost
final HostVO destinationHostVO = _hostDao.findById(destinationHost.getId());
if (_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host name: " + destinationHost.getName() + ": " + destinationHost.getName() + " already has max Running VMs(count includes system VMs), cannot migrate to this host");
}
throw new VirtualMachineMigrationException("Destination host: " + destinationHost.getName() + " already has max Running VMs(count includes system VMs), cannot migrate to this host");
}
// Check host tags
final ServiceOffering serviceOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
if (serviceOffering != null) {
final String requiredHostTag = serviceOffering.getHostTag();
final List<String> hostTags = _hostTagsDao.gethostTags(destinationHost.getId());
boolean foundRequiredHostTag = false;
for (final String hostTag : hostTags) {
if (hostTag.equals(requiredHostTag)) {
foundRequiredHostTag = true;
break;
}
}
if (!foundRequiredHostTag && requiredHostTag != null) {
throw new VirtualMachineMigrationException("Destination host: " + destinationHost.getName() + " does not have required host tag " + requiredHostTag);
}
}
final UserVmVO uservm = _vmDao.findById(vmId);
if (uservm != null) {
collectVmDiskStatistics(uservm);
}
_itMgr.migrate(vm.getUuid(), srcHostId, dest);
final VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
return _vmDao.findById(vmId);
} else {
return vmInstance;
}
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnVmInstanceTest.
@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnVmInstanceTest() {
final HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
final VMInstanceVO vMInstanceVO = Mockito.mock(VMInstanceVO.class);
final ArrayList<VMInstanceVO> arrayList = new ArrayList<>();
arrayList.add(vMInstanceVO);
Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(0);
Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(arrayList);
Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(new ArrayList<>());
configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method checkIfZoneIsDeletableFailureOnPodTest.
@Test(expected = CloudRuntimeException.class)
public void checkIfZoneIsDeletableFailureOnPodTest() {
final HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
final ArrayList<HostPodVO> arrayList = new ArrayList<>();
arrayList.add(hostPodVO);
Mockito.when(_hostDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_podDao.listByDataCenterId(anyLong())).thenReturn(arrayList);
Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
Mockito.when(_publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<>());
Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<>());
configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
}
use of com.cloud.dc.HostPodVO in project cloudstack by apache.
the class EndpointSelectorTest method setUp.
@Before
public void setUp() {
// create data center
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, DataCenter.NetworkType.Basic, null, null, true, true, null, null);
dc = dcDao.persist(dc);
dcId = dc.getId();
// create pod
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "10.223.0.1", "10.233.2.2/25", 8, "test");
pod = podDao.persist(pod);
podId = pod.getId();
// create xenserver cluster
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
cluster.setHypervisorType(Hypervisor.HypervisorType.XenServer.toString());
cluster.setClusterType(Cluster.ClusterType.CloudManaged);
cluster.setManagedState(Managed.ManagedState.Managed);
cluster = clusterDao.persist(cluster);
clusterId = cluster.getId();
imageStore = new ImageStoreVO();
imageStore.setName(UUID.randomUUID().toString());
imageStore.setDataCenterId(dcId);
imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
imageStore.setRole(DataStoreRole.Image);
imageStore.setUrl(UUID.randomUUID().toString());
imageStore.setUuid(UUID.randomUUID().toString());
imageStore.setProtocol("nfs");
imageStore = imageStoreDao.persist(imageStore);
when(primaryDataStoreProvider.configure(Matchers.anyMap())).thenReturn(true);
Set<DataStoreProvider.DataStoreProviderType> types = new HashSet<DataStoreProvider.DataStoreProviderType>();
types.add(DataStoreProvider.DataStoreProviderType.PRIMARY);
when(primaryDataStoreProvider.getTypes()).thenReturn(types);
when(primaryDataStoreProvider.getName()).thenReturn(DataStoreProvider.DEFAULT_PRIMARY);
when(primaryDataStoreProvider.getDataStoreDriver()).thenReturn(driver);
User user = mock(User.class);
when(user.getId()).thenReturn(1L);
Account account = mock(Account.class);
when(account.getId()).thenReturn(1L);
when(accountManager.getSystemAccount()).thenReturn(account);
when(accountManager.getSystemUser()).thenReturn(user);
if (Merovingian2.getLockController() == null) {
_lockController = Merovingian2.createLockController(1234);
} else {
_lockController = Merovingian2.getLockController();
}
_lockController.cleanupThisServer();
ComponentContext.initComponentsLifeCycle();
}
Aggregations