use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method updateQuotaByCluster.
protected void updateQuotaByCluster(final Guid defaultQuota, final String quotaName) {
if (getModel().getQuota().getIsAvailable()) {
Cluster cluster = getModel().getSelectedCluster();
if (cluster == null) {
return;
}
AsyncDataProvider.getInstance().getAllRelevantQuotasForClusterSorted(new AsyncQuery<>(quotaList -> {
UnitVmModel vmModel = getModel();
if (quotaList == null) {
return;
}
if (!quotaList.isEmpty()) {
vmModel.getQuota().setItems(quotaList);
}
if (defaultQuota != null && !Guid.Empty.equals(defaultQuota)) {
boolean hasQuotaInList = false;
if (!quotaList.isEmpty()) {
hasQuotaInList = defaultQuota.equals(quotaList.get(0).getId());
}
// Add the quota to the list only in edit mode
if (!hasQuotaInList && !getModel().getIsNew()) {
Quota quota = new Quota();
quota.setId(defaultQuota);
quota.setQuotaName(quotaName);
quotaList.add(0, quota);
vmModel.getQuota().setItems(quotaList);
vmModel.getQuota().setSelectedItem(quota);
}
}
}), cluster.getId(), defaultQuota);
}
}
use of org.ovirt.engine.ui.frontend.AsyncQuery 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.ui.frontend.AsyncQuery 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.ui.frontend.AsyncQuery 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.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class AsyncDataProvider method getDefaultConfigurationVersion.
private void getDefaultConfigurationVersion(final LoginModel loginModel) {
AsyncQuery<QueryReturnValue> callback = new AsyncQuery<>(returnValue -> {
if (returnValue != null) {
_defaultConfigurationVersion = ((QueryReturnValue) returnValue).getReturnValue();
} else {
_defaultConfigurationVersion = GENERAL;
}
loginModel.getLoggedInEvent().raise(loginModel, EventArgs.EMPTY);
});
callback.setHandleFailure(true);
Frontend.getInstance().runQuery(QueryType.GetDefaultConfigurationVersion, new QueryParametersBase(), callback);
}
Aggregations