use of org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol in project cloudstack by apache.
the class DirectDownloadManagerImplTest method testGetProtocolNfs.
@Test
public void testGetProtocolNfs() {
String url = "nfs://192.168.1.2/tmpl.qcow2";
DownloadProtocol protocol = DirectDownloadManagerImpl.getProtocolFromUrl(url);
Assert.assertEquals(DownloadProtocol.NFS, protocol);
}
use of org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol in project cloudstack by apache.
the class DirectDownloadManagerImplTest method testGetProtocolHttp.
@Test
public void testGetProtocolHttp() {
String url = "http://192.168.1.2/tmpl.qcow2";
DownloadProtocol protocol = DirectDownloadManagerImpl.getProtocolFromUrl(url);
Assert.assertEquals(DownloadProtocol.HTTP, protocol);
}
use of org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol in project cloudstack by apache.
the class DirectDownloadManagerImplTest method testGetProtocolHttps.
@Test
public void testGetProtocolHttps() {
String url = "https://192.168.1.2/tmpl.qcow2";
DownloadProtocol protocol = DirectDownloadManagerImpl.getProtocolFromUrl(url);
Assert.assertEquals(DownloadProtocol.HTTPS, protocol);
}
use of org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol in project cloudstack by apache.
the class DirectDownloadManagerImplTest method testGetProtocolMetalink.
@Test
public void testGetProtocolMetalink() {
String url = "http://192.168.1.2/tmpl.metalink";
DownloadProtocol protocol = DirectDownloadManagerImpl.getProtocolFromUrl(url);
Assert.assertEquals(DownloadProtocol.METALINK, protocol);
}
use of org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol in project cloudstack by apache.
the class DirectDownloadManagerImpl method downloadTemplate.
@Override
public void downloadTemplate(long templateId, long poolId, long hostId) {
VMTemplateVO template = vmTemplateDao.findById(templateId);
StoragePoolVO pool = primaryDataStoreDao.findById(poolId);
HostVO host = hostDao.findById(hostId);
if (pool == null) {
throw new CloudRuntimeException("Storage pool " + poolId + " could not be found");
}
if (template == null) {
throw new CloudRuntimeException("Template " + templateId + " could not be found");
}
if (host == null) {
throw new CloudRuntimeException("Host " + hostId + " could not be found");
}
if (!template.isDirectDownload()) {
throw new CloudRuntimeException("Template " + templateId + " is not marked for direct download");
}
Map<String, String> details = template.getDetails();
String url = template.getUrl();
String checksum = template.getChecksum();
Map<String, String> headers = getHeadersFromDetails(details);
DataStore store = dataStoreManager.getDataStore(poolId, DataStoreRole.Primary);
if (store == null) {
throw new CloudRuntimeException("Data store " + poolId + " could not be found");
}
PrimaryDataStore primaryDataStore = (PrimaryDataStore) store;
PrimaryDataStoreTO to = (PrimaryDataStoreTO) primaryDataStore.getTO();
DownloadProtocol protocol = getProtocolFromUrl(url);
DirectDownloadCommand cmd = getDirectDownloadCommandFromProtocol(protocol, url, templateId, to, checksum, headers);
cmd.setTemplateSize(template.getSize());
cmd.setFormat(template.getFormat());
if (tmplFactory.getTemplate(templateId, store) != null) {
cmd.setDestData((TemplateObjectTO) tmplFactory.getTemplate(templateId, store).getTO());
}
int cmdTimeOut = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
cmd.setWait(cmdTimeOut);
Answer answer = sendDirectDownloadCommand(cmd, template, poolId, host);
VMTemplateStoragePoolVO sPoolRef = vmTemplatePoolDao.findByPoolTemplate(poolId, templateId, null);
if (sPoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not found (templateId:" + templateId + " poolId: " + poolId + ") in template_spool_ref, persisting it");
}
DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
sPoolRef = new VMTemplateStoragePoolVO(poolId, templateId, null);
sPoolRef.setDownloadPercent(100);
sPoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
sPoolRef.setState(ObjectInDataStoreStateMachine.State.Ready);
sPoolRef.setTemplateSize(ans.getTemplateSize());
sPoolRef.setLocalDownloadPath(ans.getInstallPath());
sPoolRef.setInstallPath(ans.getInstallPath());
vmTemplatePoolDao.persist(sPoolRef);
} else {
// For managed storage, update after template downloaded and copied to the disk
DirectDownloadAnswer ans = (DirectDownloadAnswer) answer;
sPoolRef.setDownloadPercent(100);
sPoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
sPoolRef.setState(ObjectInDataStoreStateMachine.State.Ready);
sPoolRef.setTemplateSize(ans.getTemplateSize());
sPoolRef.setLocalDownloadPath(ans.getInstallPath());
sPoolRef.setInstallPath(ans.getInstallPath());
vmTemplatePoolDao.update(sPoolRef.getId(), sPoolRef);
}
}
Aggregations