use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class VmListModel method initImportModelForVmsToImportNamesOnly.
private void initImportModelForVmsToImportNamesOnly(final ImportVmsModel importVmsModel, final ImportVmModel importVmModel) {
final UIMessages messages = ConstantsManager.getInstance().getMessages();
final UIConstants constants = ConstantsManager.getInstance().getConstants();
final List<String> vmsToImport = new ArrayList<>();
OriginType originType = convertImportSourceToOriginType(importVmsModel.getImportSources().getSelectedItem());
final List<VM> externalVms = importVmsModel.getVmsToImport();
for (VM vm : externalVms) {
vmsToImport.add(vm.getName());
}
importVmsModel.clearProblem();
importVmsModel.startProgress();
importVmModel.setMessage("");
AsyncQuery query = new AsyncQuery(returnValue -> {
if (returnValue instanceof QueryReturnValue) {
importVmsModel.setError(messages.providerFailure());
importVmsModel.stopProgress();
} else {
List<VM> remoteVms = (List<VM>) returnValue;
List<VM> remoteDownVms = new ArrayList<>();
List<VM> nonRetrievedVms = new ArrayList<>();
// find vms with status=down
for (VM vm : remoteVms) {
if (vm.isDown()) {
remoteDownVms.add(vm);
}
}
// i.e. they were retrieved with their names only but not with their full info
if (remoteVms.size() != externalVms.size()) {
for (VM vm : externalVms) {
if (!remoteVms.contains(vm)) {
nonRetrievedVms.add(vm);
}
}
}
importVmsModel.stopProgress();
// prepare error message to be displayed in one of the models
String messageForImportVm = null;
String messageForImportVms = null;
if (remoteVms.size() != remoteDownVms.size()) {
if (!nonRetrievedVms.isEmpty()) {
messageForImportVm = constants.nonRetrievedAndRunningVmsWereFilteredOnImportVm();
messageForImportVms = constants.nonRetrievedAndRunningVmsWereAllFilteredOnImportVm();
} else {
messageForImportVm = constants.runningVmsWereFilteredOnImportVm();
messageForImportVms = constants.runningVmsWereAllFilteredOnImportVm();
}
} else if (!nonRetrievedVms.isEmpty()) {
messageForImportVm = constants.nonRetrievedVmsWereFilteredOnImportVm();
messageForImportVms = constants.nonRetrievedVmsWereAllFilteredOnImportVm();
}
if (remoteDownVms.isEmpty() && messageForImportVms != null) {
importVmsModel.setError(messageForImportVms);
}
if (!importVmsModel.validateArchitectures(remoteDownVms)) {
return;
}
// init and display next dialog - the importVmsModel model
importVmModel.init(remoteDownVms, importVmsModel.getDataCenters().getSelectedItem().getId());
setWindow(null);
setWindow(importVmModel);
if (messageForImportVm != null) {
importVmModel.setMessage(messageForImportVm);
}
}
});
if (!(importVmModel instanceof ImportVmFromExternalSourceModel)) {
importVmsModel.setError(messages.providerImportFailure());
importVmsModel.stopProgress();
return;
}
ImportVmFromExternalSourceModel importVmsFromExternalSource = (ImportVmFromExternalSourceModel) importVmModel;
query.setHandleFailure(true);
AsyncDataProvider.getInstance().getVmsFromExternalServer(query, importVmsModel.getDataCenters().getSelectedItem().getId(), importVmsFromExternalSource.getProxyHostId(), importVmsFromExternalSource.getUrl(), importVmsFromExternalSource.getUsername(), importVmsFromExternalSource.getPassword(), originType, vmsToImport);
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method updateGraphics.
protected void updateGraphics(Guid id) {
Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(id), new AsyncQuery<QueryReturnValue>(returnValue -> {
List<VmDevice> graphicsVmDevs = returnValue.getReturnValue();
List<GraphicsType> graphicsTypes = new ArrayList<>();
for (VmDevice graphicsVmDev : graphicsVmDevs) {
graphicsTypes.add(GraphicsType.fromString(graphicsVmDev.getDevice()));
}
boolean hasSpiceAndVnc = graphicsTypes.size() == 2 && graphicsTypes.containsAll(Arrays.asList(GraphicsType.SPICE, GraphicsType.VNC));
boolean canBeSelected = getModel().getGraphicsType().getItems().contains(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
if (hasSpiceAndVnc && canBeSelected) {
getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
} else if (graphicsVmDevs.size() == 1) {
GraphicsType type = GraphicsType.fromString(graphicsVmDevs.get(0).getDevice());
getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.fromGraphicsType(type));
}
}));
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class ExistingNonClusterModelBehavior method doBuild.
public void doBuild() {
buildModel(entity, (source, destination) -> {
Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(entity.getId()), new AsyncQuery<>((QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), entity.getId());
getInstance().getWatchdogByVmId(new AsyncQuery<QueryReturnValue>(returnValue -> {
@SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
for (VmWatchdog watchdog : watchdogs) {
getModel().getWatchdogAction().setSelectedItem(watchdog.getAction());
getModel().getWatchdogModel().setSelectedItem(watchdog.getModel());
}
}), entity.getId());
Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
List<VmDevice> rngDevices = returnValue.getReturnValue();
getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
if (!rngDevices.isEmpty()) {
VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
getModel().setRngDevice(rngDevice);
}
}));
getModel().getEmulatedMachine().setSelectedItem(entity.getCustomEmulatedMachine());
getModel().getCustomCpu().setSelectedItem(entity.getCustomCpuName());
getModel().getMigrationMode().setSelectedItem(entity.getMigrationSupport());
postBuild();
});
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class VmInstanceTypeManager method updateNetworkInterfacesByTemplate.
public void updateNetworkInterfacesByTemplate(VmBase vmBase) {
QueryType queryType = (vmBase instanceof VmTemplate) ? QueryType.GetTemplateInterfacesByTemplateId : QueryType.GetVmInterfacesByVmId;
AsyncQuery<QueryReturnValue> query = new AsyncQuery<>(returnValue -> {
if (returnValue == null) {
return;
}
List<VmNetworkInterface> nics = returnValue.getReturnValue();
updateNetworkInterfaces(getNetworkProfileBehavior(), nics);
});
Frontend.getInstance().runQuery(queryType, new IdQueryParameters(vmBase.getId()), query);
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class VncConsoleModel method invokeConsole.
private void invokeConsole() {
final GraphicsInfo vncInfo = getEntity().getGraphicsInfos().get(GraphicsType.VNC);
if (vncInfo == null) {
// $NON-NLS-1$
throw new IllegalStateException("Trying to invoke VNC console but VM GraphicsInfo is null.");
}
vncImpl.getOptions().setVmId(getEntity().getId());
ConfigureConsoleOptionsParams parameters = new ConfigureConsoleOptionsParams(vncImpl.getOptions(), true);
parameters.setEngineBaseUrl(FrontendUrlUtils.getRootURL());
parameters.setConsoleClientResourcesUrl(dynamicMessages.consoleClientResourcesUrl());
Frontend.getInstance().runQuery(QueryType.ConfigureConsoleOptions, parameters, new ShowErrorAsyncQuery(returnValue -> {
ConsoleOptions configuredOptions = ((QueryReturnValue) returnValue).getReturnValue();
// overriding global server settings by frontend settings
configuredOptions.setRemapCtrlAltDelete(vncImpl.getOptions().isRemapCtrlAltDelete());
vncImpl.setOptions(configuredOptions);
vncImpl.getOptions().setTitle(getClientTitle());
vncImpl.getOptions().setVmName(getEntity().getName());
vncImpl.invokeClient();
}));
}
Aggregations