Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Replace "storage_manager" with "spm"
......................................................................

restapi: Replace "storage_manager" with "spm"

Currently the SPM priority of a host is modeled in the RESTAPI as an
attribute of an element that also has text content:

  <host>
    <storage_manager priority="5">true</storage_manager>
  </host>

This means that it is impossible to send an udpate containing only the
priority and not the text content. For example, a document like the
following:

  <host>
    <storage_manager priority="5"/>
  </host>

Is not valid because the text is declared as xs:boolean, and an empty
text isn't a valid value.

To avoid this issue this patch removes the "storage_manager" element
from the RSDL metadata and introduces a new "spm" element that contains
inner elements for the priority and the SPM status. For example:

  <host>
    <spm>
      <priority>5</priority>
      <status>
        <state>spm</state>
      </status>
    </spm>
  </host>

This way clients can send updates for only the priority:

  <host>
    <spm>
      <priority>6</priority>
    </spm>
  </host>

The previous "storage_manager" element and its behaviour are preserved
for backwards compatibility, but removed from the RSDL metadata.

Change-Id: I9bb8dba2385b1219f6d90fa99692a79fc7cb36b7
Bug-Url: https://bugzilla.redhat.com/1136061
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/SpmState.java
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/HostMapper.java
5 files changed, 115 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/32274/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/SpmState.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/SpmState.java
new file mode 100644
index 0000000..a2158a0
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/SpmState.java
@@ -0,0 +1,36 @@
+/*
+* Copyright (c) 2014 Red Hat, Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.ovirt.engine.api.model;
+
+public enum SpmState {
+    NONE,
+    CONTENDING,
+    SPM;
+
+    public String value() {
+        return name().toLowerCase();
+    }
+
+    public static SpmState fromValue(String text) {
+        try {
+            return valueOf(text.toUpperCase());
+        }
+        catch (IllegalArgumentException exception) {
+            return null;
+        }
+    }
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
index a64a831..fd58c05 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
@@ -634,6 +634,7 @@
           <xs:element ref="watchdog_actions" minOccurs="0"/>
           <xs:element ref="authentication_methods" minOccurs="0"/>
           <xs:element ref="kdump_states" minOccurs="0"/>
+          <xs:element ref="spm_states" minOccurs="0"/>
           <!--  External tasks -->
           <xs:element ref="step_types" minOccurs="0"/>
           <xs:element ref="payload_encodings" minOccurs="0"/>
@@ -1083,6 +1084,20 @@
         <xs:annotation>
           <xs:appinfo>
             <jaxb:property name="KdumpStates"/>
+          </xs:appinfo>
+        </xs:annotation>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="spm_states" type="SpmStates"/>
+
+  <xs:complexType name="SpmStates">
+    <xs:sequence>
+      <xs:element name="spm_state" type="xs:string" minOccurs="0" 
maxOccurs="unbounded">
+        <xs:annotation>
+          <xs:appinfo>
+            <jaxb:property name="SpmState"/>
           </xs:appinfo>
         </xs:annotation>
       </xs:element>
@@ -1765,7 +1780,10 @@
                e.g. the standard VDSM port 54321 -->
           <xs:element name="port" type="xs:unsignedShort" minOccurs="0"/>
           <xs:element name="type" type="xs:string" minOccurs="0"/>
+          <!-- This element is deprecated because it uses a mix of attributes 
and text content, which makes it
+               impossible to send the values independently. Use the the "spm" 
element instead. -->
           <xs:element name="storage_manager" type="StorageManager" 
minOccurs="0"/>
+          <xs:element name="spm" type="SPM" minOccurs="0"/>
           <xs:element name="version" type="Version" minOccurs="0"/>
           <xs:element ref="hardware_information" minOccurs="0"/>
           <xs:element ref="power_management" minOccurs="0"/>
@@ -1801,6 +1819,8 @@
     </xs:complexContent>
   </xs:complexType>
 
+  <!-- This element is deprecated because it uses a mix of attributes and text 
content, which makes it
+       impossible to send the values independently. Use the the "spm" element 
instead. -->
   <xs:element name="storage_manager" type="StorageManager"/>
 
   <xs:complexType name="StorageManager">
@@ -1817,6 +1837,15 @@
     </xs:simpleContent>
   </xs:complexType>
 
+  <xs:element name="spm" type="SPM"/>
+
+  <xs:complexType name="SPM">
+    <xs:sequence>
+      <xs:element name="priority" type="xs:int" minOccurs="0" maxOccurs="1"/>
+      <xs:element ref="status" minOccurs="0" maxOccurs="1"/>
+    </xs:sequence>
+  </xs:complexType>
+
   <xs:element name="hosted_engine" type="HostedEngine"/>
 
   <xs:complexType name="HostedEngine">
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index 97e340e..4b9530e 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -2784,7 +2784,8 @@
       signatures:
       - mandatoryArguments: {}
         optionalArguments: {host.name: 'xs:string', host.comment: 'xs:string', 
host.address: 'xs:string', host.root_password--DEPRECATED: 'xs:string',
-          host.display.address: 'xs:string', host.cluster.id|name: 
'xs:string', host.port: 'xs:int', host.storage_manager.priority: 'xs:int',
+          host.display.address: 'xs:string', host.cluster.id|name: 
'xs:string', host.port: 'xs:int',
+          host.spm.priority: 'xs:int',
           host.power_management.type: 'xs:string', 
host.power_management.enabled: 'xs:boolean', host.power_management.address: 
'xs:string',
           host.power_management.username: 'xs:string', 
host.power_management.password: 'xs:string', 
host.power_management.automatic_pm_enabled: 'xs:boolean',
           host.power_management.options.option--COLLECTION: {option.name: 
'xs:string', option.value: 'xs:string'},
@@ -2795,7 +2796,9 @@
       - mandatoryArguments: {}
         optionalArguments: {host.name: 'xs:string', host.comment: 'xs:string', 
host.address: 'xs:string',
           host.ssh.port: 'xs:int', host.ssh.user.user_name: 'xs:string', 
host.ssh.fingerprint: 'xs:string', host.display.address: 'xs:string',
-          host.cluster.id|name: 'xs:string', host.port: 'xs:int', 
host.storage_manager.priority: 'xs:int', host.power_management.type: 
'xs:string',
+          host.cluster.id|name: 'xs:string', host.port: 'xs:int',
+          host.spm.priority: 'xs:int',
+          host.power_management.type: 'xs:string',
           host.power_management.automatic_pm_enabled: 'xs:boolean',
           host.power_management.enabled: 'xs:boolean', 
host.power_management.address: 'xs:string', host.power_management.username: 
'xs:string',
           host.power_management.password: 'xs:string', 
host.power_management.options.option--COLLECTION: {option.name: 'xs:string',
@@ -2817,7 +2820,9 @@
       signatures:
       - mandatoryArguments: {host.name: 'xs:string', host.address: 
'xs:string', host.root_password--DEPRECATED: 'xs:string', host.cluster.id|name: 
'xs:string'}
         optionalArguments: {host.comment: 'xs:string', host.port: 'xs:int',
-          host.display.address: 'xs:string', host.storage_manager.priority: 
'xs:int', host.power_management.type: 'xs:string',
+          host.display.address: 'xs:string',
+          host.spm.priority: 'xs:int',
+          host.power_management.type: 'xs:string',
           host.power_management.enabled: 'xs:boolean', 
host.power_management.address: 'xs:string', host.power_management.username: 
'xs:string', host.power_management.automatic_pm_enabled: 'xs:boolean',
           host.power_management.password: 'xs:string', 
host.power_management.options.option--COLLECTION: {option.name: 'xs:string', 
option.value: 'xs:string'},
           host.power_management.pm_proxy--COLLECTION: {propietary : 
'xs:string'}, host.power_management.agents.agent--COLLECTION:{type: 'xs:string',
@@ -2827,7 +2832,9 @@
       - mandatoryArguments: {host.name: 'xs:string', host.address: 
'xs:string', host.cluster.id|name: 'xs:string'}
         optionalArguments: {host.comment: 'xs:string', host.ssh.port: 
'xs:int', host.ssh.fingerprint: 'xs:string', host.ssh.authentication_method: 
'xs:string',
           host.ssh.user.user_name: 'xs:string', host.ssh.user.password: 
'xs:string', host.port: 'xs:int',
-          host.display.address: 'xs:string', host.storage_manager.priority: 
'xs:int', host.power_management.type: 'xs:string', 
host.power_management.automatic_pm_enabled: 'xs:boolean',
+          host.display.address: 'xs:string',
+          host.spm.priority: 'xs:int',
+          host.power_management.type: 'xs:string', 
host.power_management.automatic_pm_enabled: 'xs:boolean',
           host.power_management.enabled: 'xs:boolean', 
host.power_management.address: 'xs:string', host.power_management.username: 
'xs:string',
           host.power_management.password: 'xs:string', 
host.power_management.options.option--COLLECTION: {option.name: 'xs:string', 
option.value: 'xs:string'},
           host.power_management.pm_proxy--COLLECTION: {propietary : 
'xs:string'}, host.power_management.agents.agent--COLLECTION:{type: 
'xs:string', address: 'xs:string',
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
index 921bc49..c4f89e7 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCapabilitiesResource.java
@@ -88,6 +88,8 @@
 import org.ovirt.engine.api.model.SerialNumberPolicy;
 import org.ovirt.engine.api.model.SnapshotStatus;
 import org.ovirt.engine.api.model.SnapshotStatuses;
+import org.ovirt.engine.api.model.SpmState;
+import org.ovirt.engine.api.model.SpmStates;
 import org.ovirt.engine.api.model.Stages;
 import org.ovirt.engine.api.model.StepEnum;
 import org.ovirt.engine.api.model.StepTypes;
@@ -270,6 +272,7 @@
         addSELinuxModes(version, SELinuxMode.values());
         addRngSources(version, RngSource.values());
         addPolicyUnitTypes(version, PolicyUnitType.values());
+        addSpmStates(version, SpmState.values());
         // External tasks types
         addStepEnumTypes(version, StepEnum.values());
 
@@ -891,6 +894,16 @@
         }
     }
 
+    private void addSpmStates(VersionCaps version, SpmState[] values) {
+        if (VersionUtils.greaterOrEqual(version, VERSION_3_5)) {
+            SpmStates states = new SpmStates();
+            for (SpmState state : values) {
+                states.getSpmState().add(state.value());
+            }
+            version.setSpmStates(states);
+        }
+    }
+
     @Override
     public CapabiliyResource getCapabilitiesSubResource(String id) {
         return new BackendCapabilityResource(id, this);
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 aead25f..8fbbb07 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
@@ -31,6 +31,7 @@
 import org.ovirt.engine.api.model.PmProxy;
 import org.ovirt.engine.api.model.PowerManagement;
 import org.ovirt.engine.api.model.SELinuxMode;
+import org.ovirt.engine.api.model.SPM;
 import org.ovirt.engine.api.model.SSH;
 import org.ovirt.engine.api.model.StorageManager;
 import org.ovirt.engine.api.model.TransparentHugePages;
@@ -38,6 +39,7 @@
 import org.ovirt.engine.api.model.Version;
 import org.ovirt.engine.api.model.VmSummary;
 import org.ovirt.engine.api.model.SELinux;
+import org.ovirt.engine.api.model.SpmState;
 import org.ovirt.engine.api.restapi.model.AuthenticationMethod;
 import org.ovirt.engine.api.restapi.utils.GuidUtils;
 import org.ovirt.engine.core.common.action.VdsOperationActionParameters;
@@ -50,6 +52,7 @@
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import 
org.ovirt.engine.core.common.businessentities.VdsTransparentHugePagesState;
 import org.ovirt.engine.core.compat.Guid;
+
 
 public class HostMapper {
 
@@ -92,6 +95,11 @@
         if (model.isSetStorageManager()) {
             if (model.getStorageManager().getPriority() != null) {
                 
entity.setVdsSpmPriority(model.getStorageManager().getPriority());
+            }
+        }
+        if (model.isSetSpm()) {
+            if (model.getSpm().getPriority() != null) {
+                entity.setVdsSpmPriority(model.getSpm().getPriority());
             }
         }
         if (model.isSetDisplay() && model.getDisplay().isSetAddress()) {
@@ -357,6 +365,10 @@
         sm.setPriority(entity.getVdsSpmPriority());
         sm.setValue(entity.getSpmStatus() == VdsSpmStatus.SPM);
         model.setStorageManager(sm);
+        SPM spm = new SPM();
+        spm.setPriority(entity.getVdsSpmPriority());
+        spm.setStatus(StatusUtils.create(map(entity.getSpmStatus(), null)));
+        model.setSpm(spm);
         if (entity.getVersion() != null &&
                 entity.getVersion().getMajor() != -1 &&
                 entity.getVersion().getMinor() != -1 &&
@@ -828,4 +840,18 @@
         }
         return result;
     }
+
+    @Mapping(from = VdsSpmStatus.class, to = SpmState.class)
+    public static SpmState map(VdsSpmStatus entityStatus, SpmState template) {
+        switch (entityStatus) {
+            case None:
+                return SpmState.NONE;
+            case Contending:
+                return SpmState.CONTENDING;
+            case SPM:
+                return SpmState.SPM;
+            default:
+                return null;
+        }
+    }
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bb8dba2385b1219f6d90fa99692a79fc7cb36b7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to