use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class ImportVmsModel method loadVMsFromExternalProvider.
private void loadVMsFromExternalProvider(final OriginType type, String uri, String username, String password, Guid proxyId) {
startProgress();
AsyncQuery query = new AsyncQuery(returnValue -> {
if (returnValue instanceof QueryReturnValue) {
setError(messages.providerFailure());
stopProgress();
} else {
List<VM> remoteVms = (List<VM>) returnValue;
List<VM> remoteDownVms = new ArrayList<>();
for (VM vm : remoteVms) {
if (vm.isDown()) {
remoteDownVms.add(vm);
}
}
if (remoteVms.size() != remoteDownVms.size()) {
setWarning(constants.runningVmsWereFilteredOnImportVm());
}
updateVms(remoteDownVms);
}
});
query.setHandleFailure(true);
AsyncDataProvider.getInstance().getVmsFromExternalServer(query, getDataCenters().getSelectedItem().getId(), proxyId, uri, username, password, type, null);
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class VmDevicesListModel method syncSearch.
@Override
protected void syncSearch() {
if (getEntity() != null) {
final E vm = getEntity();
final AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<QueryReturnValue>(new AsyncCallback<QueryReturnValue>() {
@Override
public void onSuccess(QueryReturnValue returnValue) {
final Collection<VmDevice> vmDevices = returnValue.getReturnValue();
final ArrayList<VmDeviceFeEntity> frontendDevices = new ArrayList<>();
for (VmDevice vmDevice : vmDevices) {
// exclude USB controller devices with model property set to 'none'
if (vmDevice.getDevice().equals(VmDeviceType.USB.getName()) && vmDevice.getType() == VmDeviceGeneralType.CONTROLLER && (vmDevice.getSpecParams().get(MODEL)) != null && vmDevice.getSpecParams().get(MODEL).equals(UsbControllerModel.NONE.libvirtName)) {
continue;
}
frontendDevices.add(new VmDeviceFeEntity(vmDevice, vm, idsOfDevicesBeingUnplugged.contains(vmDevice.getId())));
}
setItems(frontendDevices);
}
}) {
};
super.syncSearch(QueryType.GetVmDevicesForVm, new IdQueryParameters(vm.getId()), asyncQuery);
}
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class VmGeneralModel method updateProperties.
private void updateProperties() {
VM vm = getEntity();
super.updateProperties(vm.getId());
setName(vm.getName());
setDescription(vm.getVmDescription());
// $NON-NLS-1$
setQuotaName(vm.getQuotaName() != null ? vm.getQuotaName() : "");
setQuotaAvailable(vm.getQuotaEnforcementType() != null && !vm.getQuotaEnforcementType().equals(QuotaEnforcementTypeEnum.DISABLED));
setTemplate(vmTemplateNameRenderer.render(vm));
// $NON-NLS-1$
setDefinedMemory(vm.getVmMemSizeMb() + " MB");
// $NON-NLS-1$
setMinAllocatedMemory(vm.getMinAllocatedMem() + " MB");
if (vm.isRunningOrPaused() && vm.getGuestMemoryBuffered() != null && vm.getGuestMemoryCached() != null && vm.getGuestMemoryFree() != null) {
setGuestFreeCachedBufferedMemInfo(// $NON-NLS-1$
(vm.getGuestMemoryFree() / 1024L) + " / " + (vm.getGuestMemoryBuffered() / 1024L) + // $NON-NLS-1$
" / " + (vm.getGuestMemoryCached() / 1024L) + // $NON-NLS-1$
" MB");
} else {
// Handled in form
setGuestFreeCachedBufferedMemInfo(null);
}
setOS(AsyncDataProvider.getInstance().getOsName(vm.getVmOsId()));
EnumTranslator translator = EnumTranslator.getInstance();
setDefaultDisplayType(translator.translate(vm.getDefaultDisplayType()));
setOrigin(translator.translate(vm.getOrigin()));
setIsHighlyAvailable(vm.isAutoStartup());
setPriority(AsyncDataProvider.getInstance().priorityToString(vm.getPriority()));
setOptimizedForSystemProfile(translator.translate(vm.getVmType()));
setMonitorCount(vm.getNumOfMonitors());
setUsbPolicy(translator.translate(vm.getUsbPolicy()));
setCpuInfo(ConstantsManager.getInstance().getMessages().cpuInfoLabel(vm.getNumOfCpus(), vm.getNumOfSockets(), vm.getCpuPerSocket(), vm.getThreadsPerCpu()));
setGuestCpuCount(vm.getGuestCpuCount());
setHasDomain(AsyncDataProvider.getInstance().isWindowsOsType(vm.getVmOsId()));
if (vm.getVmInit() != null) {
setDomain(vm.getVmInit().getDomain());
}
setHasTimeZone(!StringHelper.isNullOrEmpty(vm.getTimeZone()));
setTimeZone(vm.getTimeZone());
setHasCustomProperties(!StringHelper.isNullOrEmpty(vm.getCustomProperties()));
setCustomProperties(getHasCustomProperties() ? constants.configured() : constants.notConfigured());
setCompatibilityVersion(vm.getCompatibilityVersion() != null ? vm.getCompatibilityVersion().toString() : // $NON-NLS-1$
"");
setVmId(vm.getId().toString());
setFqdn(vm.getFqdn());
setHasAlert(vm.getVmPauseStatus() != VmPauseStatus.NONE && vm.getVmPauseStatus() != VmPauseStatus.NOERR);
if (getHasAlert()) {
setAlert(translator.translate(vm.getVmPauseStatus()));
} else {
setAlert(null);
}
setHasCreatedByUser(vm.getCreatedByUserId() != null);
if (getHasCreatedByUser()) {
Frontend.getInstance().runQuery(QueryType.GetDbUserByUserId, new IdQueryParameters(vm.getCreatedByUserId()), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {
@Override
public void onSuccess(QueryReturnValue result) {
DbUser dbUser = result.getReturnValue();
if (dbUser != null) {
setCreatedByUser(getUserName(dbUser));
}
}
private String getUserName(DbUser dbUser) {
if (StringHelper.isNotNullOrEmpty(dbUser.getFirstName()) || StringHelper.isNotNullOrEmpty(dbUser.getLastName())) {
return messages.userName(nullToEmpty(dbUser.getFirstName()), nullToEmpty(dbUser.getLastName()));
}
return dbUser.getLoginName();
}
private String nullToEmpty(String val) {
return val == null ? "" : val;
}
}));
}
setHasDefaultHost(vm.getDedicatedVmForVdsList().size() > 0);
if (getHasDefaultHost()) {
Frontend.getInstance().runQuery(QueryType.Search, new SearchParameters(// $NON-NLS-1$
"Host: cluster = " + vm.getClusterName() + " sortby name", SearchType.VDS).withoutRefresh(), new AsyncQuery<QueryReturnValue>(returnValue -> {
// $NON-NLS-1$
VM localVm = getEntity();
if (localVm == null) {
return;
}
ArrayList<VDS> hosts = returnValue.getReturnValue();
if (localVm.getDedicatedVmForVdsList().size() > 0) {
String defaultHost = "";
for (VDS host : hosts) {
if (localVm.getDedicatedVmForVdsList().contains(host.getId())) {
if (defaultHost.isEmpty()) {
defaultHost = host.getName();
} else {
// $NON-NLS-1$
defaultHost += ", " + host.getName();
}
}
}
setDefaultHost(defaultHost);
}
}));
} else {
setDefaultHost(ConstantsManager.getInstance().getConstants().anyHostInCluster());
}
final String guestCpuType = vm.getCpuName() != null ? vm.getCpuName() : (vm.getCustomCpuName() != null ? vm.getCustomCpuName() : vm.getClusterCpuName());
setGuestCpuType(guestCpuType);
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class TemplateVmModelBehavior method initialize.
@Override
public void initialize() {
super.initialize();
getModel().getTemplateWithVersion().setIsChangeable(false);
getModel().getBaseTemplate().setIsChangeable(false);
getModel().getTemplateWithVersion().setIsChangeable(false);
getModel().getProvisioning().setIsChangeable(false);
getModel().getStorageDomain().setIsChangeable(false);
getModel().getIsSoundcardEnabled().setIsChangeable(true);
getModel().getVmType().setIsChangeable(true);
getModel().getTemplateVersionName().setIsChangeable(!template.isBaseTemplate());
getModel().getName().setIsChangeable(template.isBaseTemplate());
if (template.getStoragePoolId() != null && !template.getStoragePoolId().equals(Guid.Empty)) {
AsyncDataProvider.getInstance().getDataCenterById(new AsyncQuery<>(dataCenter -> AsyncDataProvider.getInstance().getClusterListByService(new AsyncQuery<>(clusters -> {
ArrayList<Cluster> clustersSupportingVirt = new ArrayList<>();
// filter clusters supporting virt service only
for (Cluster cluster : clusters) {
if (cluster.supportsVirtService()) {
clustersSupportingVirt.add(cluster);
}
}
List<Cluster> filteredClusters = AsyncDataProvider.getInstance().filterByArchitecture(clustersSupportingVirt, template.getClusterArch());
getModel().setDataCentersAndClusters(getModel(), new ArrayList<>(Arrays.asList(new StoragePool[] { dataCenter })), filteredClusters, template.getClusterId());
updateRngDevice(template.getId());
AsyncDataProvider.getInstance().isSoundcardEnabled(new AsyncQuery<>(returnValue -> {
getModel().getIsSoundcardEnabled().setEntity(returnValue);
initTemplate();
initCdImage();
}), template.getId());
Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(template.getId()), new AsyncQuery<>((QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
AsyncDataProvider.getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), template.getId());
}), true, false)), template.getStoragePoolId());
}
AsyncDataProvider.getInstance().getWatchdogByVmId(new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
UnitVmModel model = getModel();
@SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
for (VmWatchdog watchdog : watchdogs) {
model.getWatchdogAction().setSelectedItem(watchdog.getAction());
model.getWatchdogModel().setSelectedItem(watchdog.getModel());
}
}), template.getId());
getModel().getMigrationMode().setSelectedItem(template.getMigrationSupport());
setupBaseTemplate(template.getBaseTemplateId());
}
use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.
the class Backend method runQueryImpl.
protected QueryReturnValue runQueryImpl(QueryType actionType, QueryParametersBase parameters, boolean isPerformUserCheck, EngineContext engineContext) {
if (isPerformUserCheck) {
String sessionId = parameters.getSessionId();
if (StringUtils.isEmpty(sessionId) || sessionDataContainer.getUser(sessionId, parameters.getRefresh()) == null) {
log.debug("Unable to execute query {} as no user session was found", actionType);
return getErrorQueryReturnValue(EngineMessage.USER_IS_NOT_LOGGED_IN);
}
logExecution(sessionId, String.format("query %s with isFiltered : %s", actionType, parameters.isFiltered()));
}
Class<?> clazz = CommandsFactory.getQueryClass(actionType.name());
if (clazz.isAnnotationPresent(DisableInMaintenanceMode.class)) {
String mode = vdcOptionDao.getByNameAndVersion(ConfigValues.EngineMode.name(), ConfigCommon.defaultConfigurationVersion).getOptionValue();
if (EngineWorkingMode.MAINTENANCE.name().equalsIgnoreCase(mode)) {
return getErrorQueryReturnValue(EngineMessage.ENGINE_IS_RUNNING_IN_MAINTENANCE_MODE);
}
}
if (parameters.getCorrelationId() == null) {
parameters.setCorrelationId(CorrelationIdTracker.getCorrelationId());
}
QueriesCommandBase<?> command = createQueryCommand(actionType, parameters, engineContext);
command.setInternalExecution(!isPerformUserCheck);
QueryReturnValue returnValue = queryExecutor.get().execute(command, actionType);
if (returnValue.getCorrelationId() == null) {
returnValue.setCorrelationId(parameters.getCorrelationId());
}
CorrelationIdTracker.setCorrelationId(parameters.getCorrelationId());
return returnValue;
}
Aggregations