Search in sources :

Example 11 with CopyCommand

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

the class StorageSystemDataMotionStrategy method performCopyOfVdi.

/**
     * Copies data from secondary storage to a primary volume
     * @param volumeInfo The primary volume
     * @param snapshotInfo  destination of the copy
     * @param hostVO the host used to copy the data
     * @return result of the copy
     */
private CopyCmdAnswer performCopyOfVdi(VolumeInfo volumeInfo, SnapshotInfo snapshotInfo, HostVO hostVO) {
    Snapshot.LocationType locationType = snapshotInfo.getLocationType();
    String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    DataObject srcData = snapshotInfo;
    CopyCmdAnswer copyCmdAnswer = null;
    DataObject cacheData = null;
    boolean needCacheStorage = needCacheStorage(snapshotInfo, volumeInfo);
    if (needCacheStorage) {
        cacheData = cacheSnapshotChain(snapshotInfo, new ZoneScope(volumeInfo.getDataCenterId()));
        srcData = cacheData;
    }
    CopyCommand copyCommand = new CopyCommand(srcData.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    try {
        if (Snapshot.LocationType.PRIMARY.equals(locationType)) {
            _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
            Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
            copyCommand.setOptions(srcDetails);
        }
        _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        Map<String, String> destDetails = getVolumeDetails(volumeInfo);
        copyCommand.setOptions2(destDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) {
        String msg = "Failed to perform VDI copy : ";
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage());
    } finally {
        if (Snapshot.LocationType.PRIMARY.equals(locationType)) {
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        }
        _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        if (needCacheStorage && copyCmdAnswer != null && copyCmdAnswer.getResult()) {
            cacheMgr.deleteCacheObject(cacheData);
        }
    }
    return copyCmdAnswer;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Snapshot(com.cloud.storage.Snapshot) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 12 with CopyCommand

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

the class AncientDataMotionStrategy method cloneVolume.

protected Answer cloneVolume(DataObject template, DataObject volume) {
    CopyCommand cmd = new CopyCommand(template.getTO(), addFullCloneFlagOnVMwareDest(volume.getTO()), 0, VirtualMachineManager.ExecuteInSequence.value());
    try {
        EndPoint ep = selector.select(volume.getDataStore());
        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);
        }
        return answer;
    } catch (Exception e) {
        s_logger.debug("Failed to send to storage pool", e);
        throw new CloudRuntimeException("Failed to send to storage pool", e);
    }
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 13 with CopyCommand

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

the class AncientDataMotionStrategy method copySnapshot.

protected Answer copySnapshot(DataObject srcData, DataObject destData) {
    String value = configDao.getValue(Config.BackupSnapshotWait.toString());
    int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
    DataObject cacheData = null;
    SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
    Object payload = snapshotInfo.getPayload();
    Boolean fullSnapshot = true;
    if (payload != null) {
        fullSnapshot = (Boolean) payload;
    }
    Map<String, String> options = new HashMap<String, String>();
    options.put("fullSnapshot", fullSnapshot.toString());
    Answer answer = null;
    try {
        if (needCacheStorage(srcData, destData)) {
            Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
            cacheData = cacheMgr.getCacheObject(srcData, selectedScope);
            CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setCacheTO(cacheData.getTO());
            cmd.setOptions(options);
            EndPoint ep = selector.select(srcData, destData);
            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);
            }
        } else {
            addFullCloneFlagOnVMwareDest(destData.getTO());
            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setOptions(options);
            EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
            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);
            }
        }
        // clean up cache entry
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    } catch (Exception e) {
        s_logger.debug("copy snasphot failed: " + e.toString());
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : HashMap(java.util.HashMap) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject)

Example 14 with CopyCommand

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

the class AncientDataMotionStrategy method createTemplateFromSnapshot.

@DB
protected Answer createTemplateFromSnapshot(DataObject srcData, DataObject destData) {
    String value = configDao.getValue(Config.CreatePrivateTemplateFromSnapshotWait.toString());
    int _createprivatetemplatefromsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreatePrivateTemplateFromSnapshotWait.getDefaultValue()));
    boolean needCache = false;
    if (needCacheStorage(srcData, destData)) {
        needCache = true;
        SnapshotInfo snapshot = (SnapshotInfo) srcData;
        srcData = cacheSnapshotChain(snapshot, snapshot.getDataStore().getScope());
    }
    EndPoint ep = null;
    if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
        ep = selector.select(destData);
    } else {
        ep = selector.select(srcData, destData);
    }
    CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _createprivatetemplatefromsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
    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);
    }
    // clean up snapshot copied to staging
    if (needCache && srcData != null) {
        // reduce ref count, but keep it there on cache which is converted from previous secondary storage
        cacheMgr.releaseCacheObject(srcData);
    }
    return answer;
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) DB(com.cloud.utils.db.DB)

Example 15 with CopyCommand

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

the class Ovm3StorageProcessorTest method copyCommandTemplateToTemplateTest.

/**
     * Copy template from secondary to primary template
     *
     * @throws ConfigurationException
     */
@Test
public void copyCommandTemplateToTemplateTest() throws ConfigurationException {
    con = prepare();
    con.setMethodResponse("storage_plugin_mount", results.simpleResponseWrapWrapper(storageplugin.getNfsFileSystemInfo()));
    /*
         * because the template requires a reference to the name for the uuid...
         * -sigh-
         */
    String templateid = ovmObject.newUuid();
    String targetid = ovmObject.newUuid();
    String templatedir = "template/tmpl/1/11" + templateid + ".raw";
    String storeUrl = "nfs://" + linux.getRemoteHost() + "/" + linux.getRemoteDir();
    TemplateObjectTO src = template(templateid, linux.getRepoId(), storeUrl, templatedir);
    TemplateObjectTO dest = template(targetid, linux.getRepoId(), linux.getRepoId(), linux.getTemplatesDir());
    CopyCommand copy = new CopyCommand(src, dest, 0, true);
    CopyCmdAnswer ra = (CopyCmdAnswer) hypervisor.executeRequest(copy);
    TemplateObjectTO vol = (TemplateObjectTO) ra.getNewData();
    results.basicStringTest(vol.getUuid(), targetid);
    results.basicStringTest(vol.getPath(), targetid);
    results.basicBooleanTest(ra.getResult());
}
Also used : CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) 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)

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