Search in sources :

Example 1 with HostPodVO

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HostPodVO(com.cloud.dc.HostPodVO) Test(org.junit.Test)

Example 2 with HostPodVO

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;
    }
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) Zone(com.cloud.db.model.Zone) Cluster(com.cloud.org.Cluster) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) ActionEvent(com.cloud.event.ActionEvent)

Example 3 with HostPodVO

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());
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) Test(org.junit.Test)

Example 4 with HostPodVO

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());
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) Test(org.junit.Test)

Example 5 with HostPodVO

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();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) User(com.cloud.user.User) PrimaryDataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HostPodVO(com.cloud.dc.HostPodVO) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

HostPodVO (com.cloud.dc.HostPodVO)126 ArrayList (java.util.ArrayList)52 HostVO (com.cloud.host.HostVO)47 ClusterVO (com.cloud.dc.ClusterVO)46 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 DataCenterVO (com.cloud.dc.DataCenterVO)39 Account (com.cloud.user.Account)25 DB (com.cloud.utils.db.DB)25 Test (org.junit.Test)23 ConfigurationException (javax.naming.ConfigurationException)22 TransactionStatus (com.cloud.utils.db.TransactionStatus)21 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 VMInstanceVO (com.cloud.vm.VMInstanceVO)18 Random (java.util.Random)18 VolumeVO (com.cloud.storage.VolumeVO)17 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)16 HashMap (java.util.HashMap)16 List (java.util.List)16 Zone (com.cloud.db.model.Zone)15 DataCenter (com.cloud.dc.DataCenter)14