Search in sources :

Example 11 with StoragePoolVO

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

the class TemplateManagerImplTest method testPrepareTemplateNotDownloaded.

@Test
public void testPrepareTemplateNotDownloaded() {
    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);
    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(null);
    final VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
    assertTrue("Test template is not ready", returnObject == null);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 12 with StoragePoolVO

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

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInDisabledPool.

@Test
public void testTemplateScheduledForDownloadInDisabledPool() {
    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.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())).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 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) 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 13 with StoragePoolVO

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

the class TemplateManagerImplTest method testPrepareTemplateIsSeeded.

@Test
public void testPrepareTemplateIsSeeded() {
    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);
    final 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())).thenReturn(mockTemplateStore);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    final 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) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 14 with StoragePoolVO

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

the class UserVmManagerTest method testRestoreVMF2.

// Test restoreVm when VM is in stopped state
@Test
public void testRestoreVMF2() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    doReturn(VirtualMachine.State.Stopped).when(_vmMock).getState();
    when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
    when(_volsDao.findByInstanceAndType(314L, Volume.Type.ROOT)).thenReturn(_rootVols);
    doReturn(false).when(_rootVols).isEmpty();
    when(_rootVols.get(eq(0))).thenReturn(_volumeMock);
    doReturn(3L).when(_volumeMock).getTemplateId();
    when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
    when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
    doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
    when(_volumeMock.getId()).thenReturn(3L);
    doNothing().when(_volsDao).detachVolume(anyLong());
    when(_templateMock.getUuid()).thenReturn("e0552266-7060-11e2-bbaa-d55f5db67735");
    final Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    final StoragePoolVO storagePool = new StoragePoolVO();
    storagePool.setManaged(false);
    when(_storagePoolDao.findById(anyLong())).thenReturn(storagePool);
    CallContext.register(user, account);
    try {
        _userVmMgr.restoreVMInternal(_account, _vmMock, null);
    } finally {
        CallContext.unregister();
    }
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 15 with StoragePoolVO

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

the class VolumeOrchestrator method createVolumeFromSnapshot.

@DB
@Override
public VolumeInfo createVolumeFromSnapshot(final Volume volume, final Snapshot snapshot, final UserVm vm) throws StorageUnavailableException {
    final Account account = _entityMgr.findById(Account.class, volume.getAccountId());
    final HashSet<StoragePool> poolsToAvoid = new HashSet<>();
    StoragePool pool = null;
    final Set<Long> podsToAvoid = new HashSet<>();
    Pair<Pod, Long> pod = null;
    final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    final DataCenter dc = _entityMgr.findById(DataCenter.class, volume.getDataCenterId());
    final DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType());
    String msg = "There are no available storage pools to store the volume in";
    if (vm != null) {
        final Pod podofVM = _entityMgr.findById(Pod.class, vm.getPodIdToDeployIn());
        if (podofVM != null) {
            pod = new Pair<>(podofVM, podofVM.getId());
        }
    }
    if (vm != null && pod != null) {
        // if VM is running use the hostId to find the clusterID. If it is stopped, refer the cluster where the ROOT volume of the VM exists.
        Long hostId = null;
        Long clusterId = null;
        if (vm.getState() == State.Running) {
            hostId = vm.getHostId();
            if (hostId != null) {
                final Host vmHost = _entityMgr.findById(Host.class, hostId);
                clusterId = vmHost.getClusterId();
            }
        } else {
            final List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
            if (rootVolumesOfVm.size() != 1) {
                throw new CloudRuntimeException("The VM " + vm.getHostName() + " has more than one ROOT volume and is in an invalid state. Please contact Cloud Support.");
            } else {
                final VolumeVO rootVolumeOfVm = rootVolumesOfVm.get(0);
                final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
                clusterId = (rootDiskPool == null ? null : rootDiskPool.getClusterId());
            }
        }
        // Determine what storage pool to store the volume in
        while ((pool = findStoragePool(dskCh, dc, pod.first(), clusterId, hostId, vm, poolsToAvoid)) != null) {
            break;
        }
        if (pool == null) {
            // pool could not be found in the VM's pod/cluster.
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Could not find any storage pool to create Volume in the pod/cluster of the provided VM " + vm.getUuid());
            }
            final StringBuilder addDetails = new StringBuilder(msg);
            addDetails.append(", Could not find any storage pool to create Volume in the pod/cluster of the VM ");
            addDetails.append(vm.getUuid());
            msg = addDetails.toString();
        }
    } else {
        // Determine what pod to store the volume in
        while ((pod = findPod(null, null, dc, account.getId(), podsToAvoid)) != null) {
            podsToAvoid.add(pod.first().getId());
            // Determine what storage pool to store the volume in
            while ((pool = findStoragePool(dskCh, dc, pod.first(), null, null, null, poolsToAvoid)) != null) {
                break;
            }
            if (pool != null) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found a suitable pool for create volume: " + pool.getId());
                }
                break;
            }
        }
    }
    if (pool == null) {
        s_logger.info(msg);
        throw new StorageUnavailableException(msg, -1);
    }
    final VolumeInfo vol = volFactory.getVolume(volume.getId());
    final DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    final DataStoreRole dataStoreRole = getDataStoreRole(snapshot);
    SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
    if (snapInfo == null && dataStoreRole == DataStoreRole.Image) {
        // snapshot is not backed up to secondary, let's do that now.
        snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
        if (snapInfo == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId());
        }
        // We need to copy the snapshot onto secondary.
        final SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP);
        snapshotStrategy.backupSnapshot(snapInfo);
        // Attempt to grab it again.
        snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
        if (snapInfo == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup");
        }
    }
    // don't try to perform a sync if the DataStoreRole of the snapshot is equal to DataStoreRole.Primary
    if (!DataStoreRole.Primary.equals(dataStoreRole)) {
        try {
            // sync snapshot to region store if necessary
            final DataStore snapStore = snapInfo.getDataStore();
            final long snapVolId = snapInfo.getVolumeId();
            _snapshotSrv.syncVolumeSnapshotsToRegionStore(snapVolId, snapStore);
        } catch (final Exception ex) {
            // log but ignore the sync error to avoid any potential S3 down issue, it should be sync next time
            s_logger.warn(ex.getMessage(), ex);
        }
    }
    // create volume on primary from snapshot
    final AsyncCallFuture<VolumeService.VolumeApiResult> future = volService.createVolumeFromSnapshot(vol, store, snapInfo);
    try {
        final VolumeService.VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create volume from snapshot:" + result.getResult());
            throw new CloudRuntimeException("Failed to create volume from snapshot:" + result.getResult());
        }
        return result.getVolume();
    } catch (final InterruptedException e) {
        s_logger.debug("Failed to create volume from snapshot", e);
        throw new CloudRuntimeException("Failed to create volume from snapshot", e);
    } catch (final ExecutionException e) {
        s_logger.debug("Failed to create volume from snapshot", e);
        throw new CloudRuntimeException("Failed to create volume from snapshot", e);
    }
}
Also used : Account(com.cloud.user.Account) StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) DataStoreRole(com.cloud.storage.DataStoreRole) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) SnapshotStrategy(com.cloud.engine.subsystem.api.storage.SnapshotStrategy) HashSet(java.util.HashSet) Pod(com.cloud.dc.Pod) Host(com.cloud.host.Host) DiskProfile(com.cloud.vm.DiskProfile) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataCenter(com.cloud.dc.DataCenter) DB(com.cloud.utils.db.DB)

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