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);
}
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);
}
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;
}
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();
}
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;
}
Aggregations