Muli Salem has uploaded a new change for review.

Change subject: engine: Adding VmGuestInfoInterface (WIP)
......................................................................

engine: Adding VmGuestInfoInterface (WIP)

As part of the Reporting Internal Vnic Information feature,
this patch adds a new table, Dao and entity called
vm_guest_agent_interface, VmGuestInfoInterfaceDao and
VmGuestInfoInterface respectively.

Each row in this table is related to a specific VM, and will
be presented through REST API under that VM. Also, it will
be paired with Vm Interfaces according to Mac address.

Change-Id: Ic2b8e7012ecbeb0b8b9027a5d3b846b8d2325906
Signed-off-by: Muli Salem <[email protected]>
---
M backend/manager/dbscripts/network_sp.sql
A 
backend/manager/dbscripts/upgrade/03_01_1550_add_vm_guest_agent_interface_table.sql
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmGuestAgentInterfacesByVmIdQuery.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmGuestAgentInterface.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetVmGuestAgentInterfacesByVmIdParameters.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDaoDbFacadeImpl.java
M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
M 
frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
10 files changed, 359 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/9772/1

diff --git a/backend/manager/dbscripts/network_sp.sql 
b/backend/manager/dbscripts/network_sp.sql
index be12d3d..b5afb17 100644
--- a/backend/manager/dbscripts/network_sp.sql
+++ b/backend/manager/dbscripts/network_sp.sql
@@ -624,6 +624,44 @@
 
 
 ----------------------------------------------------------------
+-- [network_cluster] Table
+--
+Create or replace FUNCTION GetVmGuestAgentInterfacesByVmId(v_vm_id UUID)
+RETURNS SETOF vm_guest_agent_interface
+   AS $procedure$
+BEGIN
+RETURN QUERY SELECT *
+   FROM vm_guest_agent_interface
+   WHERE vm_id = v_vm_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteVmGuestAgentInterfacesByVmId(v_vm_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+   DELETE FROM vm_guest_agent_interface
+   WHERE vm_id = v_vm_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION InsertVmGuestAgentInterface(v_vm_id UUID,
+   v_interface_name VARCHAR(50),
+   v_mac_address VARCHAR(59),
+   v_ipv4_addresses text,
+   v_ipv6_addresses text)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+INSERT INTO vm_guest_agent_interface(id, interface_name, mac_address, 
ipv4_addresses, ipv6_addresses)
+       VALUES(v_vm_id, v_interface_name, v_mac_address, v_ipv4_addresses, 
v_ipv6_addresses);
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+----------------------------------------------------------------
 -- [vds_interface_statistics] Table
 --
 
diff --git 
a/backend/manager/dbscripts/upgrade/03_01_1550_add_vm_guest_agent_interface_table.sql
 
b/backend/manager/dbscripts/upgrade/03_01_1550_add_vm_guest_agent_interface_table.sql
new file mode 100644
index 0000000..4e8c1f0
--- /dev/null
+++ 
b/backend/manager/dbscripts/upgrade/03_01_1550_add_vm_guest_agent_interface_table.sql
@@ -0,0 +1,26 @@
+CREATE OR REPLACE FUNCTION __temp_Upgrade_add_vm_guest_agent_interface_table()
+RETURNS void
+AS $function$
+BEGIN
+   IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name 
ILIKE 'vm_guest_agent_interface') THEN
+
+-- Add the vm_guest_agent_interface table.
+CREATE TABLE vm_guest_agent_interface
+(
+   vm_id UUID NOT NULL,
+   interface_name VARCHAR (50),
+   mac_address VARCHAR(59),
+   ipv4_addresses text,
+   ipv6_addresses text,
+   CONSTRAINT FK_vm_guest_agent_interface FOREIGN KEY(vm_id) REFERENCES 
vm_static(vm_guid) ON UPDATE NO ACTION ON DELETE CASCADE
+) WITH OIDS;
+
+   END IF;
+END; $function$
+LANGUAGE plpgsql;
+
+
+SELECT * FROM __temp_Upgrade_add_vm_guest_agent_interface_table();
+
+DROP FUNCTION __temp_Upgrade_add_vm_guest_agent_interface_table();
+
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmGuestAgentInterfacesByVmIdQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmGuestAgentInterfacesByVmIdQuery.java
new file mode 100644
index 0000000..f569f60
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmGuestAgentInterfacesByVmIdQuery.java
@@ -0,0 +1,18 @@
+package org.ovirt.engine.core.bll;
+
+import 
org.ovirt.engine.core.common.queries.GetVmGuestAgentInterfacesByVmIdParameters;
+
+public class GetVmGuestAgentInterfacesByVmIdQuery<P extends 
GetVmGuestAgentInterfacesByVmIdParameters>
+        extends QueriesCommandBase<P> {
+
+    public GetVmGuestAgentInterfacesByVmIdQuery(P parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected void executeQueryCommand() {
+        getQueryReturnValue().setReturnValue(
+                getDbFacade().getVmGuestAgentInterfaceDao()
+                        .getAllForVm(getParameters().getVmId()));
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmGuestAgentInterface.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmGuestAgentInterface.java
new file mode 100644
index 0000000..827a7cf
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmGuestAgentInterface.java
@@ -0,0 +1,137 @@
+package org.ovirt.engine.core.common.businessentities;
+
+import java.util.List;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class VmGuestAgentInterface extends IVdcQueryable {
+
+    private static final long serialVersionUID = -9164680367965630250L;
+
+    /**
+     * The Id of the VM this interface belongs to
+     */
+    private Guid vmId;
+
+    /**
+     * The internal nic's name as seen by the guest agent
+     */
+    private String interfaceName;
+
+    /**
+     * The internal nic's mac address as seen by the guest agent
+     */
+    private String macAddress;
+
+    /**
+     * The vNic's IPv4 addresses
+     */
+    private List<String> ipv4Addresses;
+
+    /**
+     * The vNic's IPv6 addresses
+     */
+    private List<String> ipv6Addresses;
+
+    public Guid getVmId() {
+        return vmId;
+    }
+
+    public void setVmId(Guid vmId) {
+        this.vmId = vmId;
+    }
+
+    public String getInterfaceName() {
+        return interfaceName;
+    }
+
+    public void setInterfaceName(String interfaceName) {
+        this.interfaceName = interfaceName;
+    }
+
+    public String getMacAddress() {
+        return macAddress;
+    }
+
+    public void setMacAddress(String macAddress) {
+        this.macAddress = macAddress;
+    }
+
+    public List<String> getIpv4Addresses() {
+        return ipv4Addresses;
+    }
+
+    public void setIpv4Addresses(List<String> ipv4Addresses) {
+        this.ipv4Addresses = ipv4Addresses;
+    }
+
+    public List<String> getIpv6Addresses() {
+        return ipv6Addresses;
+    }
+
+    public void setIpv6Addresses(List<String> ipv6Addresses) {
+        this.ipv6Addresses = ipv6Addresses;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((interfaceName == null) ? 0 : 
interfaceName.hashCode());
+        result = prime * result + ((ipv4Addresses == null) ? 0 : 
ipv4Addresses.hashCode());
+        result = prime * result + ((ipv6Addresses == null) ? 0 : 
ipv6Addresses.hashCode());
+        result = prime * result + ((macAddress == null) ? 0 : 
macAddress.hashCode());
+        result = prime * result + ((vmId == null) ? 0 : vmId.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        VmGuestAgentInterface other = (VmGuestAgentInterface) obj;
+        if (interfaceName == null) {
+            if (other.interfaceName != null) {
+                return false;
+            }
+        } else if (!interfaceName.equals(other.interfaceName)) {
+            return false;
+        }
+        if (ipv4Addresses == null) {
+            if (other.ipv4Addresses != null) {
+                return false;
+            }
+        } else if (!ipv4Addresses.equals(other.ipv4Addresses)) {
+            return false;
+        }
+        if (ipv6Addresses == null) {
+            if (other.ipv6Addresses != null) {
+                return false;
+            }
+        } else if (!ipv6Addresses.equals(other.ipv6Addresses)) {
+            return false;
+        }
+        if (macAddress == null) {
+            if (other.macAddress != null) {
+                return false;
+            }
+        } else if (!macAddress.equals(other.macAddress)) {
+            return false;
+        }
+        if (vmId == null) {
+            if (other.vmId != null) {
+                return false;
+            }
+        } else if (!vmId.equals(other.vmId)) {
+            return false;
+        }
+        return true;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetVmGuestAgentInterfacesByVmIdParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetVmGuestAgentInterfacesByVmIdParameters.java
new file mode 100644
index 0000000..4484d7f
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetVmGuestAgentInterfacesByVmIdParameters.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.core.common.queries;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class GetVmGuestAgentInterfacesByVmIdParameters extends 
VdcQueryParametersBase {
+    private static final long serialVersionUID = -4575932839901418416L;
+    private Guid vmId = new Guid();
+
+    public GetVmGuestAgentInterfacesByVmIdParameters(Guid vmId) {
+        this.vmId = vmId;
+    }
+
+    public Guid getVmId() {
+        return vmId;
+    }
+
+    public GetVmGuestAgentInterfacesByVmIdParameters() {
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
index e629bee..db8f98f 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
@@ -92,6 +92,7 @@
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmDeviceDAO;
 import org.ovirt.engine.core.dao.VmDynamicDAO;
+import org.ovirt.engine.core.dao.VmGuestAgentInterfaceDao;
 import org.ovirt.engine.core.dao.VmInterfaceDynamicDao;
 import org.ovirt.engine.core.dao.VmNetworkInterfaceDAO;
 import org.ovirt.engine.core.dao.VmNetworkStatisticsDAO;
@@ -883,4 +884,13 @@
     public VmInterfaceDynamicDao getVmInterfaceDynamicDao() {
         return getDao(VmInterfaceDynamicDao.class);
     }
+
+    /**
+     * Returns the singleton instance of {@link VmGuestAgentInterfaceDao}.
+     *
+     * @return the dao
+     */
+    public VmGuestAgentInterfaceDao getVmGuestAgentInterfaceDao() {
+        return getDao(VmGuestAgentInterfaceDao.class);
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDao.java
new file mode 100644
index 0000000..292df52
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDao.java
@@ -0,0 +1,35 @@
+package org.ovirt.engine.core.dao;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface;
+import org.ovirt.engine.core.compat.Guid;
+
+/**
+ * {@link VmGuestAgentInterfaceDao} defines a type for performing CRUD 
operations on instances of
+ * {@link VmGuestAgentInterface}.
+ */
+public interface VmGuestAgentInterfaceDao extends DAO {
+
+    /**
+     * Returns a list of the VmGuestAgentInterfaces for the given VM Id
+     * @param vmId
+     *            the VM
+     * @return the list of VmGuestAgentInterfaces
+     */
+    public List<VmGuestAgentInterface> getAllForVm(Guid vmId);
+
+    /**
+     * Removes all the VmGuestAgentInterfaces of the given VM
+     * @param vmId
+     *            the VM
+     */
+    public void removeAllForVm(Guid vmId);
+
+    /**
+     * Persists the given VmGuestAgentInterface
+     * @param vmGuestAgentInterface
+     *            the VmGuestAgentInterface
+     */
+    public void save(VmGuestAgentInterface vmGuestAgentInterface);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDaoDbFacadeImpl.java
new file mode 100644
index 0000000..1f24800
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmGuestAgentInterfaceDaoDbFacadeImpl.java
@@ -0,0 +1,74 @@
+package org.ovirt.engine.core.dao;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface;
+import org.ovirt.engine.core.compat.Guid;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
+
+public class VmGuestAgentInterfaceDaoDbFacadeImpl extends BaseDAODbFacade 
implements VmGuestAgentInterfaceDao
+{
+
+    private static final String DELIMITER = ",";
+
+    public List<VmGuestAgentInterface> getAllForVm(Guid vmId) {
+        return 
getCallsHandler().executeReadList("GetVmGuestAgentInterfacesByVmId",
+                VmGuestAgentInterfaceRowMapper.instance, 
getCustomMapSqlParameterSource()
+                .addValue("vm_id", vmId));
+    }
+
+    public void save(VmGuestAgentInterface vmGuestAgentInterface) {
+        getCallsHandler().executeModification("InsertVmGuestAgentInterface",
+                createFullParametersMapper(vmGuestAgentInterface));
+    }
+
+    public void removeAllForVm(Guid vmId) {
+        getCallsHandler().executeReadList("DeleteVmGuestAgentInterfacesByVmId",
+                VmGuestAgentInterfaceRowMapper.instance, 
getCustomMapSqlParameterSource()
+                        .addValue("vm_id", vmId));
+    }
+
+    protected MapSqlParameterSource 
createFullParametersMapper(VmGuestAgentInterface entity) {
+        return getCustomMapSqlParameterSource()
+                .addValue("vm_id", entity.getVmId())
+                .addValue("interface_name", entity.getInterfaceName())
+                .addValue("mac_address", entity.getMacAddress())
+                .addValue("ipv4_addresses", 
getIpAddressesAsString(entity.getIpv4Addresses()))
+                .addValue("ipv6_addresses", 
getIpAddressesAsString(entity.getIpv4Addresses()));
+    }
+
+    protected final static class VmGuestAgentInterfaceRowMapper implements 
ParameterizedRowMapper<VmGuestAgentInterface> {
+        public static VmGuestAgentInterfaceRowMapper instance = new 
VmGuestAgentInterfaceRowMapper();
+
+        @Override
+        public VmGuestAgentInterface mapRow(ResultSet rs, int rowNum)
+                throws SQLException {
+            VmGuestAgentInterface vmGuestAgentInterface = new 
VmGuestAgentInterface();
+            
vmGuestAgentInterface.setVmId(Guid.createGuidFromString(rs.getString("vm_id")));
+            
vmGuestAgentInterface.setInterfaceName(rs.getString("interface_name"));
+            vmGuestAgentInterface.setMacAddress(rs.getString("mad_address"));
+            
vmGuestAgentInterface.setIpv4Addresses(getListOfIpAddresses(rs.getString("ipv4_addresses")));
+            
vmGuestAgentInterface.setIpv6Addresses(getListOfIpAddresses(rs.getString("ipv6_addresses")));
+            return vmGuestAgentInterface;
+        }
+
+        private List<String> getListOfIpAddresses(String ipAddressesAsString) {
+            List<String> ipAddresses = new ArrayList<String>();
+            for (String ipAddress : ipAddressesAsString.split(DELIMITER)) {
+                if (!ipAddress.equals("")) {
+                    ipAddresses.add(ipAddress.trim());
+                }
+            }
+            return ipAddresses;
+        }
+    }
+
+    private String getIpAddressesAsString(List<String> ipAddresses) {
+        return StringUtils.join(ipAddresses, DELIMITER);
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties 
b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
index 74b57f6..2da4eff 100644
--- a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
+++ b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
@@ -57,4 +57,4 @@
 
ImageStorageDomainMapDao=org.ovirt.engine.core.dao.ImageStorageDomainMapDaoDbFacadeImpl
 NetworkViewDao=org.ovirt.engine.core.dao.NetworkViewDaoDbFacadeImpl
 
VmInterfaceDynamicDao=org.ovirt.engine.core.dao.VmInterfaceDynamicDaoDbFacadeImpl
-
+VmGuestAgentInterfaceDao=org.ovirt.engine.core.dao.VmGuestAgentInterfaceDaoDbFacadeImpl
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 2e8a657..cae07bd 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
@@ -157,6 +157,7 @@
                <include 
name="common/businessentities/BusinessEntityComparator.java" />
                 <include name="common/businessentities/Identifiable.java" />
                <include name="common/businessentities/VmInterfaceDynamic.java" 
/>
+               <include 
name="common/businessentities/VmGuestAgentInterface.java" />
 
                <include name="common/job/*.java" />
 


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

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

Reply via email to