Search in sources :

Example 36 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint 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 37 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint 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 38 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class VolumeServiceImpl method registerVolumeForPostUpload.

@Override
public Pair<EndPoint, DataObject> registerVolumeForPostUpload(VolumeInfo volume, DataStore store) {
    EndPoint ep = _epSelector.select(store);
    if (ep == null) {
        String errorMessage = "There is no secondary storage VM for image store " + store.getName();
        s_logger.warn(errorMessage);
        throw new CloudRuntimeException(errorMessage);
    }
    DataObject volumeOnStore = store.create(volume);
    return new Pair<>(ep, volumeOnStore);
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) Pair(com.cloud.utils.Pair)

Example 39 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class VolumeServiceImpl method resizeVolumeOnHypervisor.

@Override
public void resizeVolumeOnHypervisor(long volumeId, long newSize, long destHostId, String instanceName) {
    final String errMsg = "Resize command failed";
    try {
        Answer answer = null;
        Host destHost = _hostDao.findById(destHostId);
        EndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(destHost);
        if (ep != null) {
            VolumeVO volume = volDao.findById(volumeId);
            PrimaryDataStore primaryDataStore = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
            ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(volume.getPath(), new StorageFilerTO(primaryDataStore), volume.getSize(), newSize, true, instanceName, primaryDataStore.isManaged(), volume.get_iScsiName());
            answer = ep.sendMessage(resizeCmd);
        } else {
            throw new CloudRuntimeException("Could not find a remote endpoint to send command to. Check if host or SSVM is down.");
        }
        if (answer == null || !answer.getResult()) {
            throw new CloudRuntimeException(answer != null ? answer.getDetails() : errMsg);
        }
    } catch (Exception e) {
        throw new CloudRuntimeException(errMsg, e);
    }
}
Also used : Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) Host(com.cloud.host.Host) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 40 with EndPoint

use of org.apache.cloudstack.engine.subsystem.api.storage.EndPoint in project cloudstack by apache.

the class DefaultEndPointSelector method select.

@Override
public EndPoint select(DataObject object) {
    DataStore store = object.getDataStore();
    EndPoint ep = select(store);
    if (ep != null) {
        return ep;
    }
    if (object instanceof TemplateInfo) {
        TemplateInfo tmplInfo = (TemplateInfo) object;
        if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null && tmplInfo.getTemplateType() == TemplateType.SYSTEM) {
            // for bootstrap system vm template downloading to region image store
            return LocalHostEndpoint.getEndpoint();
        }
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint)

Aggregations

EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)44 Answer (com.cloud.agent.api.Answer)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)22 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)17 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)13 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)10 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)9 Date (java.util.Date)8 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)8 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)7 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)6 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)5 HostVO (com.cloud.host.HostVO)5 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)5 UploadVO (com.cloud.storage.UploadVO)4 URISyntaxException (java.net.URISyntaxException)4 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)4 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)4 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)4 CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)3