use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.
the class KVMGuru method getCommandHostDelegation.
@Override
public Pair<Boolean, Long> getCommandHostDelegation(final long hostId, final Command cmd) {
if (cmd instanceof StorageSubSystemCommand) {
final StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(false);
}
if (cmd instanceof CopyCommand) {
final CopyCommand c = (CopyCommand) cmd;
final DataTO srcData = c.getSrcTO();
boolean inSeq = true;
if (c.getSrcTO().getObjectType() == DataObjectType.SNAPSHOT || c.getDestTO().getObjectType() == DataObjectType.SNAPSHOT) {
inSeq = false;
} else if (c.getDestTO().getDataStore().getRole() == DataStoreRole.Image || c.getDestTO().getDataStore().getRole() == DataStoreRole.ImageCache) {
inSeq = false;
}
c.setExecuteInSequence(inSeq);
if (srcData.getHypervisorType() == HypervisorType.KVM) {
return new Pair<>(true, new Long(hostId));
}
}
return new Pair<>(false, new Long(hostId));
}
use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.
the class StorageSystemDataMotionStrategy method handleCreateTemplateFromSnapshot.
private Void handleCreateTemplateFromSnapshot(final SnapshotInfo snapshotInfo, final TemplateInfo templateInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
try {
snapshotInfo.processEvent(Event.CopyingRequested);
} catch (final Exception ex) {
throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template.");
}
final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
final DataStore srcDataStore = snapshotInfo.getDataStore();
final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
try {
_volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(srcDataStore.getId()), snapshotInfo);
copyCommand.setOptions(srcDetails);
copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
} catch (final Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
} finally {
try {
_volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore);
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
errMsg = copyCmdAnswer.getDetails();
} else {
errMsg = "Unable to perform host-side operation";
}
}
try {
if (errMsg == null) {
snapshotInfo.processEvent(Event.OperationSuccessed);
} else {
snapshotInfo.processEvent(Event.OperationFailed);
}
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
}
final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
return null;
}
use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.
the class AncientDataMotionStrategy method copyObject.
protected Answer copyObject(final DataObject srcData, final DataObject destData, final Host destHost) {
final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
Answer answer = null;
DataObject cacheData = null;
DataObject srcForCopy = srcData;
try {
if (needCacheStorage(srcData, destData)) {
final Scope destScope = pickCacheScopeForCopy(srcData, destData);
srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope);
}
final CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), destData.getTO(), _primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
final EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, destData);
if (ep == null) {
final 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 (cacheData != null) {
final Long cacheId = cacheData.getId();
final String cacheType = cacheData.getType().toString();
final String cacheUuid = cacheData.getUuid().toString();
if (srcData.getType() == DataObjectType.VOLUME && (destData.getType() == DataObjectType.VOLUME || destData.getType() == DataObjectType.TEMPLATE)) {
// volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools
// Delete cache in order to certainly transfer a latest image.
s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
cacheMgr.deleteCacheObject(srcForCopy);
} else {
// for template, we want to leave it on cache for performance reason
if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
// cache object created by this copy, not already there
s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
cacheMgr.deleteCacheObject(srcForCopy);
} else {
s_logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
cacheMgr.releaseCacheObject(srcForCopy);
}
}
}
return answer;
} catch (final Exception e) {
s_logger.debug("copy object failed: ", e);
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
throw new CloudRuntimeException(e.toString());
}
}
use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.
the class AncientDataMotionStrategy method copySnapshot.
protected Answer copySnapshot(final DataObject srcData, final DataObject destData) {
final String value = configDao.getValue(Config.BackupSnapshotWait.toString());
final int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
DataObject cacheData = null;
final SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
final Object payload = snapshotInfo.getPayload();
Boolean fullSnapshot = true;
if (payload != null) {
fullSnapshot = (Boolean) payload;
}
final Map<String, String> options = new HashMap<>();
options.put("fullSnapshot", fullSnapshot.toString());
Answer answer = null;
try {
if (needCacheStorage(srcData, destData)) {
final Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
cacheData = cacheMgr.getCacheObject(srcData, selectedScope);
final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
cmd.setCacheTO(cacheData.getTO());
cmd.setOptions(options);
final EndPoint ep = selector.select(srcData, destData);
if (ep == null) {
final 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 {
final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
cmd.setOptions(options);
final EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
if (ep == null) {
final 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 (final Exception e) {
s_logger.debug("copy snasphot failed: " + e.toString());
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
throw new CloudRuntimeException(e.toString());
}
}
use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.
the class AncientDataMotionStrategy method cloneVolume.
protected Answer cloneVolume(final DataObject template, final DataObject volume) {
final CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0, VirtualMachineManager.ExecuteInSequence.value());
try {
final EndPoint ep = selector.select(volume.getDataStore());
Answer answer = null;
if (ep == null) {
final 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 (final Exception e) {
s_logger.debug("Failed to send to storage pool", e);
throw new CloudRuntimeException("Failed to send to storage pool", e);
}
}
Aggregations