use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class DataObjectManagerImpl method copyAsync.
@Override
public void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback<CreateCmdResult> callback) {
try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
} catch (NoTransitionException e) {
s_logger.debug("failed to change state", e);
try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
}
CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to change state: " + e.toString());
callback.complete(res);
} catch (ConcurrentOperationException e) {
s_logger.debug("failed to change state", e);
try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) {
s_logger.debug("failed to further change state to OperationFailed", e1);
}
CreateCmdResult res = new CreateCmdResult(null, null);
res.setResult("Failed to change state: " + e.toString());
callback.complete(res);
}
CopyContext<CreateCmdResult> anotherCall = new CopyContext<CreateCmdResult>(callback, srcData, destData);
AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
motionSrv.copyAsync(srcData, destData, caller);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class BaseImageStoreDriverImpl method createVolumeAsyncCallback.
protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, CreateContext<CreateCmdResult> context) {
DownloadAnswer answer = callback.getResult();
DataObject obj = context.data;
DataStore store = obj.getDataStore();
VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
if (volStoreVO != null) {
if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
}
return null;
}
VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
updateBuilder.setDownloadPercent(answer.getDownloadPct());
updateBuilder.setDownloadState(answer.getDownloadStatus());
updateBuilder.setLastUpdated(new Date());
updateBuilder.setErrorString(answer.getErrorString());
updateBuilder.setJobId(answer.getJobId());
updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
updateBuilder.setInstallPath(answer.getInstallPath());
updateBuilder.setSize(answer.getTemplateSize());
updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
_volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
// update size in volume table
VolumeVO volUpdater = volumeDao.createForUpdate();
volUpdater.setSize(answer.getTemplateSize());
volumeDao.update(obj.getId(), volUpdater);
}
AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(answer.getErrorString());
caller.complete(result);
String msg = "Failed to upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString();
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg);
s_logger.error(msg);
} else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
CreateCmdResult result = new CreateCmdResult(null, null);
caller.complete(result);
}
return null;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class DataObjectManagerImpl method createAsync.
@Override
public void createAsync(DataObject data, DataStore store, AsyncCompletionCallback<CreateCmdResult> callback, boolean noCopy) {
DataObjectInStore obj = objectInDataStoreMgr.findObject(data, store);
DataObject objInStore = null;
boolean freshNewTemplate = false;
if (obj == null) {
try {
objInStore = objectInDataStoreMgr.create(data, store);
freshNewTemplate = true;
} catch (Throwable e) {
obj = objectInDataStoreMgr.findObject(data, store);
if (obj == null) {
CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(e.toString());
callback.complete(result);
return;
}
}
}
if (!freshNewTemplate && obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
try {
objInStore = waitingForCreated(data, store);
} catch (Exception e) {
CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(e.toString());
callback.complete(result);
return;
}
CreateCmdResult result = new CreateCmdResult(null, null);
callback.complete(result);
return;
}
try {
ObjectInDataStoreStateMachine.Event event = null;
if (noCopy) {
event = ObjectInDataStoreStateMachine.Event.CreateOnlyRequested;
} else {
event = ObjectInDataStoreStateMachine.Event.CreateRequested;
}
objectInDataStoreMgr.update(objInStore, event);
} catch (NoTransitionException e) {
try {
objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) {
s_logger.debug("state transation failed", e1);
}
CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(e.toString());
callback.complete(result);
return;
} catch (ConcurrentOperationException e) {
try {
objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed);
} catch (Exception e1) {
s_logger.debug("state transation failed", e1);
}
CreateCmdResult result = new CreateCmdResult(null, null);
result.setSuccess(false);
result.setResult(e.toString());
callback.complete(result);
return;
}
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, objInStore);
AsyncCallbackDispatcher<DataObjectManagerImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createAsynCallback(null, null)).setContext(context);
store.getDriver().createAsync(store, objInStore, caller);
return;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class SimulatorImageStoreDriverImpl method createVolume.
protected void createVolume(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this);
caller.setContext(context);
caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
String path = UUID.randomUUID().toString();
Long size = new Long(5 * 1024L * 1024L);
DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, path, path, size, size, null);
caller.complete(answer);
return;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class SimulatorImageStoreDriverImpl method createTemplate.
protected void createTemplate(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this);
caller.setContext(context);
caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
String path = UUID.randomUUID().toString();
Long size = new Long(5 * 1024L * 1024L);
DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, path, path, size, size, null);
caller.complete(answer);
return;
}
Aggregations