Search in sources :

Example 11 with DownloadAnswer

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());
    }
}
Also used : MockVolumeVO(com.cloud.simulator.MockVolumeVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)

Example 12 with DownloadAnswer

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);
}
Also used : MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 13 with DownloadAnswer

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);
}
Also used : SwiftTO(com.cloud.agent.api.to.SwiftTO) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) Test(org.junit.Test)

Example 14 with DownloadAnswer

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);
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Example 15 with DownloadAnswer

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);
        }
    }
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer)

Aggregations

DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)5 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)4 NfsTO (com.cloud.agent.api.to.NfsTO)4 MockVolumeVO (com.cloud.simulator.MockVolumeVO)4 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 DownloadCommand (org.apache.cloudstack.storage.command.DownloadCommand)4 VolumeVO (com.cloud.storage.VolumeVO)3 Date (java.util.Date)3 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)3 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 SwiftTO (com.cloud.agent.api.to.SwiftTO)2 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)2 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ConfigurationException (javax.naming.ConfigurationException)2