Search in sources :

Example 6 with VmWatchdog

use of org.ovirt.engine.core.common.businessentities.VmWatchdog 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());
}
Also used : DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) Arrays(java.util.Arrays) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) NameAndDescriptionVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.NameAndDescriptionVmBaseToUnitBuilder) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) CommentVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.CommentVmBaseToUnitBuilder) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) Collections(java.util.Collections) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) CommonVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.CommonVmBaseToUnitBuilder) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with VmWatchdog

use of org.ovirt.engine.core.common.businessentities.VmWatchdog 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());
            }
        }
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) WatchdogParameters(org.ovirt.engine.core.common.action.WatchdogParameters) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Example 8 with VmWatchdog

use of org.ovirt.engine.core.common.businessentities.VmWatchdog 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;
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AddVmParameters(org.ovirt.engine.core.common.action.AddVmParameters) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Example 9 with VmWatchdog

use of org.ovirt.engine.core.common.businessentities.VmWatchdog in project ovirt-engine by oVirt.

the class ProcessDownVmCommand method createUpdateVmParameters.

private VmManagementParametersBase createUpdateVmParameters() {
    // clear non updateable fields got from config
    getVm().setExportDate(null);
    getVm().setOvfVersion(null);
    VmManagementParametersBase updateVmParams = new VmManagementParametersBase(getVm());
    updateVmParams.setUpdateWatchdog(true);
    updateVmParams.setSoundDeviceEnabled(false);
    updateVmParams.setBalloonEnabled(false);
    updateVmParams.setVirtioScsiEnabled(false);
    updateVmParams.setClearPayload(true);
    updateVmParams.setUpdateRngDevice(true);
    for (GraphicsType graphicsType : GraphicsType.values()) {
        updateVmParams.getGraphicsDevices().put(graphicsType, null);
    }
    for (VmDevice device : getVm().getManagedVmDeviceMap().values()) {
        switch(device.getType()) {
            case WATCHDOG:
                updateVmParams.setWatchdog(new VmWatchdog(device));
                break;
            case SOUND:
                updateVmParams.setSoundDeviceEnabled(true);
                break;
            case BALLOON:
                updateVmParams.setBalloonEnabled(true);
                break;
            case CONTROLLER:
                if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
                    updateVmParams.setVirtioScsiEnabled(true);
                }
                break;
            case DISK:
                if (VmPayload.isPayload(device.getSpecParams())) {
                    updateVmParams.setVmPayload(new VmPayload(device));
                }
                break;
            case CONSOLE:
                updateVmParams.setConsoleEnabled(true);
                break;
            case RNG:
                updateVmParams.setRngDevice(new VmRngDevice(device));
                break;
            case GRAPHICS:
                updateVmParams.getGraphicsDevices().put(GraphicsType.fromString(device.getDevice()), new GraphicsDevice(device));
                break;
            default:
        }
    }
    // clear these fields as these are non updatable
    getVm().getManagedVmDeviceMap().clear();
    getVm().getUnmanagedDeviceList().clear();
    return updateVmParams;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 10 with VmWatchdog

use of org.ovirt.engine.core.common.businessentities.VmWatchdog in project ovirt-engine by oVirt.

the class WatchdogMapper method map.

@Mapping(from = VmWatchdog.class, to = Watchdog.class)
public static Watchdog map(VmWatchdog entity, Watchdog template) {
    Watchdog model = template == null ? new Watchdog() : template;
    if (entity.getAction() != null) {
        model.setAction(map(entity.getAction()));
    }
    if (entity.getModel() != null) {
        model.setModel(map(entity.getModel()));
    }
    model.setId(entity.getId().toString());
    return model;
}
Also used : VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) Watchdog(org.ovirt.engine.api.model.Watchdog)

Aggregations

VmWatchdog (org.ovirt.engine.core.common.businessentities.VmWatchdog)27 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)7 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)7 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)6 Guid (org.ovirt.engine.core.compat.Guid)5 Test (org.junit.Test)4 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 List (java.util.List)3 Watchdog (org.ovirt.engine.api.model.Watchdog)3 GraphicsDevice (org.ovirt.engine.core.common.businessentities.GraphicsDevice)3 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)3 VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)3 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)3 VmWatchdogType (org.ovirt.engine.core.common.businessentities.VmWatchdogType)3 QueryType (org.ovirt.engine.core.common.queries.QueryType)3 AsyncQuery (org.ovirt.engine.ui.frontend.AsyncQuery)3 Frontend (org.ovirt.engine.ui.frontend.Frontend)3 BuilderExecutor (org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor)3