cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jburwell <...@git.apache.org>
Subject [GitHub] cloudstack pull request: Taking fast and efficient volume snapshot...
Date Fri, 08 Apr 2016 20:08:16 GMT
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1403#discussion_r59082041
  
    --- Diff: engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
---
    @@ -361,59 +608,225 @@ private String getProperty(long snapshotId, String property) {
         }
     
         private Map<String, String> getVolumeDetails(VolumeInfo volumeInfo) {
    -        Map<String, String> sourceDetails = new HashMap<String, String>();
    +        Map<String, String> volumeDetails = new HashMap<String, String>();
     
             VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
     
             long storagePoolId = volumeVO.getPoolId();
             StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);
     
    -        sourceDetails.put(DiskTO.STORAGE_HOST, storagePoolVO.getHostAddress());
    -        sourceDetails.put(DiskTO.STORAGE_PORT, String.valueOf(storagePoolVO.getPort()));
    -        sourceDetails.put(DiskTO.IQN, volumeVO.get_iScsiName());
    +        volumeDetails.put(DiskTO.STORAGE_HOST, storagePoolVO.getHostAddress());
    +        volumeDetails.put(DiskTO.STORAGE_PORT, String.valueOf(storagePoolVO.getPort()));
    +        volumeDetails.put(DiskTO.IQN, volumeVO.get_iScsiName());
     
             ChapInfo chapInfo = _volumeService.getChapInfo(volumeInfo, volumeInfo.getDataStore());
     
             if (chapInfo != null) {
    -            sourceDetails.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
    -            sourceDetails.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
    -            sourceDetails.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
    -            sourceDetails.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
    +            volumeDetails.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
    +            volumeDetails.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
    +            volumeDetails.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
    +            volumeDetails.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
    +        }
    +
    +        return volumeDetails;
    +    }
    +
    +    private Map<String, String> getSnapshotDetails(SnapshotInfo snapshotInfo) {
    +        Map<String, String> snapshotDetails = new HashMap<String, String>();
    +
    +        long storagePoolId = snapshotInfo.getDataStore().getId();
    +        StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);
    +
    +        snapshotDetails.put(DiskTO.STORAGE_HOST, storagePoolVO.getHostAddress());
    +        snapshotDetails.put(DiskTO.STORAGE_PORT, String.valueOf(storagePoolVO.getPort()));
    +
    +        long snapshotId = snapshotInfo.getId();
    +
    +        snapshotDetails.put(DiskTO.IQN, getProperty(snapshotId, DiskTO.IQN));
    +
    +        snapshotDetails.put(DiskTO.CHAP_INITIATOR_USERNAME, getProperty(snapshotId, DiskTO.CHAP_INITIATOR_USERNAME));
    +        snapshotDetails.put(DiskTO.CHAP_INITIATOR_SECRET, getProperty(snapshotId, DiskTO.CHAP_INITIATOR_SECRET));
    +        snapshotDetails.put(DiskTO.CHAP_TARGET_USERNAME, getProperty(snapshotId, DiskTO.CHAP_TARGET_USERNAME));
    +        snapshotDetails.put(DiskTO.CHAP_TARGET_SECRET, getProperty(snapshotId, DiskTO.CHAP_TARGET_SECRET));
    +
    +        return snapshotDetails;
    +    }
    +
    +    private HostVO getHost(SnapshotInfo snapshotInfo) {
    +        HostVO hostVO = getHost(snapshotInfo.getDataCenterId(), true);
    +
    +        if (hostVO == null) {
    +            hostVO = getHost(snapshotInfo.getDataCenterId(), false);
    +
    +            if (hostVO == null) {
    +                throw new CloudRuntimeException("Unable to locate an applicable host");
    +            }
             }
     
    -        return sourceDetails;
    +        return hostVO;
         }
     
    -    public HostVO getHost(long dataStoreId) {
    -        StoragePoolVO storagePoolVO = _storagePoolDao.findById(dataStoreId);
    +    private HostVO getHost(Long zoneId, boolean computeClusterMustSupportResign) {
    +        if (zoneId == null) {
    +            throw new CloudRuntimeException("Zone ID cannot be null.");
    +        }
     
    -        List<? extends Cluster> clusters = _mgr.searchForClusters(storagePoolVO.getDataCenterId(),
new Long(0), Long.MAX_VALUE, HypervisorType.XenServer.toString());
    +        List<? extends Cluster> clusters = _mgr.searchForClusters(zoneId, new Long(0),
Long.MAX_VALUE, HypervisorType.XenServer.toString());
     
             if (clusters == null) {
    -            throw new CloudRuntimeException("Unable to locate an applicable cluster");
    +            clusters = new ArrayList<>();
             }
     
    +        Collections.shuffle(clusters, new Random(System.nanoTime()));
    +
    +        clusters:
             for (Cluster cluster : clusters) {
                 if (cluster.getAllocationState() == AllocationState.Enabled) {
                     List<HostVO> hosts = _hostDao.findByClusterId(cluster.getId());
     
                     if (hosts != null) {
    +                    Collections.shuffle(hosts, new Random(System.nanoTime()));
    +
                         for (HostVO host : hosts) {
                             if (host.getResourceState() == ResourceState.Enabled) {
    -                            return host;
    +                            if (computeClusterMustSupportResign) {
    +                                if (computeClusterSupportsResign(cluster.getId())) {
    +                                    return host;
    +                                }
    +                                else {
    +                                    // no other host in the cluster in question should
be able to satisfy our requirements here, so move on to the next cluster
    +                                    continue clusters;
    +                                }
    +                            }
    +                            else {
    +                                return host;
    +                            }
                             }
                         }
                     }
                 }
             }
     
    -        throw new CloudRuntimeException("Unable to locate an applicable cluster");
    +        return null;
         }
     
         @Override
         public void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO
vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback)
{
             CopyCommandResult result = new CopyCommandResult(null, null);
    +
             result.setResult("Unsupported operation requested for copying data.");
    +
             callback.complete(result);
         }
    +
    +    private Map<String, String> getDetails(DataObject dataObj) {
    +        if (dataObj instanceof VolumeInfo) {
    +            return getVolumeDetails((VolumeInfo)dataObj);
    +        }
    +        else if (dataObj instanceof SnapshotInfo) {
    +            return getSnapshotDetails((SnapshotInfo)dataObj);
    +        }
    +
    +        throw new CloudRuntimeException("'dataObj' must be of type 'VolumeInfo' or 'SnapshotInfo'.");
    +    }
    +
    +    private CopyCmdAnswer performResignature(DataObject dataObj, HostVO hostVO) {
    +        return performResignature(dataObj, hostVO, false);
    +    }
    +
    +    private CopyCmdAnswer performResignature(DataObject dataObj, HostVO hostVO, boolean
keepGrantedAccess) {
    +        long storagePoolId = dataObj.getDataStore().getId();
    +        DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    +
    +        Map<String, String> details = getDetails(dataObj);
    +
    +        ResignatureCommand command = new ResignatureCommand(details);
    +
    +        ResignatureAnswer answer = null;
    +
    +        try {
    +            _volumeService.grantAccess(dataObj, hostVO, dataStore);
    +
    +            answer = (ResignatureAnswer)_agentMgr.send(hostVO.getId(), command);
    +        }
    +        catch (Exception ex) {
    +            keepGrantedAccess = false;
    +
    +            throw new CloudRuntimeException(ex.getMessage());
    +        }
    +        finally {
    +            if (keepGrantedAccess == false) {
    +                try {
    +                    _volumeService.revokeAccess(dataObj, hostVO, dataStore);
    +                }
    +                catch (Exception ex) {
    +                    s_logger.debug(ex.getMessage(), ex);
    +                }
    +            }
    +        }
    +
    +        if (answer == null || !answer.getResult()) {
    +            final String errMsg;
    +
    +            if (answer != null && answer.getDetails() != null && !answer.getDetails().isEmpty())
{
    +                errMsg = answer.getDetails();
    +            }
    +            else {
    +                errMsg = "Unable to perform resignature operation";
    +            }
    +
    +            throw new CloudRuntimeException(errMsg);
    +        }
    +
    +        VolumeObjectTO newVolume = new VolumeObjectTO();
    +
    +        newVolume.setSize(answer.getSize());
    +        newVolume.setPath(answer.getPath());
    +        newVolume.setFormat(answer.getFormat());
    +
    +        return new CopyCmdAnswer(newVolume);
    +    }
    +
    +    private CopyCmdAnswer performCopyOfVdi(VolumeInfo volumeInfo, SnapshotInfo snapshotInfo,
HostVO hostVO) {
    +        String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    +        int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    +        CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(),
primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    +
    +        CopyCmdAnswer copyCmdAnswer = null;
    +
    +        try {
    +            _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
    +            _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
    +
    +            Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
    +
    +            copyCommand.setOptions(srcDetails);
    +
    +            Map<String, String> destDetails = getVolumeDetails(volumeInfo);
    +
    +            copyCommand.setOptions2(destDetails);
    +
    +            copyCmdAnswer = (CopyCmdAnswer)_agentMgr.send(hostVO.getId(), copyCommand);
    +        }
    +        catch (Exception ex) {
    +            throw new CloudRuntimeException(ex.getMessage());
    --- End diff --
    
    Please add contextual information about the copy VDI operation to error message to assist
with operational debugging.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message