use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RemoveAllVmTemplateImageTemplatesCommand method executeCommand.
@SuppressWarnings("unchecked")
@Override
protected void executeCommand() {
List<DiskImage> imageTemplates = DisksFilter.filterImageDisks(diskDao.getAllForVm(getVmTemplateId()), ONLY_ACTIVE);
for (DiskImage template : imageTemplates) {
// remove this disk in all domain that were sent
for (Guid domain : (Collection<Guid>) CollectionUtils.intersection(getParameters().getStorageDomainsList(), template.getStorageIds())) {
ImagesContainterParametersBase tempVar = new ImagesContainterParametersBase(template.getImageId(), getVmTemplateId());
tempVar.setStorageDomainId(domain);
tempVar.setStoragePoolId(template.getStoragePoolId());
tempVar.setImageGroupID(template.getId());
tempVar.setEntityInfo(getParameters().getEntityInfo());
tempVar.setWipeAfterDelete(template.isWipeAfterDelete());
tempVar.setTransactionScopeOption(TransactionScopeOption.RequiresNew);
tempVar.setParentCommand(getActionType());
tempVar.setParentParameters(getParameters());
ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.RemoveTemplateSnapshot, tempVar);
if (actionReturnValue.getSucceeded()) {
getReturnValue().getInternalVdsmTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
} else {
log.error("Can't remove image id '{}' for template id '{}' from domain id '{}' due to: {}.", template.getImageId(), getVmTemplateId(), domain, actionReturnValue.getFault().getMessage());
}
imageStorageDomainMapDao.remove(new ImageStorageDomainMapId(template.getImageId(), domain));
}
DiskImage diskImage = diskImageDao.get(template.getImageId());
if (diskImage != null) {
baseDiskDao.remove(template.getId());
vmDeviceDao.remove(new VmDeviceId(diskImage.getImageId(), getVmTemplateId()));
imageStorageDomainMapDao.remove(diskImage.getImageId());
imageDao.remove(template.getImageId());
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class AbstractVmInterfaceCommand method activateOrDeactivateNic.
protected boolean activateOrDeactivateNic(VmNic nic, PlugAction plugAction, boolean newNic) {
ActivateDeactivateVmNicParameters parameters = new ActivateDeactivateVmNicParameters(nic, plugAction, newNic);
parameters.setVmId(getParameters().getVmId());
ActionReturnValue returnValue = runInternalAction(ActionType.ActivateDeactivateVmNic, parameters, cloneContextAndDetachFromParent());
if (!returnValue.getSucceeded()) {
propagateFailure(returnValue);
}
return returnValue.getSucceeded();
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class SyncAllHostNetworksCommand method executeCommand.
@Override
protected void executeCommand() {
PersistentHostSetupNetworksParameters parameters = generateSyncAllHostNetworksParameters();
ActionReturnValue retVal = runInternalAction(ActionType.PersistentHostSetupNetworks, parameters, cloneContextAndDetachFromParent());
if (!retVal.getSucceeded()) {
propagateFailure(retVal);
} else {
setSucceeded(true);
}
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method deleteOrphanedImages.
protected void deleteOrphanedImages(List<CinderDisk> cinderDisksToRemove) {
ActionReturnValue returnValue;
boolean noImagesRemovedYet = getTaskIdList().isEmpty();
Set<Guid> deletedDisksIds = new HashSet<>();
for (DiskImage image : diskImageDao.getImagesWithNoDisk(getVm().getId())) {
if (!deletedDisksIds.contains(image.getId())) {
deletedDisksIds.add(image.getId());
if (image.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisksToRemove.add((CinderDisk) image);
continue;
}
returnValue = runAsyncTask(ActionType.RemoveImage, new RemoveImageParameters(image.getImageId()));
if (!returnValue.getSucceeded() && noImagesRemovedYet) {
setSucceeded(false);
getReturnValue().setFault(returnValue.getFault());
return;
}
noImagesRemovedYet = false;
}
}
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
if (!getImagesList().isEmpty()) {
lockVmWithCompensationIfNeeded();
if (!isInternalExecution()) {
freeLock();
}
}
initializeSnapshotsLeasesDomainIds();
restoreSnapshotAndRemoveObsoleteSnapshots(getSnapshot());
boolean succeeded = removeLeaseIfNeeded();
List<CinderDisk> cinderDisksToRestore = new ArrayList<>();
for (DiskImage image : imagesToRestore) {
if (image.getImageStatus() != ImageStatus.ILLEGAL) {
if (image.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisksToRestore.add((CinderDisk) image);
continue;
}
ImagesContainterParametersBase params = new RestoreFromSnapshotParameters(image.getImageId(), getVmId(), getSnapshot(), removedSnapshot.getId());
ActionReturnValue returnValue = runAsyncTask(ActionType.RestoreFromSnapshot, params);
// Save the first fault
if (succeeded && !returnValue.getSucceeded()) {
succeeded = false;
getReturnValue().setFault(returnValue.getFault());
}
}
}
List<CinderDisk> cinderVolumesToRemove = new ArrayList<>();
List<CinderDisk> cinderDisksToRemove = new ArrayList<>();
removeUnusedImages(cinderVolumesToRemove);
if (getSnapshot().getType() == SnapshotType.REGULAR) {
snapshotsToRemove.addAll(findSnapshotsWithOnlyIllegalDisks());
setNewerVmConfigurationsAsBroken();
}
removeSnapshotsFromDB();
succeeded = updateLeaseInfoIfNeeded() && succeeded;
if (!getTaskIdList().isEmpty() || !cinderDisksToRestore.isEmpty() || !cinderVolumesToRemove.isEmpty()) {
deleteOrphanedImages(cinderDisksToRemove);
if (!restoreCinderDisks(removedSnapshot.getId(), cinderDisksToRestore, cinderDisksToRemove, cinderVolumesToRemove)) {
log.error("Error to restore Cinder volumes snapshots");
}
} else {
vmStaticDao.incrementDbGeneration(getVm().getId());
snapshotDao.updateStatus(getSnapshot().getId(), SnapshotStatus.OK);
unlockVm();
}
setSucceeded(succeeded);
}
Aggregations