use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyBaseImageCallback.
@DB
protected Void copyBaseImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateBaseImageContext<VolumeApiResult> context) {
final CopyCommandResult result = callback.getResult();
final VolumeApiResult res = new VolumeApiResult(context.getVolume());
final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
final DataObject templateOnPrimaryStoreObj = context.destObj;
if (!result.isSuccess()) {
templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
res.setResult(result.getResult());
future.complete(res);
return null;
}
templateOnPrimaryStoreObj.processEvent(Event.OperationSuccessed, result.getAnswer());
createVolumeFromBaseImageAsync(context.volume, templateOnPrimaryStoreObj, context.dataStore, future);
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createBaseImageAsync.
@DB
protected void createBaseImageAsync(final VolumeInfo volume, final PrimaryDataStore dataStore, final TemplateInfo template, final AsyncCallFuture<VolumeApiResult> future) {
final DataObject templateOnPrimaryStoreObj = dataStore.create(template);
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
if (templatePoolRef == null) {
throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId());
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: " + templatePoolRef.getId());
}
}
final long templatePoolRefId = templatePoolRef.getId();
final CreateBaseImageContext<CreateCmdResult> context = new CreateBaseImageContext<>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context);
final int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds");
}
templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds);
if (templatePoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId);
}
templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
return;
}
throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId);
}
if (s_logger.isDebugEnabled()) {
s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId);
}
try {
if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
return;
}
templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested);
motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller);
} finally {
if (s_logger.isDebugEnabled()) {
s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId);
}
_tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
}
return;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromSnapshotCallback.
protected Void createVolumeFromSnapshotCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
final CopyCommandResult result = callback.getResult();
final VolumeInfo volume = (VolumeInfo) context.templateOnStore;
final SnapshotInfo snapshot = context.snapshot;
final VolumeApiResult apiResult = new VolumeApiResult(volume);
Event event = null;
if (result.isFailed()) {
apiResult.setResult(result.getResult());
event = Event.OperationFailed;
} else {
event = Event.OperationSuccessed;
}
try {
if (result.isSuccess()) {
volume.processEvent(event, result.getAnswer());
} else {
volume.processEvent(event);
}
snapshot.processEvent(event);
} catch (final Exception e) {
s_logger.debug("create volume from snapshot failed", e);
apiResult.setResult(e.toString());
}
final AsyncCallFuture<VolumeApiResult> future = context.future;
future.complete(apiResult);
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method migrateVolumes.
@Override
public AsyncCallFuture<CommandResult> migrateVolumes(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost) {
final AsyncCallFuture<CommandResult> future = new AsyncCallFuture<>();
final CommandResult res = new CommandResult();
try {
// Check to make sure there are no snapshot operations on a volume
// and
// put it in the migrating state.
final List<VolumeInfo> volumesMigrating = new ArrayList<>();
for (final Map.Entry<VolumeInfo, DataStore> entry : volumeMap.entrySet()) {
final VolumeInfo volume = entry.getKey();
if (!snapshotMgr.canOperateOnVolume(volume)) {
s_logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now.");
res.setResult("Snapshots are being created on a volume. Volumes cannot be migrated now.");
future.complete(res);
// to be put back in ready state.
for (final VolumeInfo volumeMigrating : volumesMigrating) {
volumeMigrating.processEvent(Event.OperationFailed);
}
return future;
} else {
volume.processEvent(Event.MigrationRequested);
volumesMigrating.add(volume);
}
}
final MigrateVmWithVolumesContext<CommandResult> context = new MigrateVmWithVolumesContext<>(null, future, volumeMap);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().migrateVmWithVolumesCallBack(null, null)).setContext(context);
motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume", e);
res.setResult(e.toString());
future.complete(res);
}
return future;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.
@Override
public void copyAsync(final DataObject srcdata, final DataObject destData, final AsyncCompletionCallback<CopyCommandResult> callback) {
final DataStore store = destData.getDataStore();
if (store.getRole() == DataStoreRole.Primary) {
if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
// For CLVM, we need to copy template to primary storage at all, just fake the copy result.
final TemplateObjectTO templateObjectTO = new TemplateObjectTO();
templateObjectTO.setPath(UUID.randomUUID().toString());
templateObjectTO.setSize(srcdata.getSize());
templateObjectTO.setPhysicalSize(srcdata.getSize());
templateObjectTO.setFormat(Storage.ImageFormat.RAW);
final CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
final CopyCommandResult result = new CopyCommandResult("", answer);
callback.complete(result);
} else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
// For CLVM, we need to pass template on secondary storage to hypervisor
final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
final StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
final DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
final DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
final EndPoint ep = epSelector.select(srcData, destData);
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);
}
final CopyCommandResult result = new CopyCommandResult("", answer);
callback.complete(result);
}
}
}
Aggregations