use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.
the class RebootVmCommand method perform.
@Override
protected void perform() {
if (isColdReboot()) {
ActionReturnValue returnValue = runInternalAction(ActionType.ShutdownVm, new ShutdownVmParameters(getVmId(), false));
setReturnValue(returnValue);
setSucceeded(returnValue.getSucceeded());
if (getSucceeded()) {
resourceManager.getVmManager(getVmId()).setColdReboot(true);
}
} else {
final VDSReturnValue returnValue = runVdsCommand(VDSCommandType.RebootVm, new VdsAndVmIDVDSParametersBase(getVdsId(), getVmId()));
setActionReturnValue(returnValue.getReturnValue());
setSucceeded(returnValue.getSucceeded());
}
}
use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.
the class CreateSnapshotCommand method performImageVdsmOperation.
@Override
protected boolean performImageVdsmOperation() {
setDestinationImageId(Guid.isNullOrEmpty(getParameters().getDestinationImageId()) ? Guid.newGuid() : getParameters().getDestinationImageId());
persistCommandIfNeeded();
newDiskImage = cloneDiskImage(getDestinationImageId());
newDiskImage.setStorageIds(new ArrayList<>(Arrays.asList(getDestinationStorageDomainId())));
setStoragePoolId(newDiskImage.getStoragePoolId() != null ? newDiskImage.getStoragePoolId() : Guid.Empty);
getParameters().setStoragePoolId(getStoragePoolId());
// override volume type and volume format to sparse and cow according to
// storage team request
newDiskImage.setVolumeType(VolumeType.Sparse);
newDiskImage.setVolumeFormat(VolumeFormat.COW);
try {
Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.CreateVolume, new CreateVolumeVDSCommandParameters(getStoragePoolId(), getDestinationStorageDomainId(), getImageGroupId(), getImage().getImageId(), getDiskImage().getSize(), newDiskImage.getVolumeType(), newDiskImage.getVolumeFormat(), getDiskImage().getId(), getDestinationImageId(), "", getStoragePool().getCompatibilityVersion(), getDiskImage().getContentType()));
if (vdsReturnValue != null && vdsReturnValue.getSucceeded()) {
getParameters().setVdsmTaskIds(new ArrayList<>());
getParameters().getVdsmTaskIds().add(createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId(), getParameters().getDestinationImageId()));
getReturnValue().getInternalVdsmTaskIdList().add(getParameters().getVdsmTaskIds().get(0));
// Shouldn't happen anymore:
if (getDestinationImageId().equals(Guid.Empty)) {
throw new RuntimeException();
}
return true;
}
} catch (Exception e) {
log.error("Failed creating snapshot from image id '{}'", getImage().getImageId());
commandCoordinatorUtil.logAndFailTaskOfCommandWithEmptyVdsmId(getAsyncTaskId(), "Create snapshot failed at VDSM. DB task ID is " + getAsyncTaskId());
throw new EngineException(EngineError.VolumeCreationError);
}
return false;
}
use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue 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.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.
the class DiskImagesValidator method diskImagesOnStorage.
/**
* checks that the given disks do not exist on the target storage domains
* @param imageToDestinationDomainMap map containing the destination domain for each of the disks
* @param storagePoolId the storage pool ID to check whether the disks are residing on
* @return validation result indicating whether the disks don't exist on the target storage domains
*/
public ValidationResult diskImagesOnStorage(Map<Guid, Guid> imageToDestinationDomainMap, Guid storagePoolId) {
Map<Guid, List<Guid>> domainImages = new HashMap<>();
for (DiskImage diskImage : diskImages) {
Guid targetStorageDomainId = imageToDestinationDomainMap.get(diskImage.getId());
List<Guid> imagesOnStorageDomain = domainImages.get(targetStorageDomainId);
if (imagesOnStorageDomain == null) {
VDSReturnValue returnValue = Backend.getInstance().getResourceManager().runVdsCommand(VDSCommandType.GetImagesList, new GetImagesListVDSCommandParameters(targetStorageDomainId, storagePoolId));
if (returnValue.getSucceeded()) {
imagesOnStorageDomain = (List<Guid>) returnValue.getReturnValue();
domainImages.put(targetStorageDomainId, imagesOnStorageDomain);
} else {
return new ValidationResult(EngineMessage.ERROR_GET_IMAGE_LIST, String.format("$sdName %1$s", getStorageDomainStaticDao().get(targetStorageDomainId).getName()));
}
}
if (imagesOnStorageDomain.contains(diskImage.getId())) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_ALREADY_CONTAINS_DISK);
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.
the class GetUnregisteredDisksQueryTest method prepareMocks.
/**
* Mock the VDSBroker and the Daos
*/
private void prepareMocks() {
DiskImage existingDiskImage = mock(DiskImage.class);
when(existingDiskImage.getId()).thenReturn(existingDiskId);
List<DiskImage> existingDiskImages = Collections.singletonList(existingDiskImage);
// Mock the get images List VDS command
VDSReturnValue volListReturnValue = new VDSReturnValue();
volListReturnValue.setSucceeded(true);
volListReturnValue.setReturnValue(importDiskIds);
doReturn(volListReturnValue).when(vdsBroker).runVdsCommand(eq(VDSCommandType.GetImagesList), any());
// Mock the get unregistered disk query
when(backendMock.runInternalQuery(eq(QueryType.GetUnregisteredDisk), any(), any())).thenAnswer(invocation -> {
GetUnregisteredDiskQueryParameters p = (GetUnregisteredDiskQueryParameters) invocation.getArguments()[1];
QueryReturnValue unregDiskReturnValue = new QueryReturnValue();
unregDiskReturnValue.setSucceeded(true);
DiskImage newDiskImage = mock(DiskImage.class);
when(newDiskImage.getId()).thenReturn(p.getDiskId());
unregDiskReturnValue.setReturnValue(newDiskImage);
return unregDiskReturnValue;
});
doReturn(storagePoolId).when(getQuery()).getStoragePoolId();
doReturn(storageDomainId).when(getQuery()).getStorageDomainId();
when(diskImageDaoMock.getAllSnapshotsForStorageDomain(eq(storageDomainId))).thenReturn(existingDiskImages);
}
Aggregations