use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class UpdateVmCommand method updateWatchdog.
private void updateWatchdog() {
// do not update if this flag is not set
if (getParameters().isUpdateWatchdog()) {
QueryReturnValue query = runInternalQuery(QueryType.GetWatchdog, new IdQueryParameters(getParameters().getVmId()));
List<VmWatchdog> watchdogs = query.getReturnValue();
if (watchdogs.isEmpty()) {
if (getParameters().getWatchdog() == null) {
// nothing to do, no watchdog and no watchdog to create
} else {
WatchdogParameters parameters = new WatchdogParameters();
parameters.setId(getParameters().getVmId());
parameters.setAction(getParameters().getWatchdog().getAction());
parameters.setModel(getParameters().getWatchdog().getModel());
runInternalAction(ActionType.AddWatchdog, parameters, cloneContextAndDetachFromParent());
}
} else {
WatchdogParameters watchdogParameters = new WatchdogParameters();
watchdogParameters.setId(getParameters().getVmId());
if (getParameters().getWatchdog() == null) {
// there is a watchdog in the vm, there should not be any, so let's delete
runInternalAction(ActionType.RemoveWatchdog, watchdogParameters, cloneContextAndDetachFromParent());
} else {
// there is a watchdog in the vm, we have to update.
watchdogParameters.setAction(getParameters().getWatchdog().getAction());
watchdogParameters.setModel(getParameters().getWatchdog().getModel());
runInternalAction(ActionType.UpdateWatchdog, watchdogParameters, cloneContextAndDetachFromParent());
}
}
}
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class UpdateVmCommand method updateRngDevice.
private void updateRngDevice() {
if (!getParameters().isUpdateRngDevice()) {
return;
}
QueryReturnValue query = runInternalQuery(QueryType.GetRngDevice, new IdQueryParameters(getParameters().getVmId()));
List<VmRngDevice> rngDevs = query.getReturnValue();
ActionReturnValue rngCommandResult = null;
if (rngDevs.isEmpty()) {
if (getParameters().getRngDevice() != null) {
RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), true);
rngCommandResult = runInternalAction(ActionType.AddRngDevice, params, cloneContextAndDetachFromParent());
}
} else {
if (getParameters().getRngDevice() == null) {
RngDeviceParameters params = new RngDeviceParameters(rngDevs.get(0), true);
rngCommandResult = runInternalAction(ActionType.RemoveRngDevice, params, cloneContextAndDetachFromParent());
} else {
RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), true);
params.getRngDevice().setDeviceId(rngDevs.get(0).getDeviceId());
rngCommandResult = runInternalAction(ActionType.UpdateRngDevice, params, cloneContextAndDetachFromParent());
}
}
if (rngCommandResult != null && !rngCommandResult.getSucceeded()) {
log.error("Updating RNG device of VM {} ({}) failed. Old RNG device = {}. New RNG device = {}.", getVm().getName(), getVm().getId(), rngDevs.isEmpty() ? null : rngDevs.get(0), getParameters().getRngDevice());
}
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class UpdateVmPoolCommand method isUpdateVmRequired.
private boolean isUpdateVmRequired(List<VM> vmsInPool) {
if (vmsInPool == null || vmsInPool.isEmpty()) {
return false;
}
// Check one VM in order to decide if template version was changed
VM poolVm = vmsInPool.get(0);
// old template version (based on current vm data)
Guid currentTemplateVersion = null;
// old latest status
boolean isCurrentLatest = false;
if (poolVm.isNextRunConfigurationExists()) {
QueryReturnValue qRetNextRun = backend.runInternalQuery(QueryType.GetVmNextRunConfiguration, new IdQueryParameters(poolVm.getId()));
if (qRetNextRun.getSucceeded()) {
final VM nextRunVm = qRetNextRun.getReturnValue();
if (nextRunVm != null) {
// template version was changed, the cause still needs to be checked
currentTemplateVersion = nextRunVm.getVmtGuid();
isCurrentLatest = nextRunVm.isUseLatestVersion();
}
}
} else {
currentTemplateVersion = poolVm.getVmtGuid();
isCurrentLatest = poolVm.isUseLatestVersion();
}
boolean isLatestPropertyChanged = isCurrentLatest != getParameters().getVmStaticData().isUseLatestVersion();
// template ID changed but latest is not set, as it would cause false-positives
boolean isTemplateIdChanged = false;
Guid newPoolTemplateVersion = getParameters().getVmStaticData().getVmtGuid();
if (newPoolTemplateVersion != null) {
isTemplateIdChanged = !newPoolTemplateVersion.equals(currentTemplateVersion) && !isCurrentLatest;
}
return isLatestPropertyChanged || isTemplateIdChanged;
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class StorageDomainValidator method isRunningVmsOrVmLeasesForBackupDomain.
public ValidationResult isRunningVmsOrVmLeasesForBackupDomain(VmHandler vmHandler) {
Set<String> invalidVmsForBackupStorageDomain = new HashSet<>();
QueryReturnValue ret = getEntitiesWithLeaseIdForStorageDomain(storageDomain.getId());
if (!ret.getSucceeded()) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_RETRIEVE_VMS_FOR_WITH_LEASES);
}
getRetVal(ret).forEach(vmBase -> {
VmDynamic vm = getVmDynamicDao().get(vmBase.getId());
if (vm != null && vm.getStatus() != VMStatus.Down) {
invalidVmsForBackupStorageDomain.add(vmBase.getName());
}
});
List<VM> vms = getVmDao().getAllActiveForStorageDomain(storageDomain.getId());
vms.forEach(vmHandler::updateDisksFromDb);
invalidVmsForBackupStorageDomain.addAll(vms.stream().filter(vm -> vm.getDiskMap().values().stream().filter(DisksFilter.ONLY_IMAGES).filter(DisksFilter.ONLY_PLUGGED).map(DiskImage.class::cast).anyMatch(vmDisk -> vmDisk.getStorageIds().get(0).equals(storageDomain.getId()))).map(VM::getName).collect(Collectors.toList()));
if (!invalidVmsForBackupStorageDomain.isEmpty()) {
log.warn("Can't update the backup property of the storage domain since it contains VMs with " + "leases or active disks which are attached to running VMs." + "The following VMs list are: '{}'", invalidVmsForBackupStorageDomain);
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN);
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue 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