use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method managedCopyBaseImageCallback.
protected Void managedCopyBaseImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final ManagedCreateBaseImageContext<VolumeApiResult> context) {
final CopyCommandResult result = callback.getResult();
final VolumeInfo volumeInfo = context.getVolumeInfo();
final VolumeApiResult res = new VolumeApiResult(volumeInfo);
if (result.isSuccess()) {
// volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer());
final VolumeVO volume = volDao.findById(volumeInfo.getId());
final CopyCmdAnswer answer = (CopyCmdAnswer) result.getAnswer();
final TemplateObjectTO templateObjectTo = (TemplateObjectTO) answer.getNewData();
volume.setPath(templateObjectTo.getPath());
if (templateObjectTo.getFormat() != null) {
volume.setFormat(templateObjectTo.getFormat());
}
volDao.update(volume.getId(), volume);
} else {
volumeInfo.processEvent(Event.DestroyRequested);
res.setResult(result.getResult());
}
final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
future.complete(res);
return null;
}
use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.
@DB
protected Void createVolumeFromBaseImageCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
final DataObject vo = context.vo;
final DataObject tmplOnPrimary = context.templateOnStore;
final CopyCommandResult result = callback.getResult();
final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
if (result.isSuccess()) {
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
} else {
vo.processEvent(Event.OperationFailed);
volResult.setResult(result.getResult());
// hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
// template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
final Answer ans = result.getAnswer();
if (ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")) {
if (tmplOnPrimary != null) {
s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
if (templatePoolRef != null) {
final long templatePoolRefId = templatePoolRef.getId();
templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
try {
if (templatePoolRef == null) {
s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
} else {
templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
_tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
}
} finally {
_tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
}
}
}
}
}
final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
future.complete(volResult);
return null;
}
use of com.cloud.storage.command.CopyCmdAnswer 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);
}
}
}
use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.
the class TemplateObject method processEvent.
@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
try {
if (getDataStore().getRole() == DataStoreRole.Primary) {
if (answer instanceof CopyCmdAnswer) {
final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
final TemplateObjectTO newTemplate = (TemplateObjectTO) cpyAnswer.getNewData();
final VMTemplateStoragePoolVO templatePoolRef = templatePoolDao.findByPoolTemplate(getDataStore().getId(), getId());
templatePoolRef.setDownloadPercent(100);
if (newTemplate.getSize() != null) {
templatePoolRef.setTemplateSize(newTemplate.getSize());
}
templatePoolRef.setDownloadState(Status.DOWNLOADED);
templatePoolRef.setLocalDownloadPath(newTemplate.getPath());
templatePoolRef.setInstallPath(newTemplate.getPath());
templatePoolDao.update(templatePoolRef.getId(), templatePoolRef);
}
} else if (getDataStore().getRole() == DataStoreRole.Image || getDataStore().getRole() == DataStoreRole.ImageCache) {
if (answer instanceof CopyCmdAnswer) {
final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
final TemplateObjectTO newTemplate = (TemplateObjectTO) cpyAnswer.getNewData();
final TemplateDataStoreVO templateStoreRef = templateStoreDao.findByStoreTemplate(getDataStore().getId(), getId());
templateStoreRef.setInstallPath(newTemplate.getPath());
templateStoreRef.setDownloadPercent(100);
templateStoreRef.setDownloadState(Status.DOWNLOADED);
templateStoreRef.setSize(newTemplate.getSize());
if (newTemplate.getPhysicalSize() != null) {
templateStoreRef.setPhysicalSize(newTemplate.getPhysicalSize());
}
templateStoreDao.update(templateStoreRef.getId(), templateStoreRef);
if (getDataStore().getRole() == DataStoreRole.Image) {
final VMTemplateVO templateVO = imageDao.findById(getId());
if (newTemplate.getFormat() != null) {
templateVO.setFormat(newTemplate.getFormat());
}
if (newTemplate.getName() != null) {
// For template created from snapshot, template name is determine by resource code.
templateVO.setUniqueName(newTemplate.getName());
}
if (newTemplate.getHypervisorType() != null) {
templateVO.setHypervisorType(newTemplate.getHypervisorType());
}
templateVO.setSize(newTemplate.getSize());
imageDao.update(templateVO.getId(), templateVO);
}
}
}
objectInStoreMgr.update(this, event);
} catch (final NoTransitionException e) {
s_logger.debug("failed to update state", e);
throw new CloudRuntimeException("Failed to update state" + e.toString());
} catch (final Exception ex) {
s_logger.debug("failed to process event and answer", ex);
objectInStoreMgr.delete(this);
throw new CloudRuntimeException("Failed to process event", ex);
} finally {
// in case of OperationFailed, expunge the entry
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
objectInStoreMgr.deleteIfNotReady(this);
}
}
}
use of com.cloud.storage.command.CopyCmdAnswer in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method copySnapshotAsyncCallback.
protected Void copySnapshotAsyncCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, final CopySnapshotContext<CommandResult> context) {
final CopyCommandResult result = callback.getResult();
final SnapshotInfo destSnapshot = context.destSnapshot;
final SnapshotObject srcSnapshot = (SnapshotObject) context.srcSnapshot;
final AsyncCallFuture<SnapshotResult> future = context.future;
SnapshotResult snapResult = new SnapshotResult(destSnapshot, result.getAnswer());
if (result.isFailed()) {
try {
destSnapshot.processEvent(Event.OperationFailed);
// if backup snapshot failed, mark srcSnapshot in snapshot_store_ref as failed also
srcSnapshot.processEvent(Event.DestroyRequested);
srcSnapshot.processEvent(Event.OperationSuccessed);
srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
_snapshotDao.remove(srcSnapshot.getId());
} catch (final NoTransitionException e) {
s_logger.debug("Failed to update state: " + e.toString());
}
snapResult.setResult(result.getResult());
future.complete(snapResult);
return null;
}
try {
final CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) result.getAnswer();
destSnapshot.processEvent(Event.OperationSuccessed, copyCmdAnswer);
srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded);
snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), copyCmdAnswer);
future.complete(snapResult);
} catch (final Exception e) {
s_logger.debug("Failed to update snapshot state", e);
snapResult.setResult(e.toString());
future.complete(snapResult);
}
return null;
}
Aggregations