TemplateInfo templateOnStore = context.templateOnStore;
TemplateObject template = (TemplateObject)context.srcTemplate;
AsyncCallFuture<CommandResult> future = context.future;
CommandResult result = new CommandResult();
CreateCmdResult callbackResult = callback.getResult();
if (callbackResult.isFailed()) {
try {
objectInDataStoreMgr.update(templateOnStore, Event.OperationFailed);
} catch (NoTransitionException e) {
s_logger.debug("failed to transit state", e);
}
result.setResult(callbackResult.getResult());
future.complete(result);
return null;
}
ObjectInDataStoreVO obj = objectInDataStoreMgr.findObject(templateOnStore.getId(), templateOnStore.getType(), templateOnStore.getDataStore().getId(), templateOnStore.getDataStore().getRole());
obj.setInstallPath(callbackResult.getPath());
if (callbackResult.getSize() != null) {
obj.setSize(callbackResult.getSize());
}
try {
objectInDataStoreMgr.update(obj, Event.OperationSuccessed);
} catch (NoTransitionException e) {
s_logger.debug("Failed to transit state", e);
result.setResult(e.toString());
future.complete(result);
return null;
}
template.setImageStoreId(templateOnStore.getDataStore().getId());
template.setSize(callbackResult.getSize());
try {
template.stateTransit(TemplateEvent.OperationSucceeded);
} catch (NoTransitionException e) {
s_logger.debug("Failed to transit state", e);
result.setResult(e.toString());