Moti Asayag has uploaded a new change for review.

Change subject: engine: Introduce VmNic, a base class for VmNetworkInterface
......................................................................

engine: Introduce VmNic, a base class for VmNetworkInterface

The VmNic class will act as the backend entity for vm network
interface related actions.

The VmNetworkInterface, the former engine entity will serve as
the view entity used by the clients and also as their entity
for vnic related actions.

Change-Id: I3fdd4e471aaf28e51dddb2a1205e6bdad620e3a4
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterface.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNic.java
M 
frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
3 files changed, 221 insertions(+), 199 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/17129/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterface.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterface.java
index f1b2eb7..3e9828f 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterface.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNetworkInterface.java
@@ -1,113 +1,19 @@
 package org.ovirt.engine.core.common.businessentities.network;
 
-import java.util.Map;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
-import javax.validation.constraints.Size;
-
-import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
 import org.ovirt.engine.core.common.utils.ObjectUtils;
-import org.ovirt.engine.core.common.validation.group.CreateEntity;
-import org.ovirt.engine.core.common.validation.group.UpdateEntity;
-import org.ovirt.engine.core.common.validation.group.UpdateVmNic;
-import org.ovirt.engine.core.compat.Guid;
 
 /**
- * <code>VmNetworkInterface</code> defines a type of {@link NetworkInterface} 
for instances of {@link VM}.
+ * <code>VmNetworkInterface</code> defines a type of {@link VmNic} for 
instances of {@link VM}.
  *
  */
-public class VmNetworkInterface extends NetworkInterface<VmNetworkStatistics> {
-    public static final String VALID_MAC_ADDRESS_FORMAT = 
"(\\p{XDigit}{2}:){5}\\p{XDigit}{2}";
+public class VmNetworkInterface extends VmNic {
 
-    private static final long serialVersionUID = 7428150502868988886L;
-
-    protected static final String VALIDATION_MESSAGE_MAC_ADDRESS_NOT_NULL =
-            "VALIDATION.VM.NETWORK.MAC.ADDRESS.NOT_NULL";
-    protected static final String VALIDATION_MESSAGE_NAME_NOT_NULL = 
"VALIDATION.VM.NETWORK.NAME.NOT_NULL";
-    protected static final String VALIDATION_MESSAGE_MAC_ADDRESS_INVALID = 
"VALIDATION.VM.NETWORK.MAC.ADDRESS.INVALID";
-
-    private Guid vmId;
-    private Guid vnicProfileId;
-    private String vmName;
-    private Guid vmTemplateId;
-    private boolean plugged = true;
-
-    @Size(max = BusinessEntitiesDefinitions.NETWORK_NAME_SIZE)
+    private static final long serialVersionUID = -6110269859408208756L;
     private String networkName;
-
-    /**
-     * Device custom properties
-     */
-    private Map<String, String> customProperties;
-
-    /**
-     * Link State of the Nic. <BR>
-     * <code>true</code> if UP and <code>false</code> if DOWN.
-     */
-    private boolean linked = true;
     private boolean portMirroring;
+    private String vmName;
 
     public VmNetworkInterface() {
-        super(new VmNetworkStatistics(), VmInterfaceType.pv.getValue());
-    }
-
-    /**
-     * Sets the VM instance id.
-     *
-     * @param vmId
-     *            the id
-     */
-    public void setVmId(Guid vmId) {
-        this.vmId = vmId;
-        this.statistics.setVmId(vmId);
-    }
-
-    /**
-     * Returns the VM instance id.
-     *
-     * @return the id
-     */
-    public Guid getVmId() {
-        return vmId;
-    }
-
-    /**
-     * Sets the VM name.
-     *
-     * @param vmName
-     *            the name
-     */
-    public void setVmName(String vmName) {
-        this.vmName = vmName;
-    }
-
-    /**
-     * Returns the VM name.
-     *
-     * @return the name
-     */
-    public String getVmName() {
-        return vmName;
-    }
-
-    /**
-     * Sets the VM template instance id.
-     *
-     * @param vmTemplateId
-     *            the id
-     */
-    public void setVmTemplateId(Guid vmTemplateId) {
-        this.vmTemplateId = vmTemplateId;
-    }
-
-    /**
-     * Returns the VM template instance id.
-     *
-     * @return the id
-     */
-    public Guid getVmTemplateId() {
-        return vmTemplateId;
     }
 
     @Override
@@ -115,6 +21,14 @@
         return id;
     }
 
+    /**
+     * The network name the vnic is attached to
+     *
+     * @param networkName
+     * @deprecated since ovirt 3.3 the network name is replaced by {@link 
VmNic.getVnicProfileId()} which determines the
+     *             vnic profile used for using the network
+     */
+    @Deprecated
     public void setNetworkName(String networkName) {
         this.networkName = networkName;
     }
@@ -123,64 +37,36 @@
         return networkName;
     }
 
-    public boolean isPlugged() {
-        return plugged;
+    public void setVmName(String vmName) {
+        this.vmName = vmName;
     }
 
-    public void setPlugged(boolean plugged) {
-        this.plugged = plugged;
+    public String getVmName() {
+        return vmName;
     }
 
-    public Map<String, String> getCustomProperties() {
-        return customProperties;
+    public boolean isPortMirroring() {
+        return portMirroring;
     }
 
-    public void setCustomProperties(Map<String, String> customProperties) {
-        this.customProperties = customProperties;
-    }
-
-    public boolean isLinked() {
-        return linked;
-    }
-
-    public void setLinked(boolean linked) {
-        this.linked = linked;
-    }
-
-    @NotNull(message = VmNetworkInterface.VALIDATION_MESSAGE_NAME_NOT_NULL, 
groups = { CreateEntity.class,
-            UpdateEntity.class })
-    @Override
-    public String getName() {
-        return super.getName();
-    }
-
-    @NotNull(message = 
VmNetworkInterface.VALIDATION_MESSAGE_MAC_ADDRESS_NOT_NULL, groups = { 
UpdateVmNic.class })
-    @Pattern.List({
-            @Pattern(regexp = "(^$)|(" + VALID_MAC_ADDRESS_FORMAT + ")",
-                    message = 
VmNetworkInterface.VALIDATION_MESSAGE_MAC_ADDRESS_INVALID,
-                    groups = { CreateEntity.class }),
-            @Pattern(regexp = VALID_MAC_ADDRESS_FORMAT,
-                    message = 
VmNetworkInterface.VALIDATION_MESSAGE_MAC_ADDRESS_INVALID,
-                    groups = { UpdateEntity.class })
-    })
-    @Override
-    public String getMacAddress() {
-        return super.getMacAddress();
+    public void setPortMirroring(boolean portMirroring) {
+        this.portMirroring = portMirroring;
     }
 
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
-        builder.append("VmNetworkInterface {id=")
+        builder.append(getName())
+                .append(" {id=")
                 .append(getId())
                 .append(", networkName=")
                 .append(getNetworkName())
+                .append(", vnicProfileId=")
+                .append(getVnicProfileId())
                 .append(", speed=")
                 .append(getSpeed())
                 .append(", type=")
                 .append(getType())
-                .append(", name=")
-                .append(getName())
                 .append(", macAddress=")
                 .append(getMacAddress())
                 .append(", active=")
@@ -193,8 +79,6 @@
                 .append(isPortMirroring())
                 .append(", vmId=")
                 .append(getVmId())
-                .append(", vnicProfileId=")
-                .append(getVnicProfileId())
                 .append(", vmName=")
                 .append(getVmName())
                 .append(", vmTemplateId=")
@@ -207,14 +91,9 @@
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result + (plugged ? 1231 : 1237);
-        result = prime * result + ((networkName == null) ? 0 : 
networkName.hashCode());
-        result = prime * result + (customProperties == null ? 0 : 
customProperties.hashCode());
-        result = prime * result + (linked ? 1231 : 1237);
-        result = prime * result + ((vmId == null) ? 0 : vmId.hashCode());
-        result = prime * result + ((vnicProfileId == null) ? 0 : 
vnicProfileId.hashCode());
-        result = prime * result + ((vmName == null) ? 0 : vmName.hashCode());
-        result = prime * result + ((vmTemplateId == null) ? 0 : 
vmTemplateId.hashCode());
+        result = prime * result + ((getNetworkName() == null) ? 0 : 
getNetworkName().hashCode());
+        result = prime * result + (isPortMirroring() ? 1231 : 1237);
+        result = prime * result + ((getVmName() == null) ? 0 : 
getVmName().hashCode());
         return result;
     }
 
@@ -230,63 +109,15 @@
             return false;
         }
         VmNetworkInterface other = (VmNetworkInterface) obj;
-        if (plugged != other.plugged) {
+        if (!ObjectUtils.objectsEqual(other.getNetworkName(), 
other.getNetworkName())) {
             return false;
         }
-        if (!ObjectUtils.objectsEqual(other.networkName, other.networkName)) {
+        if (isPortMirroring() != other.isPortMirroring()) {
             return false;
         }
-        if (!ObjectUtils.objectsEqual(customProperties, 
other.customProperties)) {
-            return false;
-        }
-
-        if (linked != other.linked) {
-            return false;
-        }
-        if (vmId == null) {
-            if (other.vmId != null) {
-                return false;
-            }
-        } else if (!vmId.equals(other.vmId)) {
-            return false;
-        }
-        if (vnicProfileId == null) {
-            if (other.vnicProfileId != null) {
-                return false;
-            }
-        } else if (!vnicProfileId.equals(other.vnicProfileId)) {
-            return false;
-        }
-        if (vmName == null) {
-            if (other.vmName != null) {
-                return false;
-            }
-        } else if (!vmName.equals(other.vmName)) {
-            return false;
-        }
-        if (vmTemplateId == null) {
-            if (other.vmTemplateId != null) {
-                return false;
-            }
-        } else if (!vmTemplateId.equals(other.vmTemplateId)) {
+        if (!ObjectUtils.objectsEqual(other.getVmName(), other.getVmName())) {
             return false;
         }
         return true;
-    }
-
-    public boolean isPortMirroring() {
-        return portMirroring;
-    }
-
-    public void setPortMirroring(boolean portMirroring) {
-        this.portMirroring = portMirroring;
-    }
-
-    public Guid getVnicProfileId() {
-        return vnicProfileId;
-    }
-
-    public void setVnicProfileId(Guid vnicProfileId) {
-        this.vnicProfileId = vnicProfileId;
     }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNic.java
new file mode 100644
index 0000000..455d882
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VmNic.java
@@ -0,0 +1,190 @@
+package org.ovirt.engine.core.common.businessentities.network;
+
+import java.util.Map;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+
+import org.ovirt.engine.core.common.utils.ObjectUtils;
+import org.ovirt.engine.core.common.validation.group.CreateEntity;
+import org.ovirt.engine.core.common.validation.group.UpdateEntity;
+import org.ovirt.engine.core.common.validation.group.UpdateVmNic;
+import org.ovirt.engine.core.compat.Guid;
+
+/**
+ * <code>VmNic</code> defines a type of {@link NetworkInterface} for instances 
of {@link VM}.
+ */
+public class VmNic extends NetworkInterface<VmNetworkStatistics> {
+    public static final String VALID_MAC_ADDRESS_FORMAT = 
"(\\p{XDigit}{2}:){5}\\p{XDigit}{2}";
+
+    private static final long serialVersionUID = 7428150502868988886L;
+
+    protected static final String VALIDATION_MESSAGE_MAC_ADDRESS_NOT_NULL =
+            "VALIDATION.VM.NETWORK.MAC.ADDRESS.NOT_NULL";
+    protected static final String VALIDATION_MESSAGE_NAME_NOT_NULL = 
"VALIDATION.VM.NETWORK.NAME.NOT_NULL";
+    protected static final String VALIDATION_MESSAGE_MAC_ADDRESS_INVALID = 
"VALIDATION.VM.NETWORK.MAC.ADDRESS.INVALID";
+
+    private Guid vmId;
+    private Guid vnicProfileId;
+    private Guid vmTemplateId;
+    private boolean plugged = true;
+
+    /**
+     * Device custom properties
+     */
+    private Map<String, String> customProperties;
+
+    /**
+     * Link State of the Nic. <BR>
+     * <code>true</code> if UP and <code>false</code> if DOWN.
+     */
+    private boolean linked = true;
+
+    public VmNic() {
+        super(new VmNetworkStatistics(), VmInterfaceType.pv.getValue());
+    }
+
+    public void setVmId(Guid vmId) {
+        this.vmId = vmId;
+        this.statistics.setVmId(vmId);
+    }
+
+    public Guid getVmId() {
+        return vmId;
+    }
+
+    public void setVmTemplateId(Guid vmTemplateId) {
+        this.vmTemplateId = vmTemplateId;
+    }
+
+    public Guid getVmTemplateId() {
+        return vmTemplateId;
+    }
+
+    public boolean isPlugged() {
+        return plugged;
+    }
+
+    public void setPlugged(boolean plugged) {
+        this.plugged = plugged;
+    }
+
+    public Map<String, String> getCustomProperties() {
+        return customProperties;
+    }
+
+    public void setCustomProperties(Map<String, String> customProperties) {
+        this.customProperties = customProperties;
+    }
+
+    public boolean isLinked() {
+        return linked;
+    }
+
+    public void setLinked(boolean linked) {
+        this.linked = linked;
+    }
+
+    @NotNull(message = VmNic.VALIDATION_MESSAGE_NAME_NOT_NULL, groups = { 
CreateEntity.class,
+            UpdateEntity.class })
+    @Override
+    public String getName() {
+        return super.getName();
+    }
+
+    @NotNull(message = VmNic.VALIDATION_MESSAGE_MAC_ADDRESS_NOT_NULL, groups = 
{ UpdateVmNic.class })
+    @Pattern.List({
+            @Pattern(regexp = "(^$)|(" + VALID_MAC_ADDRESS_FORMAT + ")",
+                    message = VmNic.VALIDATION_MESSAGE_MAC_ADDRESS_INVALID,
+                    groups = { CreateEntity.class }),
+            @Pattern(regexp = VALID_MAC_ADDRESS_FORMAT,
+                    message = VmNic.VALIDATION_MESSAGE_MAC_ADDRESS_INVALID,
+                    groups = { UpdateEntity.class })
+    })
+    @Override
+    public String getMacAddress() {
+        return super.getMacAddress();
+    }
+
+    public Guid getVnicProfileId() {
+        return vnicProfileId;
+    }
+
+    public void setVnicProfileId(Guid vnicProfileId) {
+        this.vnicProfileId = vnicProfileId;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(getName())
+                .append(" {id=")
+                .append(getId())
+                .append(", vnicProfileId=")
+                .append(getVnicProfileId())
+                .append(", speed=")
+                .append(getSpeed())
+                .append(", type=")
+                .append(getType())
+                .append(", macAddress=")
+                .append(getMacAddress())
+                .append(", plugged=")
+                .append(isPlugged())
+                .append(", customProperties=")
+                .append(getCustomProperties())
+                .append(", linked=")
+                .append(isLinked())
+                .append(", vmId=")
+                .append(getVmId())
+                .append(", vmTemplateId=")
+                .append(getVmTemplateId())
+                .append("}");
+        return builder.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + (isPlugged() ? 1231 : 1237);
+        result = prime * result + (getCustomProperties() == null ? 0 : 
getCustomProperties().hashCode());
+        result = prime * result + (isLinked() ? 1231 : 1237);
+        result = prime * result + ((getVmId() == null) ? 0 : 
getVmId().hashCode());
+        result = prime * result + ((getVnicProfileId() == null) ? 0 : 
getVnicProfileId().hashCode());
+        result = prime * result + ((getVmTemplateId() == null) ? 0 : 
getVmTemplateId().hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (!(obj instanceof VmNic)) {
+            return false;
+        }
+        VmNic other = (VmNic) obj;
+        if (isPlugged() != other.isPlugged()) {
+            return false;
+        }
+        if (!ObjectUtils.objectsEqual(getCustomProperties(), 
other.getCustomProperties())) {
+            return false;
+        }
+        if (isPlugged() != other.isPlugged()) {
+            return false;
+        }
+        if (!ObjectUtils.objectsEqual(getVmId(), other.getVmId())) {
+            return false;
+        }
+        if (!ObjectUtils.objectsEqual(getVnicProfileId(), 
other.getVnicProfileId())) {
+            return false;
+        }
+        if (!ObjectUtils.objectsEqual(getVmTemplateId(), 
other.getVmTemplateId())) {
+            return false;
+        }
+        return true;
+    }
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
index 1763ed4..46f6328 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
@@ -66,6 +66,7 @@
                <include 
name="common/businessentities/network/VdsNetworkStatistics.java" />
                <include 
name="common/businessentities/network/VnicProfileView.java" />
                <include 
name="common/businessentities/network/VnicProfile.java" />
+               <include name="common/businessentities/network/VmNic.java" />
 
                <include name="common/businessentities/Commented.java" />
                <include name="common/businessentities/IVdcQueryable.java" />


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

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

Reply via email to