Search in sources :

Example 56 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInOnePool.

@Test
public void testTemplateScheduledForDownloadInOnePool() {
    final VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    final StoragePoolVO mockPool = mock(StoragePoolVO.class);
    final PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    final VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPool.getId()).thenReturn(2l);
    when(mockPool.getStatus()).thenReturn(StoragePoolStatus.Up);
    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())).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(mockPool);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    final 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 scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 1);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 57 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class TemplateManagerImplTest method testPrepareTemplateNoHostConnectedToPool.

@Test(expected = CloudRuntimeException.class)
public void testPrepareTemplateNoHostConnectedToPool() {
    final VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    when(mockTemplate.getId()).thenReturn(202l);
    final StoragePoolVO mockPool = mock(StoragePoolVO.class);
    when(mockPool.getId()).thenReturn(2l);
    final PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPrimaryDataStore.getDataCenterId()).thenReturn(1l);
    final TemplateDataStoreVO mockTemplateDataStore = mock(TemplateDataStoreVO.class);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(null);
    when(templateDataStoreDao.findByTemplateZoneDownloadStatus(202l, 1l, VMTemplateStorageResourceAssoc.Status.DOWNLOADED)).thenReturn(mockTemplateDataStore);
    when(storagePoolHostDao.listByHostStatus(2l, Status.Up)).thenReturn(null);
    templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
}
Also used : VMTemplateVO(com.cloud.storage.VMTemplateVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 58 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInMultiplePool.

@Test
public void testTemplateScheduledForDownloadInMultiplePool() {
    final VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    final PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    final VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    final List<StoragePoolVO> pools = new ArrayList<>();
    final StoragePoolVO mockPool1 = mock(StoragePoolVO.class);
    when(mockPool1.getId()).thenReturn(2l);
    when(mockPool1.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool1.getDataCenterId()).thenReturn(1l);
    final StoragePoolVO mockPool2 = mock(StoragePoolVO.class);
    when(mockPool2.getId()).thenReturn(3l);
    when(mockPool2.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool2.getDataCenterId()).thenReturn(1l);
    final 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())).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());
    final 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) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 59 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class VMSnapshotHelperImpl method pickRunningHost.

@Override
public Long pickRunningHost(final Long vmId) {
    final UserVmVO vm = userVmDao.findById(vmId);
    // use VM's host if VM is running
    if (vm.getState() == VirtualMachine.State.Running) {
        return vm.getHostId();
    }
    // check if lastHostId is available
    if (vm.getLastHostId() != null) {
        final HostVO lastHost = hostDao.findByIdIncludingRemoved(vm.getLastHostId());
        if (lastHost.getStatus() == com.cloud.host.Status.Up && !lastHost.isInMaintenanceStates()) {
            return lastHost.getId();
        }
    }
    final List<VolumeVO> listVolumes = volumeDao.findByInstance(vmId);
    if (listVolumes == null || listVolumes.size() == 0) {
        throw new InvalidParameterValueException("vmInstance has no volumes");
    }
    final VolumeVO volume = listVolumes.get(0);
    final Long poolId = volume.getPoolId();
    if (poolId == null) {
        throw new InvalidParameterValueException("pool id is not found");
    }
    final StoragePoolVO storagePool = primaryDataStoreDao.findById(poolId);
    if (storagePool == null) {
        throw new InvalidParameterValueException("storage pool is not found");
    }
    final List<HostVO> listHost = hostDao.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, storagePool.getClusterId(), storagePool.getPodId(), storagePool.getDataCenterId(), null);
    if (listHost == null || listHost.size() == 0) {
        throw new InvalidParameterValueException("no host in up state is found");
    }
    return listHost.get(0).getId();
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) HostVO(com.cloud.host.HostVO)

Example 60 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreHelper method maintain.

public boolean maintain(final DataStore store) {
    final StoragePoolVO pool = this.dataStoreDao.findById(store.getId());
    pool.setStatus(StoragePoolStatus.Maintenance);
    this.dataStoreDao.update(pool.getId(), pool);
    return true;
}
Also used : StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8