Search in sources :

Example 1 with DownloadProtocol

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);
}
Also used : DownloadProtocol(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol) Test(org.junit.Test)

Example 2 with DownloadProtocol

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);
}
Also used : DownloadProtocol(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol) Test(org.junit.Test)

Example 3 with DownloadProtocol

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);
}
Also used : DownloadProtocol(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol) Test(org.junit.Test)

Example 4 with DownloadProtocol

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);
}
Also used : DownloadProtocol(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol) Test(org.junit.Test)

Example 5 with DownloadProtocol

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);
    }
}
Also used : DirectDownloadCommand(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand) HttpDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.HttpDirectDownloadCommand) MetalinkDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.MetalinkDirectDownloadCommand) HttpsDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.HttpsDirectDownloadCommand) NfsDirectDownloadCommand(org.apache.cloudstack.agent.directdownload.NfsDirectDownloadCommand) VMTemplateVO(com.cloud.storage.VMTemplateVO) HostVO(com.cloud.host.HostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadProtocol(org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol) DirectDownloadAnswer(org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Aggregations

DownloadProtocol (org.apache.cloudstack.agent.directdownload.DirectDownloadCommand.DownloadProtocol)5 Test (org.junit.Test)4 Answer (com.cloud.agent.api.Answer)1 HostVO (com.cloud.host.HostVO)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 DirectDownloadAnswer (org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer)1 DirectDownloadCommand (org.apache.cloudstack.agent.directdownload.DirectDownloadCommand)1 HttpDirectDownloadCommand (org.apache.cloudstack.agent.directdownload.HttpDirectDownloadCommand)1 HttpsDirectDownloadCommand (org.apache.cloudstack.agent.directdownload.HttpsDirectDownloadCommand)1 MetalinkDirectDownloadCommand (org.apache.cloudstack.agent.directdownload.MetalinkDirectDownloadCommand)1 NfsDirectDownloadCommand (org.apache.cloudstack.agent.directdownload.NfsDirectDownloadCommand)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)1