Vitor de Lima has uploaded a new change for review.

Change subject: core: Memory Hotplug
......................................................................

core: Memory Hotplug

This change allows a running VM to have its memory size increased
without being restarted.

Change-Id: I2c4f262d232429bd50eb62929c35b47dd7f0e68b
Signed-off-by: Vitor de Lima <vdel...@redhat.com>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetAmountOfMemoryCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HotSetAmountOfMemoryParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/SetAmountOfMemoryVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
18 files changed, 265 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/81/35081/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetAmountOfMemoryCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetAmountOfMemoryCommand.java
new file mode 100644
index 0000000..8de3400
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotSetAmountOfMemoryCommand.java
@@ -0,0 +1,109 @@
+package org.ovirt.engine.core.bll;
+
+
+import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter;
+import org.ovirt.engine.core.bll.quota.QuotaVdsDependent;
+import org.ovirt.engine.core.bll.quota.QuotaVdsGroupConsumptionParameter;
+import org.ovirt.engine.core.bll.validator.LocalizedVmStatus;
+import org.ovirt.engine.core.common.FeatureSupported;
+import org.ovirt.engine.core.common.action.HotSetAmountOfMemoryParameters;
+import org.ovirt.engine.core.common.action.PlugAction;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.errors.VdcFault;
+import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
+import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
+import org.ovirt.engine.core.vdsbroker.SetAmountOfMemoryVDSCommand;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@NonTransactiveCommandAttribute
+public class HotSetAmountOfMemoryCommand<T extends 
HotSetAmountOfMemoryParameters> extends VmManagementCommandBase<T> implements 
QuotaVdsDependent {
+
+    public HotSetAmountOfMemoryCommand(T parameters) {
+        this(parameters, null);
+    }
+
+    public HotSetAmountOfMemoryCommand(T parameters, CommandContext 
commandContext) {
+        super(parameters, commandContext);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        boolean canDo = true;
+
+        if (getVm() == null) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND);
+        }
+
+        if (getVm().getStatus() != VMStatus.Up) {
+            canDo = 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_STATUS_ILLEGAL,
+                    LocalizedVmStatus.from(getVm().getStatus()));
+        }
+
+        // FIXME:
+        // - maxmem
+        // - # slots
+
+        if (getParameters().getPlugAction() == PlugAction.PLUG) {
+            if 
(!FeatureSupported.hotPlugMemory(getVm().getVdsGroupCompatibilityVersion(), 
getVm().getClusterArch())) {
+                canDo = 
failCanDoAction(VdcBllMessages.HOT_PLUG_MEMORY_IS_NOT_SUPPORTED);
+            }
+        } else if 
(!FeatureSupported.hotUnplugMemory(getVm().getVdsGroupCompatibilityVersion(), 
getVm().getClusterArch())) {
+            canDo = 
failCanDoAction(VdcBllMessages.HOT_UNPLUG_MEMORY_IS_NOT_SUPPORTED);
+        }
+
+        return canDo;
+    }
+
+    @Override
+    protected void executeCommand() {
+        VDSReturnValue vdsReturnValue = 
runVdsCommand(VDSCommandType.SetAmountOfMemory,
+                new SetAmountOfMemoryVDSCommand.Params(
+                        getVm().getRunOnVds(),
+                        getVm().getId(),
+                        getParameters().getVm().getMemSizeMb()));
+
+        if (vdsReturnValue.getSucceeded()) {
+            setSucceeded(true);
+        } else {
+            VdcFault fault = new VdcFault();
+            fault.setError(vdsReturnValue.getVdsError().getCode());
+            fault.setMessage(vdsReturnValue.getVdsError().getMessage());
+            getReturnValue().setFault(fault);
+        }
+    }
+
+    @Override
+    public List<QuotaConsumptionParameter> getQuotaVdsConsumptionParameters() {
+        List<QuotaConsumptionParameter> list = new ArrayList<>();
+
+        // Calculate the change in memory consumption, result above Zero means 
we add memory to
+        // the VM
+        // result bellow Zero means we subtracted memory from the VM
+        int memoryToConsume =
+                getParameters().getVm().getMemSizeMb() - 
getVm().getMemSizeMb();
+
+        if (memoryToConsume > 0) {
+            // Consume CPU quota
+            list.add(new 
QuotaVdsGroupConsumptionParameter(getVm().getQuotaId(),
+                    null,
+                    QuotaConsumptionParameter.QuotaAction.CONSUME,
+                    getVm().getVdsGroupId(),
+                    0,
+                    memoryToConsume));
+
+        } else if (memoryToConsume < 0) {
+            // Release CPU quota
+            list.add(new 
QuotaVdsGroupConsumptionParameter(getVm().getQuotaId(),
+                    null,
+                    QuotaConsumptionParameter.QuotaAction.RELEASE,
+                    getVm().getVdsGroupId(),
+                    0,
+                    memoryToConsume));
+        }
+        return list;
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
index 5551952..2f8c2f5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
@@ -28,6 +28,7 @@
 import org.ovirt.engine.core.common.FeatureSupported;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.HotSetNumerOfCpusParameters;
+import org.ovirt.engine.core.common.action.HotSetAmountOfMemoryParameters;
 import org.ovirt.engine.core.common.action.LockProperties;
 import org.ovirt.engine.core.common.action.LockProperties.Scope;
 import org.ovirt.engine.core.common.action.PlugAction;
@@ -83,6 +84,7 @@
     private boolean quotaSanityOnly = false;
     private VmStatic newVmStatic;
     private VdcReturnValueBase setNumberOfCpusResult;
+    private VdcReturnValueBase setAmountOfMemoryResult;
 
     public UpdateVmCommand(T parameters) {
         this(parameters, null);
@@ -136,6 +138,7 @@
         // save user selected value for hotplug before overriding with db 
values (when updating running vm)
         int cpuPerSocket = newVmStatic.getCpuPerSocket();
         int numOfSockets = newVmStatic.getNumOfSockets();
+        int memSizeMb = newVmStatic.getMemSizeMb();
 
         if (newVmStatic.getCreationDate().equals(DateTime.getMinValue())) {
             newVmStatic.setCreationDate(new Date());
@@ -153,6 +156,7 @@
         updateVmNumaNodes();
         if (isHotSetEnabled()) {
             hotSetCpus(cpuPerSocket, numOfSockets);
+            hotSetMemory(memSizeMb);
         }
         getVmStaticDAO().update(newVmStatic);
         if (getVm().isNotRunning()) {
@@ -248,6 +252,24 @@
         }
     }
 
+    private void hotSetMemory(int newAmountOfMemory) {
+        int currentMemory = getVm().getMemSizeMb();
+
+        if (getVm().getStatus() == VMStatus.Up) {
+            HotSetAmountOfMemoryParameters params =
+                    new HotSetAmountOfMemoryParameters(
+                            newVmStatic,
+                            currentMemory < newAmountOfMemory ? 
PlugAction.PLUG : PlugAction.UNPLUG);
+            setAmountOfMemoryResult =
+                    runInternalAction(
+                            VdcActionType.HotSetAmountOfMemory,
+                            params, cloneContextAndDetachFromParent());
+            newVmStatic.setNumOfSockets(setAmountOfMemoryResult.getSucceeded() 
? newAmountOfMemory : currentMemory);
+            // FIXME
+            // auditLogHotSetMemoryCandos(params);
+        }
+    }
+
     private void auditLogHotSetCpusCandos(HotSetNumerOfCpusParameters params) {
         if (!setNumberOfCpusResult.getCanDoAction()) {
             AuditLogableBase logable = new HotSetNumberOfCpusCommand<>(params);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java
index 619790e..7bb77b1 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/FeatureSupported.java
@@ -248,6 +248,14 @@
         return supportedInConfig(ConfigValues.HotUnplugCpuSupported, version, 
arch);
     }
 
+    public static boolean hotPlugMemory(Version version, ArchitectureType 
arch) {
+        return supportedInConfig(ConfigValues.HotPlugMemorySupported, version, 
arch);
+    }
+
+    public static boolean hotUnplugMemory(Version version, ArchitectureType 
arch) {
+        return supportedInConfig(ConfigValues.HotUnplugMemorySupported, 
version, arch);
+    }
+
     /**
      * @param version
      *            Compatibility version to check for.
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HotSetAmountOfMemoryParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HotSetAmountOfMemoryParameters.java
new file mode 100644
index 0000000..6b7c46b
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/HotSetAmountOfMemoryParameters.java
@@ -0,0 +1,21 @@
+package org.ovirt.engine.core.common.action;
+
+import org.ovirt.engine.core.common.businessentities.VmStatic;
+
+public class HotSetAmountOfMemoryParameters extends VmManagementParametersBase 
 {
+
+    private PlugAction plugAction;
+
+    public HotSetAmountOfMemoryParameters() {
+    }
+
+    public HotSetAmountOfMemoryParameters(VmStatic vmStatic, PlugAction 
plugAction) {
+        super(vmStatic);
+        this.plugAction = plugAction;
+    }
+
+    public PlugAction getPlugAction() {
+        return plugAction;
+    }
+
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
index e99a0ee..a7cf8ac 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
@@ -43,6 +43,7 @@
     HotUnPlugDiskFromVm(183, ActionGroup.CONFIGURE_VM_STORAGE, false, 
QuotaDependency.NONE),
     HotSetNumberOfCpus(184, ActionGroup.EDIT_VM_PROPERTIES, false, 
QuotaDependency.VDS_GROUP, true),
     VmSlaPolicy(185, ActionGroup.EDIT_VM_PROPERTIES, false, 
QuotaDependency.NONE),
+    HotSetAmountOfMemory(186, ActionGroup.EDIT_VM_PROPERTIES, false, 
QuotaDependency.VDS_GROUP, true),
     ChangeFloppy(35, QuotaDependency.NONE),
     ImportVm(36, ActionGroup.IMPORT_EXPORT_VM, QuotaDependency.STORAGE),
     RemoveVmFromImportExport(37, ActionGroup.DELETE_VM, QuotaDependency.NONE),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
index ecdf995..f96fe8b 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
@@ -68,7 +68,7 @@
     private String comment;
 
     @CopyOnNewVersion
-    @EditableOnVmStatusField
+    @EditableOnVmStatusField(isHotsetAllowed = true)
     @EditableOnTemplate
     private int memSizeMb;
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index bd59128..623ccef 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -309,6 +309,10 @@
     @TypeConverterAttribute(Integer.class)
     @DefaultValueAttribute("16")
     MaxNumOfCpuPerSocket,
+    @Reloadable
+    @TypeConverterAttribute(Integer.class)
+    @DefaultValueAttribute("131072")
+    MaxAmountOfMemory,
     @TypeConverterAttribute(Integer.class)
     @DefaultValueAttribute("1")
     NumberVmRefreshesBeforeSave,
@@ -1712,6 +1716,15 @@
     @DefaultValueAttribute("{\"x86_64\":\"false\",\"ppc64\":\"false\"}")
     HotUnplugCpuSupported,
 
+    @TypeConverterAttribute(Map.class)
+    @DefaultValueAttribute("{\"x86_64\":\"true\",\"ppc64\":\"false\"}")
+    HotPlugMemorySupported,
+
+    @TypeConverterAttribute(Map.class)
+    @DefaultValueAttribute("{\"x86_64\":\"false\",\"ppc64\":\"false\"}")
+    HotUnplugMemorySupported,
+
+
     @TypeConverterAttribute(String.class)
     @DefaultValueAttribute("")
     ChangePasswordMsg,
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 3e584fa..4c95868 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -783,6 +783,8 @@
     HOT_PLUG_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     HOT_PLUG_CPU_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     HOT_UNPLUG_CPU_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
+    HOT_PLUG_MEMORY_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
+    HOT_UNPLUG_MEMORY_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     UNLINKING_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     HOT_PLUG_DISK_SNAPSHOT_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     NULL_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java
index 17b7c79..c99b049 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java
@@ -162,6 +162,7 @@
     StopGlusterVolumeGeoRepSession("org.ovirt.engine.core.vdsbroker.gluster"),
     
DeleteGlusterVolumeGeoRepSession("org.ovirt.engine.core.vdsbroker.gluster"),
     SetNumberOfCpus("org.ovirt.engine.core.vdsbroker"),
+    SetAmountOfMemory("org.ovirt.engine.core.vdsbroker"),
     UpdateVmPolicy("org.ovirt.engine.core.vdsbroker"),
     List("org.ovirt.engine.core.vdsbroker.vdsbroker"),           // get a list 
of VMs with status only
     GetVmStats("org.ovirt.engine.core.vdsbroker.vdsbroker"),     // get a VM 
with full data and statistics
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index b4b1970..1c35628 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -965,6 +965,8 @@
 HOT_PLUG_IS_NOT_SUPPORTED=Activate/Deactivate while VM is running, is only 
supported for Clusters of version 3.1 and above.
 HOT_PLUG_CPU_IS_NOT_SUPPORTED=Hot plugging a CPU is not supported for cluster 
version ${clusterVersion} and architecture ${architecture}.
 HOT_UNPLUG_CPU_IS_NOT_SUPPORTED=Hot un-plugging a CPU is not supported for 
cluster version ${clusterVersion} and architecture ${architecture}.
+HOT_PLUG_MEMORY_IS_NOT_SUPPORTED=Hot plugging memory is not supported for 
cluster version ${clusterVersion} and architecture ${architecture}.
+HOT_UNPLUG_MEMORY_IS_NOT_SUPPORTED=Hot un-plugging memory is not supported for 
cluster version ${clusterVersion} and architecture ${architecture}.
 HOT_PLUG_DISK_SNAPSHOT_IS_NOT_SUPPORTED=Cannot ${action} ${type}. 
Activation/Deactivation of Disk Snapshot is not supported for clusters of 
version ${clusterVersion}.
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/SetAmountOfMemoryVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/SetAmountOfMemoryVDSCommand.java
new file mode 100644
index 0000000..79f5017
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/SetAmountOfMemoryVDSCommand.java
@@ -0,0 +1,44 @@
+package org.ovirt.engine.core.vdsbroker;
+
+import org.ovirt.engine.core.common.vdscommands.VdsAndVmIDVDSParametersBase;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsBrokerCommand;
+
+public class SetAmountOfMemoryVDSCommand <P extends 
SetAmountOfMemoryVDSCommand.Params> extends VdsBrokerCommand<P> {
+    public SetAmountOfMemoryVDSCommand(P parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected void executeVdsBrokerCommand() {
+        try {
+            status = getBroker().setAmountOfMemory(
+                    getParameters().getVmId().toString(),
+                    String.valueOf(getParameters().getAmountOfMemory()));
+            proceedProxyReturnValue();
+        } catch (RuntimeException e) {
+            setVdsRuntimeError(e);
+            // prevent exception handler from rethrowing an exception
+            getVDSReturnValue().setExceptionString(null);
+        }
+    }
+
+    public static class Params extends VdsAndVmIDVDSParametersBase {
+
+        private int amountOfMemory;
+
+        public Params(Guid vdsId, Guid vmId, int amountOfMemory) {
+            super(vdsId, vmId);
+            this.amountOfMemory = amountOfMemory;
+        }
+
+        public int getAmountOfMemory() {
+            return amountOfMemory;
+        }
+
+        @Override
+        public String toString() {
+            return String.format("%s, amountOfMemory=%s", super.toString(), 
getAmountOfMemory());
+        }
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java
index ba78c94..eebcc37 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/jsonrpc/JsonRpcVdsServer.java
@@ -1523,6 +1523,17 @@
         return new StatusOnlyReturnForXmlRpc(response);
     }
 
+    @Override
+    public StatusOnlyReturnForXmlRpc setAmountOfMemory(String vmId, String 
amountOfMemory) {
+        JsonRpcRequest request =
+                new 
RequestBuilder("VM.setAmountOfMemory").withParameter("vmID", vmId)
+                        .withParameter("amountOfMemory", amountOfMemory)
+                        .build();
+        Map<String, Object> response =
+                new FutureMap(this.client, request);
+        return new StatusOnlyReturnForXmlRpc(response);
+    }
+
     @SuppressWarnings("rawtypes")
     @Override
     public StatusOnlyReturnForXmlRpc updateVmPolicy(Map params) {
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java
index a2eb0fa..3b41d9d 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/IVdsServer.java
@@ -326,5 +326,7 @@
 
     StatusOnlyReturnForXmlRpc setNumberOfCpus(String vmId, String 
numberOfCpus);
 
+    StatusOnlyReturnForXmlRpc setAmountOfMemory(String vmId, String 
amountOfMemory);
+
     StatusOnlyReturnForXmlRpc updateVmPolicy(Map info);
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
index ee82ddf..9ffd3cb 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
@@ -177,6 +177,7 @@
     public static final String memFree = "memFree";
     public static final String mem_shared = "memShared";
     public static final String mem_usage = "memUsed";
+
     // swap
     public static final String swap_free = "swapFree";
     public static final String swap_total = "swapTotal";
@@ -218,6 +219,7 @@
     // vm configuration (i.e. VmStatic)
     public static final String mem_size_mb = "memSize";
     public static final String mem_guaranteed_size_mb = "memGuaranteedSize";
+    public static final String mem_maximum_mb = "memMaximum";
     public static final String num_of_monitors = "spiceMonitors";
     public static final String num_of_cpus = "smp";
     public static final String cores_per_socket = "smpCoresPerSocket";
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java
index cf0b19c..4b6a553 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerConnector.java
@@ -305,5 +305,7 @@
 
     public Map<String, Object> setNumberOfCpus(String vmId, String 
numberOfCpus);
 
+    public Map<String, Object> setAmountOfMemory(String vmId, String 
amountOfMemory);
+
     public Map<String, Object> updateVmPolicy(Map info);
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java
index 828e3e1..d7c8e16 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsServerWrapper.java
@@ -1458,6 +1458,15 @@
     }
 
     @Override
+    public StatusOnlyReturnForXmlRpc setAmountOfMemory(String vmId, String 
amountOfMemory) {
+        try {
+            return new 
StatusOnlyReturnForXmlRpc(vdsServer.setAmountOfMemory(vmId, amountOfMemory));
+        } catch (UndeclaredThrowableException ute) {
+            throw new XmlRpcRunTimeException(ute);
+        }
+    }
+
+    @Override
     public StatusOnlyReturnForXmlRpc updateVmPolicy(Map info) {
         try {
             return new 
StatusOnlyReturnForXmlRpc(vdsServer.updateVmPolicy(info));
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
index 01f4381..21ca203 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
@@ -68,6 +68,15 @@
         createInfo.put(VdsProperties.vm_name, vm.getName());
         createInfo.put(VdsProperties.mem_size_mb, vm.getVmMemSizeMb());
         createInfo.put(VdsProperties.mem_guaranteed_size_mb, 
vm.getMinAllocatedMem());
+
+        if (FeatureSupported.supportedInConfig(
+                ConfigValues.HotPlugMemorySupported,
+                vm.getVdsGroupCompatibilityVersion(),
+                vm.getClusterArch())) {
+            createInfo.put(VdsProperties.mem_maximum_mb, 
Config.<Integer>getValue(ConfigValues.MaxAmountOfMemory,
+                    vm.getVdsGroupCompatibilityVersion().getValue()));
+        }
+
         createInfo.put(VdsProperties.smartcardEnabled, 
Boolean.toString(vm.isSmartcardEnabled()));
         createInfo.put(VdsProperties.num_of_cpus, 
String.valueOf(vm.getNumOfCpus()));
         if (Config.<Boolean> getValue(ConfigValues.SendSMPOnRunVm)) {
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 70cc80f..4bac86d 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -2603,6 +2603,12 @@
     @DefaultStringValue("Hot un-plugging a CPU is not supported for cluster 
version ${clusterVersion} and architecture ${architecture}.")
     String HOT_UNPLUG_CPU_IS_NOT_SUPPORTED();
 
+    @DefaultStringValue("Hot plugging memory is not supported for cluster 
version ${clusterVersion} and architecture ${architecture}.")
+    String HOT_PLUG_MEMORY_IS_NOT_SUPPORTED();
+
+    @DefaultStringValue("Hot un-plugging memory is not supported for cluster 
version ${clusterVersion} and architecture ${architecture}.")
+    String HOT_UNPLUG_MEMORY_IS_NOT_SUPPORTED();
+
     @DefaultStringValue("Cannot ${action} ${type}. Activation/Deactivation of 
Disk Snapshot is not supported for clusters of version ${clusterVersion}.")
     String HOT_PLUG_DISK_SNAPSHOT_IS_NOT_SUPPORTED();
 


-- 
To view, visit http://gerrit.ovirt.org/35081
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c4f262d232429bd50eb62929c35b47dd7f0e68b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Vitor de Lima <vdel...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to