Search in sources :

Example 16 with PrimaryDataStore

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

the class TemplateManagerImplTest method testPrepareTemplateNoHostConnectedToPool.

@Test(expected = CloudRuntimeException.class)
public void testPrepareTemplateNoHostConnectedToPool() {
    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);
    when(mockPrimaryDataStore.getDataCenterId()).thenReturn(1l);
    TemplateDataStoreVO mockTemplateDataStore = mock(TemplateDataStoreVO.class);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong(), nullable(String.class))).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) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 17 with PrimaryDataStore

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

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInOnePool.

@Test
public void testTemplateScheduledForDownloadInOnePool() {
    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.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(), 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 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) 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 18 with PrimaryDataStore

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

the class VMwareGuru method finalizeExpungeVolumes.

@Override
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
    List<Command> commands = new ArrayList<Command>();
    List<VolumeVO> volumes = _volumeDao.findByInstance(vm.getId());
    if (volumes != null) {
        for (VolumeVO volume : volumes) {
            StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
            // so the volume was never assigned to a storage pool)
            if (storagePool != null && storagePool.isManaged() && volume.getVolumeType() == Volume.Type.ROOT) {
                VolumeInfo volumeInfo = _volFactory.getVolume(volume.getId());
                PrimaryDataStore primaryDataStore = (PrimaryDataStore) volumeInfo.getDataStore();
                Map<String, String> details = primaryDataStore.getDetails();
                if (details == null) {
                    details = new HashMap<String, String>();
                    primaryDataStore.setDetails(details);
                }
                details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
                DeleteCommand cmd = new DeleteCommand(volumeInfo.getTO());
                commands.add(cmd);
                break;
            }
        }
    }
    return commands;
}
Also used : DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) VolumeVO(com.cloud.storage.VolumeVO) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) UnregisterNicCommand(com.cloud.agent.api.UnregisterNicCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) Command(com.cloud.agent.api.Command) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) ArrayList(java.util.ArrayList) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 19 with PrimaryDataStore

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

the class ScaleIOPrimaryDataStoreLifeCycleTest method testDeleteDataStoreWithStoragePoolNull.

@Test
public void testDeleteDataStoreWithStoragePoolNull() {
    final PrimaryDataStore store = mock(PrimaryDataStore.class);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(null);
    when(dataStoreHelper.deletePrimaryDataStore(any(DataStore.class))).thenReturn(true);
    final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.deleteDataStore(store);
    assertThat(result).isFalse();
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with PrimaryDataStore

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

the class DirectDownloadManagerImpl method sendDirectDownloadCommand.

/**
 * Send direct download command for downloading template with ID templateId on storage pool with ID poolId.<br/>
 * At first, cmd is sent to host, in case of failure it will retry on other hosts before failing
 * @param cmd direct download command
 * @param template template
 * @param poolId pool id
 * @param host first host to which send the command
 * @return download answer from any host which could handle cmd
 */
private Answer sendDirectDownloadCommand(DirectDownloadCommand cmd, VMTemplateVO template, long poolId, HostVO host) {
    boolean downloaded = false;
    int retry = 3;
    StoragePoolVO storagePoolVO = primaryDataStoreDao.findById(poolId);
    // TODO: Move the host retry attempts to upper layer
    Long[] hostsToRetry = getHostsToRetryOn(host, storagePoolVO);
    int hostIndex = 0;
    Answer answer = null;
    Long hostToSendDownloadCmd = hostsToRetry[hostIndex];
    boolean continueRetrying = true;
    while (!downloaded && retry > 0 && continueRetrying) {
        PrimaryDataStore primaryDataStore = null;
        TemplateInfo templateOnPrimary = null;
        try {
            if (hostToSendDownloadCmd != host.getId() && storagePoolVO.isManaged()) {
                primaryDataStore = (PrimaryDataStore) dataStoreManager.getPrimaryDataStore(poolId);
                templateOnPrimary = primaryDataStore.getTemplate(template.getId(), null);
                if (templateOnPrimary != null) {
                    volService.grantAccess(templateOnPrimary, host, primaryDataStore);
                }
            }
            s_logger.debug("Sending Direct download command to host " + hostToSendDownloadCmd);
            answer = agentManager.easySend(hostToSendDownloadCmd, cmd);
            if (answer != null) {
                DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
                downloaded = answer.getResult();
                continueRetrying = ans.isRetryOnOtherHosts();
            }
            hostToSendDownloadCmd = hostsToRetry[(hostIndex + 1) % hostsToRetry.length];
        } finally {
            if (templateOnPrimary != null) {
                volService.revokeAccess(templateOnPrimary, host, primaryDataStore);
            }
        }
        retry--;
    }
    if (!downloaded) {
        logUsageEvent(template, poolId);
        throw new CloudRuntimeException("Template " + template.getId() + " could not be downloaded on pool " + poolId + ", failing after trying on several hosts");
    }
    return answer;
}
Also used : Answer(com.cloud.agent.api.Answer) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

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