use of com.cloud.agent.api.storage.DownloadAnswer in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method DownloadProcess.
@Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
String volumeId = cmd.getJobId();
MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
if (volume == null) {
return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
}
long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
volume.setSize(size);
double volumeSize = volume.getSize();
double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
if (pct >= 1.0) {
volume.setStatus(Status.DOWNLOADED);
_mockVolumeDao.update(volume.getId(), volume);
return new DownloadAnswer(cmd.getJobId(), 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(), volume.getName());
} else {
_mockVolumeDao.update(volume.getId(), volume);
return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(), volume.getName());
}
}
use of com.cloud.agent.api.storage.DownloadAnswer in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method Download.
@Override
public DownloadAnswer Download(DownloadCommand cmd) {
MockSecStorageVO ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (ssvo == null) {
return new DownloadAnswer("can't find secondary storage", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
}
MockVolumeVO volume = new MockVolumeVO();
volume.setPoolId(ssvo.getId());
volume.setName(cmd.getName());
volume.setPath(ssvo.getMountPoint() + cmd.getName());
volume.setSize(0);
volume.setType(MockVolumeType.TEMPLATE);
volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
volume = _mockVolumeDao.persist(volume);
return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class LocalNfsSecondaryStorageResourceTest method testExecuteRequest.
@Test
public void testExecuteRequest() throws Exception {
TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
NfsTO cacheStore = Mockito.mock(NfsTO.class);
Mockito.when(cacheStore.getUrl()).thenReturn("nfs://nfs2.lab.vmops.com/export/home/edison/");
SwiftTO swift = Mockito.mock(SwiftTO.class);
Mockito.when(swift.getEndPoint()).thenReturn("https://objects.dreamhost.com/auth");
Mockito.when(swift.getAccount()).thenReturn("cloudstack");
Mockito.when(swift.getUserName()).thenReturn("images");
Mockito.when(swift.getKey()).thenReturn("oxvELQaOD1U5_VyosGfA-wpZ7uBWEff-CUBGCM0u");
Mockito.when(template.getDataStore()).thenReturn(swift);
Mockito.when(template.getPath()).thenReturn("template/1/1/");
Mockito.when(template.isRequiresHvm()).thenReturn(true);
Mockito.when(template.getId()).thenReturn(1L);
Mockito.when(template.getFormat()).thenReturn(Storage.ImageFormat.VHD);
Mockito.when(template.getOrigUrl()).thenReturn("http://nfs1.lab.vmops.com/templates/test.bz2");
Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString());
Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
DownloadCommand cmd = new DownloadCommand(template, 100000L);
cmd.setCacheStore(cacheStore);
DownloadAnswer answer = (DownloadAnswer) resource.executeRequest(cmd);
Assert.assertTrue(answer.getResult());
Mockito.when(template.getPath()).thenReturn(answer.getInstallPath());
Mockito.when(template.getDataStore()).thenReturn(swift);
//download swift:
Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache);
TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class);
Mockito.when(destTemplate.getPath()).thenReturn("template/1/2");
Mockito.when(destTemplate.getDataStore()).thenReturn(cacheStore);
Mockito.when(destTemplate.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
CopyCommand cpyCmd = new CopyCommand(template, destTemplate, 10000, true);
CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) resource.executeRequest(cpyCmd);
Assert.assertTrue(copyCmdAnswer.getResult());
//list template
ListTemplateCommand listCmd = new ListTemplateCommand(swift);
ListTemplateAnswer listAnswer = (ListTemplateAnswer) resource.executeRequest(listCmd);
Assert.assertTrue(listAnswer.getTemplateInfo().size() > 0);
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class SwiftImageStoreDriverImpl method createAsync.
@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
VirtualMachineTemplate tmpl = _templateDao.findById(data.getId());
DataStore cacheStore = cacheManager.getCacheStorage(dataStore.getScope());
DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO) (data.getTO()), maxTemplateSizeInBytes);
dcmd.setCacheStore(cacheStore.getTO());
dcmd.setProxy(getHttpProxy());
EndPoint ep = _epSelector.select(data);
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
AsyncCallbackDispatcher<SwiftImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this);
caller.setContext(context);
if (data.getType() == DataObjectType.TEMPLATE) {
caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
} else if (data.getType() == DataObjectType.VOLUME) {
caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
}
ep.sendMessageAsync(dcmd, caller);
}
use of com.cloud.agent.api.storage.DownloadAnswer in project cloudstack by apache.
the class DownloadMonitorImpl method downloadTemplateToStorage.
@Override
public void downloadTemplateToStorage(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) {
if (template != null) {
long templateId = template.getId();
DataStore store = template.getDataStore();
if (isTemplateUpdateable(templateId, store.getId())) {
if (template.getUri() != null) {
initiateTemplateDownload(template, callback);
} else {
s_logger.info("Template url is null, cannot download");
DownloadAnswer ans = new DownloadAnswer("Template url is null", Status.UNKNOWN);
callback.complete(ans);
}
} else {
s_logger.info("Template download is already in progress or already downloaded");
DownloadAnswer ans = new DownloadAnswer("Template download is already in progress or already downloaded", Status.UNKNOWN);
callback.complete(ans);
}
}
}
Aggregations