Search in sources :

Example 6 with ListTemplateAnswer

use of com.cloud.agent.api.storage.ListTemplateAnswer 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 7 with ListTemplateAnswer

use of com.cloud.agent.api.storage.ListTemplateAnswer in project cloudstack by apache.

the class TemplateServiceImpl method listTemplate.

private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
    String nfsVersion = imageStoreDetailsUtil.getNfsVersion(ssStore.getId());
    ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), nfsVersion);
    EndPoint ep = _epSelector.select(ssStore);
    Answer answer = null;
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        answer = new Answer(cmd, false, errMsg);
    } else {
        answer = ep.sendMessage(cmd);
    }
    if (answer != null && answer.getResult()) {
        ListTemplateAnswer tanswer = (ListTemplateAnswer) answer;
        return tanswer.getTemplateInfo();
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("can not list template for secondary storage host " + ssStore.getId());
        }
    }
    return null;
}
Also used : Answer(com.cloud.agent.api.Answer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)

Aggregations

ListTemplateAnswer (com.cloud.agent.api.storage.ListTemplateAnswer)7 Answer (com.cloud.agent.api.Answer)6 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)5 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)4 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)4 NfsTO (com.cloud.agent.api.to.NfsTO)4 ListTemplateCommand (com.cloud.agent.api.storage.ListTemplateCommand)3 ListVolumeAnswer (com.cloud.agent.api.storage.ListVolumeAnswer)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)3 TemplateProp (com.cloud.storage.template.TemplateProp)3 HashMap (java.util.HashMap)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)2 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)2 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)2 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)2 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)2 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)2