use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method executeCommand.
@Override
protected void executeCommand() {
if (!getVm().isDown() && !getVm().isQualifiedForSnapshotMerge()) {
log.error("Cannot remove VM snapshot. Vm is not Down, Up or Paused");
throw new EngineException(EngineError.VM_NOT_QUALIFIED_FOR_SNAPSHOT_MERGE);
}
final Snapshot snapshot = snapshotDao.get(getParameters().getSnapshotId());
boolean snapshotHasImages = hasImages();
boolean removeSnapshotMemory = isMemoryVolumeRemoveable(snapshot);
// No need for locking, VDSM tasks, and all that jazz.
if (!snapshotHasImages && !removeSnapshotMemory) {
snapshotDao.remove(getParameters().getSnapshotId());
setSucceeded(true);
return;
}
lockSnapshot(snapshot);
if (getParameters().isFreeLockNeeded()) {
freeLock();
}
getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VM, getVmId()));
boolean useTaskManagerToRemoveMemory = false;
if (snapshotHasImages) {
removeImages();
if (getSnapshotActionType() == ActionType.RemoveSnapshotSingleDiskLive) {
persistCommand(getParameters().getParentCommand(), true);
useTaskManagerToRemoveMemory = true;
}
}
if (removeSnapshotMemory) {
removeMemory(snapshot, useTaskManagerToRemoveMemory);
if (!snapshotHasImages) {
// no async tasks - ending command manually
endVmCommand();
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method updateLeaseInfo.
private boolean updateLeaseInfo(Guid snapshotLeaseDomainId) {
if (snapshotLeaseDomainId == null) {
// there was no lease for the snapshot
vmDynamicDao.updateVmLeaseInfo(getParameters().getVmId(), null);
return true;
}
VDSReturnValue retVal = null;
try {
retVal = runVdsCommand(VDSCommandType.GetVmLeaseInfo, new VmLeaseVDSParameters(getStoragePoolId(), snapshotLeaseDomainId, getParameters().getVmId()));
} catch (EngineException e) {
log.error("Failure in getting lease info for VM {}, message: {}", getParameters().getVmId(), e.getMessage());
}
if (retVal == null || !retVal.getSucceeded()) {
log.error("Failed to get info on the lease of VM {}", getParameters().getVmId());
return false;
}
vmDynamicDao.updateVmLeaseInfo(getParameters().getVmId(), (Map<String, String>) retVal.getReturnValue());
return true;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class OvfVmIconDefaultsProvider method getVmIconDefaults.
public Map<Integer, VmIconIdSizePair> getVmIconDefaults() {
final Map<Integer, VmIconIdSizePair> result = new HashMap<>();
final List<VmIconDefault> iconDefaults = vmIconDefaultDao.getAll();
for (VmIconDefault iconDefault : iconDefaults) {
result.put(iconDefault.getOsId(), new VmIconIdSizePair(iconDefault.getSmallIconId(), iconDefault.getLargeIconId()));
}
if (!result.containsKey(OsRepository.DEFAULT_X86_OS)) {
throw new EngineException(EngineError.DefaultIconPairNotFound);
}
return result;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class CreateCloneOfTemplateCommand method performImageVdsmOperation.
@Override
protected boolean performImageVdsmOperation() {
setDestinationImageId(Guid.newGuid());
persistCommandIfNeeded();
newDiskImage = cloneDiskImage(getDestinationImageId());
newDiskImage.setId(Guid.newGuid());
Guid storagePoolID = newDiskImage.getStoragePoolId() != null ? newDiskImage.getStoragePoolId() : Guid.Empty;
if (isDataOperationsByHSM()) {
CopyImageGroupWithDataCommandParameters p = new CopyImageGroupWithDataCommandParameters(storagePoolID, getParameters().getStorageDomainId(), getDestinationStorageDomainId(), getDiskImage().getId(), getImage().getImageId(), newDiskImage.getId(), getDestinationImageId(), newDiskImage.getVolumeFormat(), true);
p.setParentParameters(getParameters());
p.setParentCommand(getActionType());
p.setEndProcedure(ActionParametersBase.EndProcedure.COMMAND_MANAGED);
runInternalAction(ActionType.CopyImageGroupWithData, p);
return true;
} else {
Guid taskId = persistAsyncTaskPlaceHolder(ActionType.AddVmFromTemplate);
VDSReturnValue vdsReturnValue;
try {
vdsReturnValue = runVdsCommand(VDSCommandType.CopyImage, postDeleteActionHandler.fixParameters(new CopyImageVDSCommandParameters(storagePoolID, getParameters().getStorageDomainId(), getVmTemplateId(), getDiskImage().getId(), getImage().getImageId(), newDiskImage.getId(), getDestinationImageId(), "", getDestinationStorageDomainId(), CopyVolumeType.LeafVol, newDiskImage.getVolumeFormat(), newDiskImage.getVolumeType(), getDiskImage().isWipeAfterDelete(), storageDomainDao.get(getDestinationStorageDomainId()).getDiscardAfterDelete(), false)));
} catch (EngineException e) {
log.error("Failed creating snapshot from image id '{}'", getImage().getImageId());
throw e;
}
if (vdsReturnValue.getSucceeded()) {
getTaskIdList().add(createTask(taskId, vdsReturnValue.getCreationInfo(), ActionType.AddVmFromTemplate, VdcObjectType.Storage, getParameters().getStorageDomainId(), getDestinationStorageDomainId()));
}
return vdsReturnValue.getSucceeded();
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class ChildCommandsCallbackBase method endAction.
private void endAction(CommandBase<?> commandBase, boolean succeeded) {
if (shouldExecuteEndMethod(commandBase)) {
commandBase.getReturnValue().setSucceeded(false);
ActionReturnValue returnVal = commandBase.endAction();
if (!returnVal.getSucceeded()) {
if (shouldRepeatEndMethodsOnFail(returnVal)) {
throw new EngineException(EngineError.ENGINE, String.format("Command %1$s id: '%2$s' endAction() " + "didn't complete successfully", commandBase.getActionType(), commandBase.getCommandId()));
} else {
log.warn("Command '{}' id: '{}' end method execution failed, as the command isn't marked for " + "endAction() retries silently ignoring", commandBase.getActionType(), commandBase.getCommandId());
}
}
if (!commandBase.isExecutedAsChildCommand()) {
commandCoordinatorUtil.removeAllCommandsInHierarchy(commandBase.getCommandId());
}
ExecutionHandler.getInstance().endJob(commandBase.getExecutionContext(), succeeded);
}
}
Aggregations