use of org.ovirt.engine.core.common.queries.IdQueryParameters 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.IdQueryParameters 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.IdQueryParameters in project ovirt-engine by oVirt.
the class UpdateVmVersionCommand method buildAddVmParameters.
private AddVmParameters buildAddVmParameters() {
AddVmParameters addVmParams = new AddVmParameters(getParameters().getVmStaticData());
addVmParams.setPoolId(getParameters().getVmPoolId());
addVmParams.setDiskInfoDestinationMap(buildDiskInfoDestinationMap());
addVmParams.setConsoleEnabled(deviceExists(VmDeviceGeneralType.CONSOLE));
addVmParams.setBalloonEnabled(deviceExists(VmDeviceGeneralType.BALLOON, VmDeviceType.MEMBALLOON));
addVmParams.setSoundDeviceEnabled(deviceExists(VmDeviceGeneralType.SOUND));
addVmParams.setVirtioScsiEnabled(deviceExists(VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSCSI));
List<VmWatchdog> watchdogs = runInternalQuery(QueryType.GetWatchdog, new IdQueryParameters(getVmTemplateId())).getReturnValue();
if (!watchdogs.isEmpty()) {
addVmParams.setWatchdog(watchdogs.get(0));
}
loadVmPayload(addVmParams);
// then there is no session, so using the current user.
if (StringUtils.isEmpty(getParameters().getSessionId())) {
addVmParams.setParametersCurrentUser(getCurrentUser());
} else {
addVmParams.setSessionId(getParameters().getSessionId());
}
addVmParams.setDiskOperatorAuthzPrincipalDbId(getParameters().getPreviousDiskOperatorAuthzPrincipalDbId());
// reset vm to not initialized
addVmParams.getVmStaticData().setInitialized(false);
return addVmParams;
}
use of org.ovirt.engine.core.common.queries.IdQueryParameters in project ovirt-engine by oVirt.
the class GetAllDiskSnapshotsByStorageDomainIdQueryTest method testNoActiveImagesReturned.
@Test
public void testNoActiveImagesReturned() {
IdQueryParameters params = getQueryParameters();
when(params.getId()).thenReturn(storageDoaminId);
GetAllDiskSnapshotsByStorageDomainIdQuery<IdQueryParameters> query = getQuery();
query.executeQueryCommand();
List<DiskImage> diskImages = query.getQueryReturnValue().getReturnValue();
// Assert the no active images are returned
assertTrue("Active images shouldn't be returned", diskImages.stream().noneMatch(DiskImage::getActive));
}
use of org.ovirt.engine.core.common.queries.IdQueryParameters in project ovirt-engine by oVirt.
the class BackendClusterFeatureHelper method getEnabledFeature.
public static SupportedAdditionalClusterFeature getEnabledFeature(BackendResource resource, Guid clusterId, Guid id) {
Set<SupportedAdditionalClusterFeature> addlFeatures = resource.getOptionalEntity(Set.class, QueryType.GetClusterFeaturesByClusterId, new IdQueryParameters(clusterId), clusterId.toString(), false);
SupportedAdditionalClusterFeature feature = Optional.ofNullable(addlFeatures).orElse(Collections.emptySet()).stream().filter(f -> f.getFeature().getId().equals(id) && f.isEnabled()).findFirst().orElse(null);
return feature;
}
Aggregations