Search in sources :

Example 16 with CopyCommand

use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.

the class Ovm3StorageProcessorTest method copyCommandBogusTest.

/**
     * Copy template from secondary to primary template
     *
     * @throws ConfigurationException
     */
@Test
public void copyCommandBogusTest() throws ConfigurationException {
    con = prepare();
    VolumeObjectTO src = volume(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    VolumeObjectTO dest = volume(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
    CopyCommand copy = new CopyCommand(src, dest, 0, false);
    Answer ra = hypervisor.executeRequest(copy);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 17 with CopyCommand

use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.

the class Ovm3StorageProcessorTest method copyCommandTemplateToVolumeTest.

/**
     * Copy template from primary to primary volume
     *
     * @throws ConfigurationException
     */
@Test
public void copyCommandTemplateToVolumeTest() throws ConfigurationException {
    con = prepare();
    String voluuid = ovmObject.newUuid();
    TemplateObjectTO src = template(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getTemplatesDir());
    VolumeObjectTO dest = volume(voluuid, ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
    CopyCommand copy = new CopyCommand(src, dest, 0, true);
    CopyCmdAnswer ra = (CopyCmdAnswer) hypervisor.executeRequest(copy);
    VolumeObjectTO vol = (VolumeObjectTO) ra.getNewData();
    results.basicStringTest(vol.getUuid(), voluuid);
    results.basicStringTest(vol.getPath(), voluuid);
    results.basicBooleanTest(ra.getResult());
}
Also used : CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 18 with CopyCommand

use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.

the class VMwareGuru method getCommandHostDelegation.

@Override
@DB
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
    boolean needDelegation = false;
    if (cmd instanceof StorageSubSystemCommand) {
        Boolean fullCloneEnabled = VmwareFullClone.value();
        StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(fullCloneEnabled);
    }
    //type is empty, so we need to check the format of volume at first.
    if (cmd instanceof CopyCommand) {
        CopyCommand cpyCommand = (CopyCommand) cmd;
        DataTO srcData = cpyCommand.getSrcTO();
        DataStoreTO srcStoreTO = srcData.getDataStore();
        DataTO destData = cpyCommand.getDestTO();
        DataStoreTO destStoreTO = destData.getDataStore();
        boolean inSeq = true;
        if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
            inSeq = false;
        } else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) {
            inSeq = false;
        } else if (!VmwareFullClone.value()) {
            inSeq = false;
        }
        cpyCommand.setExecuteInSequence(inSeq);
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
        if (!needDelegation && !(HypervisorType.VMware == srcData.getHypervisorType() || HypervisorType.VMware == destData.getHypervisorType())) {
            return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
        }
        if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
            needDelegation = false;
        } else {
            needDelegation = true;
        }
    } else if (cmd instanceof CreateEntityDownloadURLCommand) {
        DataTO srcData = ((CreateEntityDownloadURLCommand) cmd).getData();
        if ((HypervisorType.VMware == srcData.getHypervisorType())) {
            needDelegation = true;
        }
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
    }
    if (!needDelegation) {
        return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
    }
    HostVO host = _hostDao.findById(hostId);
    long dcId = host.getDataCenterId();
    Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
    if (cmdTarget != null) {
        // TODO, we need to make sure agent is actually connected too
        cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
        if (host.getType() == Host.Type.Routing) {
            Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
            cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
            cmd.setContextParam("username", hostDetails.get("username"));
            cmd.setContextParam("password", hostDetails.get("password"));
            cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
            cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
        }
        CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
        _cmdExecLogDao.persist(execLog);
        cmd.setContextParam("execid", String.valueOf(execLog.getId()));
        cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
        cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
        if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand || cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand || cmd instanceof CreateVolumeOVACommand || cmd instanceof PrepareOVAPackingCommand || cmd instanceof CreateVolumeFromSnapshotCommand) {
            String workerName = _vmwareMgr.composeWorkerName();
            long checkPointId = 1;
            // FIXME: Fix                    long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
            cmd.setContextParam("worker", workerName);
            cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
            // some commands use 2 workers
            String workerName2 = _vmwareMgr.composeWorkerName();
            long checkPointId2 = 1;
            // FIXME: Fix                    long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
            cmd.setContextParam("worker2", workerName2);
            cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
        }
        return new Pair<Boolean, Long>(Boolean.TRUE, cmdTarget.first().getId());
    }
    return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
Also used : BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) HostVO(com.cloud.host.HostVO) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) DataTO(com.cloud.agent.api.to.DataTO) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 19 with CopyCommand

use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.

the class NfsSecondaryStorageResource method createTemplateFromSnapshot.

protected Answer createTemplateFromSnapshot(CopyCommand cmd) {
    DataTO srcData = cmd.getSrcTO();
    DataTO destData = cmd.getDestTO();
    DataStoreTO srcDataStore = srcData.getDataStore();
    DataStoreTO destDataStore = destData.getDataStore();
    if (srcDataStore.getRole() == DataStoreRole.Image || srcDataStore.getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Primary) {
        if (!(srcDataStore instanceof NfsTO)) {
            s_logger.debug("only support nfs storage as src, when create template from snapshot");
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        if (destDataStore instanceof NfsTO) {
            return copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) destDataStore);
        } else if (destDataStore instanceof SwiftTO) {
            //create template on the same data store
            CopyCmdAnswer answer = (CopyCmdAnswer) copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) srcDataStore);
            if (!answer.getResult()) {
                return answer;
            }
            s_logger.debug("starting copy template to swift");
            TemplateObjectTO newTemplate = (TemplateObjectTO) answer.getNewData();
            newTemplate.setDataStore(srcDataStore);
            CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
            Answer result = copyFromNfsToSwift(newCpyCmd);
            cleanupStagingNfs(newTemplate);
            return result;
        } else if (destDataStore instanceof S3TO) {
            //create template on the same data store
            CopyCmdAnswer answer = (CopyCmdAnswer) copySnapshotToTemplateFromNfsToNfs(cmd, (SnapshotObjectTO) srcData, (NfsTO) srcDataStore, (TemplateObjectTO) destData, (NfsTO) srcDataStore);
            if (!answer.getResult()) {
                return answer;
            }
            TemplateObjectTO newTemplate = (TemplateObjectTO) answer.getNewData();
            newTemplate.setDataStore(srcDataStore);
            CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence());
            Answer result = copyFromNfsToS3(newCpyCmd);
            cleanupStagingNfs(newTemplate);
            return result;
        }
    }
    s_logger.debug("Failed to create template from snapshot");
    return new CopyCmdAnswer("Unsupported protocol");
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) SwiftTO(com.cloud.agent.api.to.SwiftTO) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) S3TO(com.cloud.agent.api.to.S3TO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 20 with CopyCommand

use of org.apache.cloudstack.storage.command.CopyCommand 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)

Aggregations

CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)20 Answer (com.cloud.agent.api.Answer)11 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)10 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)9 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)7 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)6 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)6 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)6 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)6 DataTO (com.cloud.agent.api.to.DataTO)5 NfsTO (com.cloud.agent.api.to.NfsTO)5 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 Test (org.junit.Test)4 ConnectionTest (com.cloud.hypervisor.ovm3.objects.ConnectionTest)3 LinuxTest (com.cloud.hypervisor.ovm3.objects.LinuxTest)3 StoragePluginTest (com.cloud.hypervisor.ovm3.objects.StoragePluginTest)3 XenTest (com.cloud.hypervisor.ovm3.objects.XenTest)3 XmlTestResultTest (com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)3