Search in sources :

Example 11 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInDisabledPool.

@Test
public void testTemplateScheduledForDownloadInDisabledPool() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    StoragePoolVO mockPool = mock(StoragePoolVO.class);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPool.getId()).thenReturn(2l);
    when(mockPool.getStatus()).thenReturn(StoragePoolStatus.Disabled);
    when(mockPool.getDataCenterId()).thenReturn(1l);
    when(mockTemplate.getId()).thenReturn(202l);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong(), nullable(String.class))).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(mockPool);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
    templateManager._preloadExecutor = preloadExecutor;
    templateManager.prepareTemplate(202, 1, 2l);
    assertTrue("Test template is not scheduled for seeding on disabled pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 0);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 12 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class UserVmManagerImpl method handleManagedStorage.

private void handleManagedStorage(UserVmVO vm, VolumeVO root) {
    if (Volume.State.Allocated.equals(root.getState())) {
        return;
    }
    StoragePoolVO storagePool = _storagePoolDao.findById(root.getPoolId());
    if (storagePool != null && storagePool.isManaged()) {
        Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
        if (hostId != null) {
            VolumeInfo volumeInfo = volFactory.getVolume(root.getId());
            Host host = _hostDao.findById(hostId);
            final Command cmd;
            if (host.getHypervisorType() == HypervisorType.XenServer) {
                DiskTO disk = new DiskTO(volumeInfo.getTO(), root.getDeviceId(), root.getPath(), root.getVolumeType());
                // it's OK in this case to send a detach command to the host for a root volume as this
                // will simply lead to the SR that supports the root volume being removed
                cmd = new DettachCommand(disk, vm.getInstanceName());
                DettachCommand detachCommand = (DettachCommand) cmd;
                detachCommand.setManaged(true);
                detachCommand.setStorageHost(storagePool.getHostAddress());
                detachCommand.setStoragePort(storagePool.getPort());
                detachCommand.set_iScsiName(root.get_iScsiName());
            } else if (host.getHypervisorType() == HypervisorType.VMware) {
                PrimaryDataStore primaryDataStore = (PrimaryDataStore) volumeInfo.getDataStore();
                Map<String, String> details = primaryDataStore.getDetails();
                if (details == null) {
                    details = new HashMap<>();
                    primaryDataStore.setDetails(details);
                }
                details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
                cmd = new DeleteCommand(volumeInfo.getTO());
            } else if (host.getHypervisorType() == HypervisorType.KVM) {
                cmd = null;
            } else {
                throw new CloudRuntimeException("This hypervisor type is not supported on managed storage for this command.");
            }
            if (cmd != null) {
                Commands cmds = new Commands(Command.OnError.Stop);
                cmds.addCommand(cmd);
                try {
                    _agentMgr.send(hostId, cmds);
                } catch (Exception ex) {
                    throw new CloudRuntimeException(ex.getMessage());
                }
                if (!cmds.isSuccessful()) {
                    for (Answer answer : cmds.getAnswers()) {
                        if (!answer.getResult()) {
                            s_logger.warn("Failed to reset vm due to: " + answer.getDetails());
                            throw new CloudRuntimeException("Unable to reset " + vm + " due to " + answer.getDetails());
                        }
                    }
                }
            }
            // root.getPoolId() should be null if the VM we are detaching the disk from has never been started before
            DataStore dataStore = root.getPoolId() != null ? _dataStoreMgr.getDataStore(root.getPoolId(), DataStoreRole.Primary) : null;
            volumeMgr.revokeAccess(volFactory.getVolume(root.getId()), host, dataStore);
            if (dataStore != null) {
                handleTargetsForVMware(host.getId(), storagePool.getHostAddress(), storagePool.getPort(), root.get_iScsiName());
            }
        }
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.host.Host) ExecutionException(com.cloud.utils.exception.ExecutionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) IOException(java.io.IOException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudException(com.cloud.exception.CloudException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) AffinityConflictException(com.cloud.exception.AffinityConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ManagementServerException(com.cloud.exception.ManagementServerException) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) Answer(com.cloud.agent.api.Answer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) GetVolumeStatsCommand(com.cloud.agent.api.GetVolumeStatsCommand) GetVmNetworkStatsCommand(com.cloud.agent.api.GetVmNetworkStatsCommand) Command(com.cloud.agent.api.Command) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) DettachCommand(org.apache.cloudstack.storage.command.DettachCommand) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) GetVmIpAddressCommand(com.cloud.agent.api.GetVmIpAddressCommand) GetVmDiskStatsCommand(com.cloud.agent.api.GetVmDiskStatsCommand) RestoreVMSnapshotCommand(com.cloud.agent.api.RestoreVMSnapshotCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DettachCommand(org.apache.cloudstack.storage.command.DettachCommand) Commands(com.cloud.agent.manager.Commands) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DiskTO(com.cloud.agent.api.to.DiskTO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 13 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class VolumeOrchestrator method release.

@Override
public void release(long vmId, long hostId) {
    List<VolumeVO> volumesForVm = _volsDao.findUsableVolumesForInstance(vmId);
    if (volumesForVm == null || volumesForVm.isEmpty()) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Releasing " + volumesForVm.size() + " volumes for VM: " + vmId + " from host: " + hostId);
    }
    for (VolumeVO volumeForVm : volumesForVm) {
        VolumeInfo volumeInfo = volFactory.getVolume(volumeForVm.getId());
        // pool id can be null for the VM's volumes in Allocated state
        if (volumeForVm.getPoolId() != null) {
            DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary);
            PrimaryDataStore primaryDataStore = (PrimaryDataStore) dataStore;
            HostVO host = _hostDao.findById(hostId);
            // This might impact other managed storages, grant access for PowerFlex storage pool only
            if (primaryDataStore.isManaged() && primaryDataStore.getPoolType() == Storage.StoragePoolType.PowerFlex) {
                volService.revokeAccess(volumeInfo, host, dataStore);
            }
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) HostVO(com.cloud.host.HostVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 14 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class TemplateManagerImplTest method testPrepareTemplateIsSeeded.

@Test
public void testPrepareTemplateIsSeeded() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    when(mockTemplate.getId()).thenReturn(202l);
    StoragePoolVO mockPool = mock(StoragePoolVO.class);
    when(mockPool.getId()).thenReturn(2l);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong(), nullable(String.class))).thenReturn(mockTemplateStore);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
    assertTrue("Test template is already seeded", returnObject == mockTemplateStore);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 15 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInMultiplePool.

@Test
public void testTemplateScheduledForDownloadInMultiplePool() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
    StoragePoolVO mockPool1 = mock(StoragePoolVO.class);
    when(mockPool1.getId()).thenReturn(2l);
    when(mockPool1.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool1.getDataCenterId()).thenReturn(1l);
    StoragePoolVO mockPool2 = mock(StoragePoolVO.class);
    when(mockPool2.getId()).thenReturn(3l);
    when(mockPool2.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool2.getDataCenterId()).thenReturn(1l);
    StoragePoolVO mockPool3 = mock(StoragePoolVO.class);
    when(mockPool3.getId()).thenReturn(4l);
    when(mockPool3.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool3.getDataCenterId()).thenReturn(2l);
    pools.add(mockPool1);
    pools.add(mockPool2);
    pools.add(mockPool3);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockTemplate.getId()).thenReturn(202l);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong(), nullable(String.class))).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(2l)).thenReturn(mockPool1);
    when(primaryDataStoreDao.findById(3l)).thenReturn(mockPool2);
    when(primaryDataStoreDao.findById(4l)).thenReturn(mockPool3);
    when(primaryDataStoreDao.listByStatus(StoragePoolStatus.Up)).thenReturn(pools);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
    templateManager._preloadExecutor = preloadExecutor;
    templateManager.prepareTemplate(202, 1, null);
    assertTrue("Test template is scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 2);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Aggregations

PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)25 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)14 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)9 ExecutionException (java.util.concurrent.ExecutionException)8 Test (org.junit.Test)8 VMTemplateVO (com.cloud.storage.VMTemplateVO)7 VolumeVO (com.cloud.storage.VolumeVO)7 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)7 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 StorageAccessException (com.cloud.exception.StorageAccessException)6 Host (com.cloud.host.Host)6 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 Answer (com.cloud.agent.api.Answer)5 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)5 ArrayList (java.util.ArrayList)4 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)3 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)3