Sergey Gotliv has uploaded a new change for review.

Change subject: engine, dao: Introduce ISCSI Bundle entity, tables and dao
......................................................................

engine, dao: Introduce ISCSI Bundle entity, tables and dao

ISCSI Bundle is the logical entity representing the group of networks
that is used for configuring iscsi multipathing.

Change-Id: I12313c02810a2f0e75016bdd78b44da43f2154d4
Bug-Url: https://bugzilla.redhat.com/753541
Signed-off-by: Sergey Gotliv <sgot...@redhat.com>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetIscsiBundlesByStoragePoolIdQuery.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IscsiBundle.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.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/IscsiBundleDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDaoDbFacadeImpl.java
M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
M packaging/dbscripts/create_tables.sql
A packaging/dbscripts/iscsi_bundles_sp.sql
A packaging/dbscripts/upgrade/03_04_0340_add_iscsi_bundle.sql
10 files changed, 370 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/22951/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetIscsiBundlesByStoragePoolIdQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetIscsiBundlesByStoragePoolIdQuery.java
new file mode 100644
index 0000000..9e7a38c
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetIscsiBundlesByStoragePoolIdQuery.java
@@ -0,0 +1,29 @@
+package org.ovirt.engine.core.bll.storage;
+
+import java.util.List;
+
+import org.ovirt.engine.core.bll.QueriesCommandBase;
+import org.ovirt.engine.core.common.businessentities.IscsiBundle;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.compat.Guid;
+
+public class GetIscsiBundlesByStoragePoolIdQuery <P extends IdQueryParameters> 
extends QueriesCommandBase<P> {
+
+    public GetIscsiBundlesByStoragePoolIdQuery(P parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected void executeQueryCommand() {
+        List<IscsiBundle> iscsiBundles = 
getDbFacade().getIscsiBundleDao().getAllByStoragePoolId(getParameters().getId());
+
+        for (IscsiBundle iscsiBundle : iscsiBundles) {
+            List<Guid> networkIds = 
getDbFacade().getIscsiBundleDao().getNetworkIdsByIscsiBundleId(iscsiBundle.getId());
+            if (networkIds != null) {
+                iscsiBundle.setNetworkIds(networkIds);
+            }
+        }
+
+        getQueryReturnValue().setReturnValue(iscsiBundles);
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IscsiBundle.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IscsiBundle.java
new file mode 100644
index 0000000..fbe8d4e
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IscsiBundle.java
@@ -0,0 +1,76 @@
+package org.ovirt.engine.core.common.businessentities;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class IscsiBundle extends IVdcQueryable implements 
BusinessEntity<Guid>, Nameable {
+
+    private static final long serialVersionUID = 6318808440502965971L;
+
+    private Guid id;
+    private Guid storagePoolId;
+    private String name;
+    private String description;
+    private List<Guid> networkIds;
+
+    public IscsiBundle() {
+        networkIds = new LinkedList<Guid>();
+    }
+
+    public IscsiBundle(Guid id, Guid storagePoolId, String name, String 
description) {
+        networkIds = new LinkedList<Guid>();
+        this.id = id;
+        this.storagePoolId = storagePoolId;
+        this.name = name;
+        this.description = description;
+    }
+
+    @Override
+    public Guid getId() {
+        return id;
+    }
+
+    @Override
+    public void setId(Guid id) {
+        this.id = id;
+    }
+
+    public Guid getStoragePoolId() {
+        return storagePoolId;
+    }
+
+    public void setStoragePoolId(Guid storagePoolId) {
+        this.storagePoolId = storagePoolId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public List<Guid> getNetworkIds() {
+        return networkIds;
+    }
+
+    public void setNetworkIds(List<Guid> networkIds) {
+        this.networkIds = networkIds;
+    }
+
+    @Override
+    public Object getQueryableId() {
+        return getId();
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
index 126838f..b7a7169 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java
@@ -220,6 +220,7 @@
     GetStorageDomainListById,
     GetLunsByVgId,
     GetPermittedStorageDomainsByStoragePoolId(VdcQueryAuthType.User),
+    GetIscsiBundlesByStoragePoolId,
 
     // Event Notification
     GetEventSubscribersBySubscriberIdGrouped,
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 3a0c04e..ebde2ae 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
@@ -64,6 +64,7 @@
 import org.ovirt.engine.core.dao.GenericDao;
 import org.ovirt.engine.core.dao.ImageDao;
 import org.ovirt.engine.core.dao.ImageStorageDomainMapDao;
+import org.ovirt.engine.core.dao.IscsiBundleDao;
 import org.ovirt.engine.core.dao.JobDao;
 import org.ovirt.engine.core.dao.JobSubjectEntityDao;
 import org.ovirt.engine.core.dao.LunDAO;
@@ -969,4 +970,8 @@
         }
         getCallsHandler().executeStoredProcAsBatch("insert_osinfo", 
executions);
     }
+
+    public IscsiBundleDao getIscsiBundleDao() {
+        return getDao(IscsiBundleDao.class);
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDao.java
new file mode 100644
index 0000000..afaf113
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDao.java
@@ -0,0 +1,23 @@
+package org.ovirt.engine.core.dao;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.IscsiBundle;
+import org.ovirt.engine.core.compat.Guid;
+
+public interface IscsiBundleDao extends DAO {
+
+    public IscsiBundle get(Guid id);
+
+    public void save(IscsiBundle iscsiBundle);
+
+    public void remove(Guid id);
+
+    public void update(IscsiBundle iscsiBundle);
+
+    public List<IscsiBundle> getAllByStoragePoolId(Guid storagePoolId);
+
+    public List<Guid> getNetworkIdsByIscsiBundleId(Guid iscsiBundleId);
+
+    public void addNetwork(Guid iscsiBundleId, Guid networkId);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDaoDbFacadeImpl.java
new file mode 100644
index 0000000..6f249b1
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBundleDaoDbFacadeImpl.java
@@ -0,0 +1,85 @@
+package org.ovirt.engine.core.dao;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.UUID;
+
+import org.ovirt.engine.core.common.businessentities.IscsiBundle;
+import org.ovirt.engine.core.compat.Guid;
+
+import org.springframework.jdbc.core.RowMapper;
+
+public class IscsiBundleDaoDbFacadeImpl extends BaseDAODbFacade implements 
IscsiBundleDao {
+
+    @Override
+    public IscsiBundle get(Guid id) {
+        return getCallsHandler().executeRead("GetIscsiBundleById",
+                IscsiBundleRowMapper.instance,
+                getCustomMapSqlParameterSource().addValue("id", id));
+    }
+
+    @Override
+    public void save(IscsiBundle iscsiBundle) {
+        getCallsHandler().executeModification("InsertIscsiBundle",
+                getCustomMapSqlParameterSource()
+                .addValue("id", iscsiBundle.getId())
+                .addValue("alias", iscsiBundle.getName())
+                .addValue("description", iscsiBundle.getDescription())
+                .addValue("storage_pool_id", iscsiBundle.getStoragePoolId()));
+    }
+
+    @Override
+    public void remove(Guid id) {
+        getCallsHandler().executeModification("DeleteIscsiBundle", 
getCustomMapSqlParameterSource().addValue("id", id));
+    }
+
+    @Override
+    public void update(IscsiBundle iscsiBundle) {
+        getCallsHandler().executeModification("UpdateIscsiBundles",
+                getCustomMapSqlParameterSource()
+                .addValue("id", iscsiBundle.getId())
+                .addValue("alias", iscsiBundle.getName())
+                .addValue("description", iscsiBundle.getDescription()));
+    }
+
+    @Override
+    public List<IscsiBundle> getAllByStoragePoolId(Guid storagePoolId) {
+        return 
getCallsHandler().executeReadList("GetIscsiBundlesByStoragePoolId",
+                IscsiBundleRowMapper.instance,
+                getCustomMapSqlParameterSource().addValue("storage_pool_id", 
storagePoolId));
+    }
+
+    @Override
+    public List<Guid> getNetworkIdsByIscsiBundleId(Guid iscsiBundleId) {
+        return getCallsHandler().executeReadList("GetNetworksByIscsiBundleId", 
new RowMapper<Guid>() {
+            @Override
+            public Guid mapRow(ResultSet rs, int index) throws SQLException {
+                return new Guid((UUID) rs.getObject(1));
+            }
+        }, getCustomMapSqlParameterSource().addValue("iscsi_bundle_id", 
iscsiBundleId));
+    }
+
+    @Override
+    public void addNetwork(Guid iscsiBundleId, Guid networkId) {
+        getCallsHandler().executeModification("InsertNetworkToIscsiBundle",
+                getCustomMapSqlParameterSource()
+                .addValue("iscsi_bundle_id", iscsiBundleId)
+                .addValue("network_id", networkId));
+    }
+
+    private static class IscsiBundleRowMapper implements 
RowMapper<IscsiBundle> {
+        public static final IscsiBundleRowMapper instance = new 
IscsiBundleRowMapper();
+
+        @Override
+        public IscsiBundle mapRow(ResultSet rs, int rowNum) throws 
SQLException {
+            IscsiBundle entity = new IscsiBundle();
+
+            entity.setId(getGuidDefaultNewGuid(rs, "id"));
+            entity.setDescription(rs.getString("description"));
+            entity.setName(rs.getString("alias"));
+            entity.setStoragePoolId(getGuidDefaultNewGuid(rs, 
"storage_pool_id"));
+            return entity;
+        }
+    }
+}
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 60ead40..c94c995 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
@@ -70,3 +70,4 @@
 PolicyUnitDao=org.ovirt.engine.core.dao.scheduling.PolicyUnitDaoImpl
 ClusterPolicyDao=org.ovirt.engine.core.dao.scheduling.ClusterPolicyDaoImpl
 
DwhHistoryTimekeepingDao=org.ovirt.engine.core.dao.dwh.DwhHistoryTimekeepingDaoDbFacadeImpl
+IscsiBundleDao=org.ovirt.engine.core.dao.IscsiBundleDaoDbFacadeImpl
\ No newline at end of file
diff --git a/packaging/dbscripts/create_tables.sql 
b/packaging/dbscripts/create_tables.sql
index e525e62..506938b 100644
--- a/packaging/dbscripts/create_tables.sql
+++ b/packaging/dbscripts/create_tables.sql
@@ -2335,6 +2335,36 @@
 ALTER TABLE ONLY vm_device
     ADD CONSTRAINT fk_vm_device_vm_static FOREIGN KEY (vm_id) REFERENCES 
vm_static(vm_guid) ON DELETE CASCADE;
 
+-- ----------------------------------------------------------------------
+-- iscsi_bundles table
+-- ----------------------------------------------------------------------
+CREATE TABLE iscsi_bundles
+(
+   id UUID NOT NULL,
+   alias varchar(30) NOT NULL,
+   description varchar(4000),
+   storage_pool_id UUID NOT NULL,
+   CONSTRAINT PK_iscsi_bundles PRIMARY KEY(id)
+) WITH OIDS;
+
+ALTER TABLE iscsi_bundles ADD  CONSTRAINT FK_iscsi_bundles_storage_pool 
FOREIGN KEY(storage_pool_id)
+REFERENCES storage_pool(id) ON DELETE CASCADE;
+
+-- ----------------------------------------------------------------------
+-- iscsi_bundles_networks_map table
+-- ----------------------------------------------------------------------
+CREATE TABLE iscsi_bundles_networks_map
+(
+   iscsi_bundle_id UUID NOT NULL,
+   network_id UUID NOT NULL,
+   CONSTRAINT PK_iscsi_bundles_networks_map PRIMARY 
KEY(iscsi_bundle_id,network_id)
+) WITH OIDS;
+
+ALTER TABLE iscsi_bundles_networks_map ADD CONSTRAINT 
FK_iscsi_bundles_networks_map_iscsi_bundle_id FOREIGN KEY(iscsi_bundle_id)
+REFERENCES iscsi_bundles(id) ON DELETE CASCADE;
+
+ALTER TABLE iscsi_bundles_networks_map ADD CONSTRAINT 
FK_iscsi_bundles_networks_map_network_id FOREIGN KEY(network_id)
+REFERENCES network(id) ON DELETE CASCADE;
 
 --
 -- Name: fk_vm_interface_statistics_vm_static; Type: FK CONSTRAINT; Schema: 
public; Owner: engine
diff --git a/packaging/dbscripts/iscsi_bundles_sp.sql 
b/packaging/dbscripts/iscsi_bundles_sp.sql
new file mode 100644
index 0000000..2e13968
--- /dev/null
+++ b/packaging/dbscripts/iscsi_bundles_sp.sql
@@ -0,0 +1,96 @@
+----------------------------------------------------------------
+-- [iscsi_bundles] Table
+--
+
+Create or replace FUNCTION GetIscsiBundleById(v_id UUID) RETURNS SETOF 
iscsi_bundles STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT iscsi_bundles.*
+      FROM iscsi_bundles
+      WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetIscsiBundlesByStoragePoolId(v_storage_pool_id 
UUID) RETURNS SETOF iscsi_bundles STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT iscsi_bundles.*
+      FROM iscsi_bundles
+      WHERE storage_pool_id = v_storage_pool_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetNetworksByIscsiBundleId(v_iscsi_bundle_id UUID) 
RETURNS SETOF UUID STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT iscsi_bundles_networks_map.network_id
+      FROM iscsi_bundles_networks_map
+      WHERE iscsi_bundle_id = v_iscsi_bundle_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION InsertIscsiBundle(v_id UUID,
+  v_alias varchar(30),
+  v_description VARCHAR(4000),
+  v_storage_pool_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+      INSERT INTO iscsi_bundles(id, alias, description, storage_pool_id)
+      VALUES(v_id, v_alias, v_description, v_storage_pool_id);
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION UpdateIscsiBundles(v_id UUID,
+  v_alias varchar(30),
+  v_description VARCHAR(4000))
+RETURNS VOID
+   AS $procedure$
+BEGIN
+      UPDATE iscsi_bundles
+      SET alias = v.alias, description = v_description
+      WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteIscsiBundle(v_id UUID)
+RETURNS VOID
+   AS $procedure$
+   DECLARE
+   v_val UUID;
+BEGIN
+                       -- Get (and keep) a shared lock with "right to upgrade 
to exclusive"
+                       -- in order to force locking parent before children
+      SELECT id INTO v_val FROM iscsi_bundles WHERE id = v_id FOR UPDATE;
+      DELETE FROM iscsi_bundles_networks_map WHERE iscsi_bundle_id = v_id;
+      DELETE FROM iscsi_bundles WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION InsertNetworkToIscsiBundle(v_iscsi_bundle_id UUID, 
v_network_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+      INSERT INTO iscsi_bundles_networks_map(iscsi_bundle_id, network_id)
+      VALUES(v_iscsi_bundle_id, v_network_id);
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION RemoveNetworkFromIscsiBundle(iscsi_bundle_id UUID, 
v_network_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+      DELETE FROM iscsi_bundles_networks_map
+      WHERE iscsi_bundle_id = v_iscsi_bundle_id and network_id = v_network_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
diff --git a/packaging/dbscripts/upgrade/03_04_0340_add_iscsi_bundle.sql 
b/packaging/dbscripts/upgrade/03_04_0340_add_iscsi_bundle.sql
new file mode 100644
index 0000000..492951c
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_04_0340_add_iscsi_bundle.sql
@@ -0,0 +1,24 @@
+CREATE TABLE iscsi_bundles
+(
+   id UUID NOT NULL,
+   alias varchar(30) NOT NULL,
+   description varchar(4000),
+   storage_pool_id UUID NOT NULL,
+   CONSTRAINT PK_iscsi_bundles PRIMARY KEY(id)
+) WITH OIDS;
+
+ALTER TABLE iscsi_bundles ADD  CONSTRAINT FK_iscsi_bundles_storage_pool 
FOREIGN KEY(storage_pool_id)
+REFERENCES storage_pool(id) ON DELETE CASCADE;
+
+CREATE TABLE iscsi_bundles_networks_map
+(
+   iscsi_bundle_id UUID NOT NULL,
+   network_id UUID NOT NULL,
+   CONSTRAINT PK_iscsi_bundles_networks_map PRIMARY 
KEY(iscsi_bundle_id,network_id)
+) WITH OIDS;
+
+ALTER TABLE iscsi_bundles_networks_map ADD CONSTRAINT 
FK_iscsi_bundles_networks_map_iscsi_bundle_id FOREIGN KEY(iscsi_bundle_id)
+REFERENCES iscsi_bundles(id) ON DELETE CASCADE;
+
+ALTER TABLE iscsi_bundles_networks_map ADD CONSTRAINT 
FK_iscsi_bundles_networks_map_network_id FOREIGN KEY(network_id)
+REFERENCES network(id) ON DELETE CASCADE;


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I12313c02810a2f0e75016bdd78b44da43f2154d4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Sergey Gotliv <sgot...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to