use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method copyAsync.
private AsyncCallFuture<TemplateApiResult> copyAsync(final DataObject source, final TemplateInfo template, final DataStore store) {
final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
final DataObject templateOnStore = store.create(template);
templateOnStore.processEvent(Event.CreateOnlyRequested);
final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null)).setContext(context);
_motionSrv.copyAsync(source, templateOnStore, caller);
return future;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method syncToRegionStoreAsync.
private AsyncCallFuture<TemplateApiResult> syncToRegionStoreAsync(final TemplateInfo template, final DataStore store) {
final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
// no need to create entry on template_store_ref here, since entries are already created when prepareSecondaryStorageForMigration is invoked.
// But we need to set default install path so that sync can be done in the right s3 path
final TemplateInfo templateOnStore = _templateFactory.getTemplate(template, store);
final String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + template.getAccountId() + "/" + template.getId() + "/" + template.getUniqueName();
((TemplateObject) templateOnStore).setInstallPath(installPath);
final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().syncTemplateCallBack(null, null)).setContext(context);
_motionSrv.copyAsync(template, templateOnStore, caller);
return future;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult 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.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class StorageSystemDataMotionStrategy method copyAsync.
@Override
public Void copyAsync(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
final CopyCommandResult result = new CopyCommandResult(null, null);
result.setResult("Unsupported operation requested for copying data.");
callback.complete(result);
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class DataObjectManagerImpl method copyCallback.
protected Void copyCallback(final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> callback, final CopyContext<CreateCmdResult> context) {
final CopyCommandResult result = callback.getResult();
final DataObject destObj = context.destObj;
if (result.isFailed()) {
try {
objectInDataStoreMgr.update(destObj, Event.OperationFailed);
} catch (final NoTransitionException e) {
s_logger.debug("Failed to update copying state", e);
} catch (final ConcurrentOperationException e) {
s_logger.debug("Failed to update copying state", e);
}
final CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult(result.getResult());
context.getParentCallback().complete(res);
}
try {
objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
} catch (final NoTransitionException | ConcurrentOperationException e) {
s_logger.debug("Failed to update copying state: ", e);
try {
objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (final Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
}
final CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to update copying state: " + e.toString());
context.getParentCallback().complete(res);
}
final CreateCmdResult res = new CreateCmdResult(result.getPath(), null);
context.getParentCallback().complete(res);
return null;
}
Aggregations