Martin Peřina has uploaded a new change for review.

Change subject: restapi: Refactor conversion between PmProxies and VDS/VdsStatic
......................................................................

restapi: Refactor conversion between PmProxies and VDS/VdsStatic

Refactors the code to use List<FenceProxySourceType> instead of comma
separated string when converting between PowerManagement and
VDS/VdsStatic entities.

Change-Id: I5e5d0f30cec48e5173680c30988e2bc4969bc365
Bug-Url: https://bugzilla.redhat.com/1182510
Signed-off-by: Martin Perina <mper...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
M 
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostMapperTest.java
3 files changed, 15 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/39760/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
index c120c47..2f3bbc3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
@@ -11,7 +11,6 @@
 import org.hibernate.validator.constraints.Range;
 import org.ovirt.engine.core.common.businessentities.pm.FenceProxySourceType;
 import org.ovirt.engine.core.common.utils.ObjectUtils;
-import org.ovirt.engine.core.common.utils.pm.FenceProxySourceTypeHelper;
 import org.ovirt.engine.core.common.validation.annotation.HostnameOrIp;
 import org.ovirt.engine.core.common.validation.annotation.ValidNameWithDot;
 import org.ovirt.engine.core.common.validation.group.CreateEntity;
@@ -278,16 +277,6 @@
 
     public void setPmKdumpDetection(boolean pmKdumpDetection) {
         this.pmKdumpDetection = pmKdumpDetection;
-    }
-
-    // TODO: Remove method when all callers use List<FenceProxySourceType>
-    public String getPmProxyPreferences() {
-        return FenceProxySourceTypeHelper.saveAsString(getFenceProxySources());
-    }
-
-    // TODO: Remove method when all callers use List<FenceProxySourceType>
-    public void setPmProxyPreferences(String pmProxyPreferences) {
-        
setFenceProxySources(FenceProxySourceTypeHelper.parseFromString(pmProxyPreferences));
     }
 
     public List<FenceProxySourceType> getFenceProxySources() {
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
index 8a440a3..d20f4ec 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
@@ -2,9 +2,10 @@
 
 import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.api.common.util.StatusUtils;
 import org.ovirt.engine.api.model.Action;
 import org.ovirt.engine.api.model.AutoNumaStatus;
@@ -51,6 +52,7 @@
 import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import 
org.ovirt.engine.core.common.businessentities.VdsTransparentHugePagesState;
+import org.ovirt.engine.core.common.businessentities.pm.FenceProxySourceType;
 import org.ovirt.engine.core.compat.Guid;
 
 
@@ -140,14 +142,11 @@
             
entity.setDisablePowerManagementPolicy(!model.isAutomaticPmEnabled());
         }
         if (model.isSetPmProxies()) {
-            String delim = "";
-            StringBuilder builder = new StringBuilder();
+            List<FenceProxySourceType> fenceProxySources = new LinkedList<>();
             for (PmProxy pmProxy : model.getPmProxies().getPmProxy()) {
-                builder.append(delim);
-                builder.append(pmProxy.getType());
-                delim = ",";
+                
fenceProxySources.add(FenceProxySourceType.forValue(pmProxy.getType()));
             }
-            entity.setPmProxyPreferences(builder.toString());
+            entity.setFenceProxySources(fenceProxySources);
         }
         if (model.isSetKdumpDetection()) {
             entity.setPmKdumpDetection(model.isKdumpDetection());
@@ -378,14 +377,13 @@
     @Mapping(from = VDS.class, to = PowerManagement.class)
     public static PowerManagement map(VDS entity, PowerManagement template) {
         PowerManagement model = template != null ? template : new 
PowerManagement();
-        if (entity.getPmProxyPreferences() != null) {
+        if (entity.getFenceProxySources() != null) {
             PmProxies pmProxies = new PmProxies();
-                String[] proxies = 
StringUtils.split(entity.getPmProxyPreferences(), ",");
-                for (String proxy : proxies) {
-                        PmProxy pmProxy = new PmProxy();
-                pmProxy.setType(proxy);
-                        pmProxies.getPmProxy().add(pmProxy);
-                }
+            for (FenceProxySourceType fenceProxySource : 
entity.getFenceProxySources()) {
+                PmProxy pmProxy = new PmProxy();
+                pmProxy.setType(fenceProxySource.getValue());
+                pmProxies.getPmProxy().add(pmProxy);
+            }
             model.setPmProxies(pmProxies);
         }
         model.setKdumpDetection(entity.isPmKdumpDetection());
diff --git 
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostMapperTest.java
 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostMapperTest.java
index a69d1af..9f99a5e 100644
--- 
a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostMapperTest.java
+++ 
b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/HostMapperTest.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.api.restapi.types;
 
 import java.math.BigDecimal;
+import java.util.Arrays;
 
 import org.junit.Test;
 import org.ovirt.engine.api.model.Agent;
@@ -15,6 +16,7 @@
 import org.ovirt.engine.core.common.businessentities.FenceAgent;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
+import org.ovirt.engine.core.common.businessentities.pm.FenceProxySourceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.RpmVersion;
 
@@ -158,7 +160,7 @@
     public void testPmProxyPreferences() {
         VDS vds = new VDS();
         vds.setId(Guid.Empty);
-        vds.setPmProxyPreferences("cluster,dc");
+        vds.setFenceProxySources(Arrays.asList(FenceProxySourceType.CLUSTER, 
FenceProxySourceType.DC));
         Host host = HostMapper.map(vds, (Host) null);
         
assertEquals(host.getPowerManagement().getPmProxies().getPmProxy().size(), 2);
         
assertTrue(host.getPowerManagement().getPmProxies().getPmProxy().get(0).getType().equalsIgnoreCase("cluster"));


-- 
To view, visit https://gerrit.ovirt.org/39760
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e5d0f30cec48e5173680c30988e2bc4969bc365
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Peřina <mper...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to