Ravi Nori has uploaded a new change for review.

Change subject: engine : Remove StopVmParameters from StopVmCommand
......................................................................

engine : Remove StopVmParameters from StopVmCommand

Removes the StopVmParameters class anf uses
the map in VdcActionParametersBase  to save
and retrived StopVmTypeEnum using the key
VmVdcParameter.StopVmType

Longer description using lines' length under 72 chars.

With multiple paragraphs if necessary.

Change-Id: I404816e3e70ce044e1348af0eeea18b59e521581
Bug-Url: https://bugzilla.redhat.com/??????
Signed-off-by: Ravi Nori <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
D 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/StopVmParameters.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmVdcParameter.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/VmItemBehavior.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
8 files changed, 99 insertions(+), 41 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/20479/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
index 860becb..66f1098 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
@@ -2,13 +2,15 @@
 
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
-import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.action.VmOperationParameterBase;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.queries.InvalidParameterValueException;
+import org.ovirt.engine.core.common.utils.VmVdcParameter;
 import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
@@ -70,7 +72,7 @@
 
             log.infoFormat("Cannot shutdown VM {0}, status is not up. Stopping 
instead.", getVmName());
 
-            StopVmParameters stopVmParams = new StopVmParameters(getVmId(), 
StopVmTypeEnum.CANNOT_SHUTDOWN);
+            VmOperationParameterBase stopVmParams = 
getStopVmParameters(getVmId(), StopVmTypeEnum.CANNOT_SHUTDOWN);
             // stopVmParams.ParametersCurrentUser = CurrentUser;
             stopVmParams.setSessionId(getParameters().getSessionId());
             Backend.getInstance().runInternalAction(VdcActionType.StopVm, 
stopVmParams);
@@ -79,6 +81,16 @@
         setSucceeded(true);
     }
 
+    private VmOperationParameterBase getStopVmParameters(Guid vmId, 
StopVmTypeEnum stopVmType) {
+        VmOperationParameterBase params = new VmOperationParameterBase(vmId);
+        try {
+            params.addParameter(VmVdcParameter.StopVmType, stopVmType);
+        } catch (InvalidParameterValueException e) {
+            log.error(e);
+        }
+        return params;
+    }
+
     private boolean canShutdownVm() {
         return getVm().getStatus() == VMStatus.Up &&
                 (Boolean.TRUE.equals(getVm().getAcpiEnable()) || 
getVm().getHasAgent());
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
index 821b787..84ab4a1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
@@ -1,12 +1,14 @@
 package org.ovirt.engine.core.bll;
 
 import org.ovirt.engine.core.common.AuditLogType;
-import org.ovirt.engine.core.common.action.StopVmParameters;
+import org.ovirt.engine.core.common.action.StopVmTypeEnum;
+import org.ovirt.engine.core.common.action.VmOperationParameterBase;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.utils.VmVdcParameter;
 import org.ovirt.engine.core.compat.Guid;
 
 @NonTransactiveCommandAttribute(forceCompensation=true)
-public class StopVmCommand<T extends StopVmParameters> extends 
StopVmCommandBase<T> {
+public class StopVmCommand<T extends VmOperationParameterBase> extends 
StopVmCommandBase<T> {
     public StopVmCommand(T stopVmParams) {
         super(stopVmParams);
     }
@@ -26,7 +28,7 @@
         if (getSuspendedVm()) {
             return getSucceeded() ? AuditLogType.USER_STOP_SUSPENDED_VM : 
AuditLogType.USER_STOP_SUSPENDED_VM_FAILED;
         } else {
-            switch (getParameters().getStopVmType()) {
+            switch (getStopVmType()) {
             case NORMAL:
                 return getSucceeded() ? AuditLogType.USER_STOP_VM : 
AuditLogType.USER_FAILED_STOP_VM;
 
@@ -40,6 +42,10 @@
         }
     }
 
+    private StopVmTypeEnum getStopVmType() {
+        return (StopVmTypeEnum) 
getParameters().getParameterValue(VmVdcParameter.StopVmType);
+    }
+
     @Override
     protected void setActionMessageParameters() {
         addCanDoActionMessage(VdcBllMessages.VAR__ACTION__STOP);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/StopVmParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/StopVmParameters.java
deleted file mode 100644
index 628afee..0000000
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/StopVmParameters.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.ovirt.engine.core.common.action;
-
-import org.ovirt.engine.core.compat.Guid;
-
-public class StopVmParameters extends VmOperationParameterBase implements 
java.io.Serializable {
-    private static final long serialVersionUID = -1331508207367552128L;
-    private StopVmTypeEnum _stopVmType;
-
-    public StopVmParameters(Guid vmID, StopVmTypeEnum stopVmType) {
-        super(vmID);
-        _stopVmType = stopVmType;
-    }
-
-    public StopVmTypeEnum getStopVmType() {
-        return _stopVmType;
-    }
-
-    public void setStopVmType(StopVmTypeEnum value) {
-        _stopVmType = value;
-    }
-
-    public StopVmParameters() {
-        _stopVmType = StopVmTypeEnum.NORMAL;
-    }
-}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmVdcParameter.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmVdcParameter.java
new file mode 100644
index 0000000..5faf7f1
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmVdcParameter.java
@@ -0,0 +1,30 @@
+package org.ovirt.engine.core.common.utils;
+
+import org.ovirt.engine.core.common.action.StopVmTypeEnum;
+import org.ovirt.engine.core.compat.Guid;
+
+public enum VmVdcParameter implements IVdcParameter {
+    StopVmType(StopVmTypeEnum.class),
+    VmId(Guid.class);
+
+    private final Class javaType;
+
+    VmVdcParameter(Class javaType) {
+        this.javaType = javaType;
+    }
+
+    @Override
+    public Class getJavaType() {
+        return javaType;
+    }
+
+    @Override
+    public String getKey() {
+        return this.name();
+    }
+
+    @Override
+    public String toString() {
+        return VdcParameter.class.getName() + "." + super.toString();
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
index 3dccc3f..cc5ee02 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
@@ -42,7 +42,6 @@
 import org.ovirt.engine.core.common.action.RunVmParams;
 import org.ovirt.engine.core.common.action.SetVmTicketParameters;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
-import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -60,6 +59,8 @@
 
 
 import static 
org.ovirt.engine.api.restapi.resource.BackendVmsResource.SUB_COLLECTIONS;
+import org.ovirt.engine.core.common.queries.InvalidParameterValueException;
+import org.ovirt.engine.core.common.utils.VmVdcParameter;
 import static org.ovirt.engine.core.utils.Ticketing.GenerateOTP;
 
 public class BackendVmResource extends
@@ -247,10 +248,20 @@
     @Override
     public Response stop(Action action) {
         return doAction(VdcActionType.StopVm,
-                        new StopVmParameters(guid, StopVmTypeEnum.NORMAL),
+                        getStopVmParameters(guid, StopVmTypeEnum.NORMAL),
                         action);
     }
 
+    private VmOperationParameterBase getStopVmParameters(Guid vmId, 
StopVmTypeEnum stopVmType) {
+        VmOperationParameterBase params = new VmOperationParameterBase(vmId);
+        try {
+            params.addParameter(VmVdcParameter.StopVmType, stopVmType);
+        } catch (InvalidParameterValueException e) {
+            LOG.error(e);
+        }
+        return params;
+    }
+
     @Override
     public Response suspend(Action action) {
         return doAction(VdcActionType.HibernateVm,
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
index ebd6ffc..882fefb 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java
@@ -48,7 +48,6 @@
 import org.ovirt.engine.core.common.action.RunVmParams;
 import org.ovirt.engine.core.common.action.SetVmTicketParameters;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
-import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -67,6 +66,7 @@
 import org.ovirt.engine.core.common.queries.NameQueryParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
+import org.ovirt.engine.core.common.utils.VmVdcParameter;
 import org.ovirt.engine.core.compat.Guid;
 
 public class BackendVmResourceTest
@@ -578,10 +578,13 @@
 
     @Test
     public void testStop() throws Exception {
-        setUriInfo(setUpActionExpectations(VdcActionType.StopVm,
-                                           StopVmParameters.class,
-                                           new String[] { "VmId", "StopVmType" 
},
-                                           new Object[] { GUIDS[0], 
StopVmTypeEnum.NORMAL }));
+        setUriInfo(setUpActionExpectationsWithParamNames(VdcActionType.StopVm,
+                                           VmOperationParameterBase.class,
+                                           new String[] { "ParameterValue", 
"VmId" },
+                                           new Object[] { 
StopVmTypeEnum.NORMAL, GUIDS[0] },
+                                           new VmVdcParameter[] 
{VmVdcParameter.StopVmType},
+                                           true,
+                                           true));
 
         verifyActionResponse(resource.stop(new Action()));
     }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/VmItemBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/VmItemBehavior.java
index ba7ff25..f761ee6 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/VmItemBehavior.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/VmItemBehavior.java
@@ -6,7 +6,6 @@
 import org.ovirt.engine.core.common.action.ChangeDiskCommandParameters;
 import org.ovirt.engine.core.common.action.RunVmParams;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
-import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VmOperationParameterBase;
@@ -14,6 +13,9 @@
 import org.ovirt.engine.core.common.businessentities.VmPool;
 import org.ovirt.engine.core.common.businessentities.VmPoolType;
 import org.ovirt.engine.core.common.businessentities.VmType;
+import org.ovirt.engine.core.common.queries.InvalidParameterValueException;
+import org.ovirt.engine.core.common.utils.VmVdcParameter;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.StringHelper;
 import org.ovirt.engine.ui.frontend.AsyncQuery;
 import org.ovirt.engine.ui.frontend.Frontend;
@@ -123,7 +125,7 @@
     private void stop()
     {
         VM entity = (VM) getItem().getEntity();
-        Frontend.RunAction(VdcActionType.StopVm, new 
StopVmParameters(entity.getId(), StopVmTypeEnum.NORMAL));
+        Frontend.RunAction(VdcActionType.StopVm, 
getStopVmParameters(entity.getId(), StopVmTypeEnum.NORMAL));
     }
 
     private void pause()
@@ -139,6 +141,15 @@
         Frontend.RunAction(VdcActionType.RunVm, new 
RunVmParams(entity.getId()));
     }
 
+    private VmOperationParameterBase getStopVmParameters(Guid vmId, 
StopVmTypeEnum stopVmType) {
+        VmOperationParameterBase params = new VmOperationParameterBase(vmId);
+        try {
+            params.addParameter(VmVdcParameter.StopVmType, stopVmType);
+        } catch (InvalidParameterValueException e) {
+        }
+        return params;
+    }
+
     private void updateProperties()
     {
         VM entity = (VM) getItem().getEntity();
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
index 5e1ce6e..6faf9db 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
@@ -20,7 +20,6 @@
 import org.ovirt.engine.core.common.action.RemoveVmParameters;
 import org.ovirt.engine.core.common.action.RunVmParams;
 import org.ovirt.engine.core.common.action.ShutdownVmParameters;
-import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.action.StopVmTypeEnum;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -46,9 +45,11 @@
 import org.ovirt.engine.core.common.interfaces.SearchType;
 import org.ovirt.engine.core.common.mode.ApplicationMode;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.InvalidParameterValueException;
 import org.ovirt.engine.core.common.queries.SearchParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.common.utils.VmVdcParameter;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.StringHelper;
 import org.ovirt.engine.core.compat.Version;
@@ -1694,7 +1695,7 @@
         for (Object item : getSelectedItems())
         {
             VM a = (VM) item;
-            list.add(new StopVmParameters(a.getId(), StopVmTypeEnum.NORMAL));
+            list.add(getStopVmParameters(a.getId(), StopVmTypeEnum.NORMAL));
         }
 
         model.startProgress(null);
@@ -1712,6 +1713,15 @@
                 }, model);
     }
 
+    private VmOperationParameterBase getStopVmParameters(Guid vmId, 
StopVmTypeEnum stopVmType) {
+        VmOperationParameterBase params = new VmOperationParameterBase(vmId);
+        try {
+            params.addParameter(VmVdcParameter.StopVmType, stopVmType);
+        } catch (InvalidParameterValueException e) {
+        }
+        return params;
+    }
+
     private void pause()
     {
         ArrayList<VdcActionParametersBase> list = new 
ArrayList<VdcActionParametersBase>();


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I404816e3e70ce044e1348af0eeea18b59e521581
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to