Ramesh N has uploaded a new change for review. Change subject: engine : Entity and DAO changes for Disk provisioning ......................................................................
engine : Entity and DAO changes for Disk provisioning Add new entity 'StorageDevice' and related DAO changes Change-Id: Ie95a12239429dd0c7f3282161221e8b8f639cee9 Signed-off-by: Ramesh Nachimuthu <[email protected]> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/StorageDevice.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/gluster/StorageDeviceDao.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties A packaging/dbscripts/storage_device_sp.sql A packaging/dbscripts/upgrade/03_06_0590_storage_device_tables.sql 7 files changed, 572 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/36428/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/StorageDevice.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/StorageDevice.java new file mode 100644 index 0000000..1e31796 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/StorageDevice.java @@ -0,0 +1,226 @@ +package org.ovirt.engine.core.common.businessentities.gluster; + +import org.ovirt.engine.core.common.businessentities.BusinessEntity; +import org.ovirt.engine.core.common.businessentities.IVdcQueryable; +import org.ovirt.engine.core.compat.Guid; + +public class StorageDevice extends IVdcQueryable implements BusinessEntity<Guid> { + + private static final long serialVersionUID = 1L; + + private Guid id; + private String name; + private String devUuid; + private String fsUuid; + private Guid vdsId; + private String description; + private String devType; + private String devPath; + private String fsType; + private String mountPoint; + private Long size; + private Boolean canCreateBrick; + + public StorageDevice() { + super(); + } + + public static long getSerialversionuid() { + return serialVersionUID; + } + + public String getName() { + return name; + } + + public String getDevPath() { + return devPath; + } + + public String getDevUuid() { + return devUuid; + } + + public String getFsUuid() { + return fsUuid; + } + + public Boolean getCanCreateBrick() { + return canCreateBrick; + } + + public String getFsType() { + return fsType; + } + + public String getMountPoint() { + return mountPoint; + } + + public Long getSize() { + return size; + } + + public void setName(String name) { + this.name = name; + } + + public void setDevPath(String devPath) { + this.devPath = devPath; + } + + public void setDevUuid(String devUuid) { + this.devUuid = devUuid; + } + + public void setFsUuid(String uuid) { + this.fsUuid = uuid; + } + + public void setCanCreateBrick(Boolean canCreateBrick) { + this.canCreateBrick = canCreateBrick; + } + + public void setFsType(String fsType) { + this.fsType = fsType; + } + + public void setMountPoint(String mountPoint) { + this.mountPoint = mountPoint; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getDescription() { + return description; + } + + public void setDescription(String model) { + this.description = model; + } + + @Override + public Object getQueryableId() { + return this.getId(); + } + + @Override + public Guid getId() { + return this.id; + } + + @Override + public void setId(Guid id) { + this.id = id; + } + + public Guid getVdsId() { + return vdsId; + } + + public void setVdsId(Guid vdsId) { + this.vdsId = vdsId; + } + + public String getDevType() { + return devType; + } + + public void setDevType(String devType) { + this.devType = devType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((canCreateBrick == null) ? 0 : canCreateBrick.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((devPath == null) ? 0 : devPath.hashCode()); + result = prime * result + ((devType == null) ? 0 : devType.hashCode()); + result = prime * result + ((devUuid == null) ? 0 : devUuid.hashCode()); + result = prime * result + ((fsType == null) ? 0 : fsType.hashCode()); + result = prime * result + ((fsUuid == null) ? 0 : fsUuid.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((mountPoint == null) ? 0 : mountPoint.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((size == null) ? 0 : size.hashCode()); + result = prime * result + ((vdsId == null) ? 0 : vdsId.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; + StorageDevice other = (StorageDevice) obj; + if (canCreateBrick == null) { + if (other.canCreateBrick != null) + return false; + } else if (!canCreateBrick.equals(other.canCreateBrick)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (devPath == null) { + if (other.devPath != null) + return false; + } else if (!devPath.equals(other.devPath)) + return false; + if (devType == null) { + if (other.devType != null) + return false; + } else if (!devType.equals(other.devType)) + return false; + if (devUuid == null) { + if (other.devUuid != null) + return false; + } else if (!devUuid.equals(other.devUuid)) + return false; + if (fsType == null) { + if (other.fsType != null) + return false; + } else if (!fsType.equals(other.fsType)) + return false; + if (fsUuid == null) { + if (other.fsUuid != null) + return false; + } else if (!fsUuid.equals(other.fsUuid)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (mountPoint == null) { + if (other.mountPoint != null) + return false; + } else if (!mountPoint.equals(other.mountPoint)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (size == null) { + if (other.size != null) + return false; + } else if (!size.equals(other.size)) + return false; + if (vdsId == null) { + if (other.vdsId != null) + return false; + } else if (!vdsId.equals(other.vdsId)) + return false; + return true; + } + +} 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 e77f46f..707c943 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 @@ -131,6 +131,7 @@ import org.ovirt.engine.core.dao.gluster.GlusterServerServiceDao; import org.ovirt.engine.core.dao.gluster.GlusterServiceDao; import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao; +import org.ovirt.engine.core.dao.gluster.StorageDeviceDao; import org.ovirt.engine.core.dao.network.HostNetworkQosDao; import org.ovirt.engine.core.dao.network.InterfaceDao; import org.ovirt.engine.core.dao.network.NetworkClusterDao; @@ -951,6 +952,15 @@ } /** + * Returns the singleton instance of {@link StorageDeviceDao}. + * + * @return the dao + */ + public StorageDeviceDao getStorageDeviceDao() { + return getDao(StorageDeviceDao.class); + } + + /** * Returns the singleton instance of {@link GlusterServerDao}. * * @return the dao diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDao.java new file mode 100644 index 0000000..96c1e00 --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDao.java @@ -0,0 +1,32 @@ +package org.ovirt.engine.core.dao.gluster; + +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.gluster.StorageDevice; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.DAO; + +/** + * Interface for DB operations on Storage Device Entities + */ +public interface StorageDeviceDao extends DAO { + + public StorageDevice getById(Guid id); + + public StorageDevice getByName(Guid vds_id, String name); + + public StorageDevice getByDeviceUuid(Guid vds_id, String deviceUuid); + + public void save(StorageDevice storageDevice); + + public List<StorageDevice> getStorageDevicesInHost(Guid hostId); + + public void remove(Guid id); + + public void removeByName(Guid vds_id, String name); + + public void removeByDeviceUuid(Guid vds_id, String deviceUuid); + + public void updateStorageDevice(StorageDevice storageDevice); + + } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDaoDbFacadeImpl.java new file mode 100644 index 0000000..259d0cf --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/StorageDeviceDaoDbFacadeImpl.java @@ -0,0 +1,145 @@ +package org.ovirt.engine.core.dao.gluster; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.gluster.StorageDevice; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; + +/** + * Implementation of the DB Facade for Storage Device. + */ +public class StorageDeviceDaoDbFacadeImpl extends MassOperationsGenericDaoDbFacade<StorageDevice, Guid> implements + StorageDeviceDao { + + private static final RowMapper<StorageDevice> storageDeviceRowMapper = new StorageDeviceRowMapper(); + + private static final class StorageDeviceRowMapper implements RowMapper<StorageDevice> { + @Override + public StorageDevice mapRow(ResultSet rs, int rowNum) + throws SQLException { + StorageDevice entity = new StorageDevice(); + entity.setId(getGuidDefaultEmpty(rs, "id")); + entity.setName(rs.getString("name")); + entity.setDevUuid(rs.getString("device_uuid")); + entity.setFsUuid(rs.getString("filesystem_uuid")); + entity.setVdsId(getGuidDefaultEmpty(rs, "vds_id")); + entity.setDescription(rs.getString("description")); + entity.setDevType(rs.getString("device_type")); + entity.setDevPath(rs.getString("device_path")); + entity.setFsType(rs.getString("filesystem_type")); + entity.setMountPoint(rs.getString("mount_point")); + entity.setSize(rs.getLong("size")); + entity.setCanCreateBrick(rs.getBoolean("is_free")); + return entity; + } + } + + public StorageDeviceDaoDbFacadeImpl() { + super("StorageDevice"); + setProcedureNameForGet("GetStorageDeviceById"); + } + + @Override + public StorageDevice getById(Guid id) { + return getCallsHandler().executeRead("GetStorageDeviceById", storageDeviceRowMapper, + createIdParameterMapper(id)); + } + + @Override + public StorageDevice getByName(Guid vds_id, String name) { + return getCallsHandler().executeRead( + "GetStorageDeviceByName", storageDeviceRowMapper, + getCustomMapSqlParameterSource() + .addValue("vds_id", vds_id) + .addValue("name", name)); + } + + @Override + public StorageDevice getByDeviceUuid(Guid vds_id, String deviceUuid) { + return getCallsHandler().executeRead( + "GetStorageDeviceByDeviceUuid", storageDeviceRowMapper, + getCustomMapSqlParameterSource() + .addValue("vds_id", vds_id) + .addValue("device_uuid", deviceUuid)); + } + + @Override + public List<StorageDevice> getStorageDevicesInHost(Guid hostId) { + return getCallsHandler().executeReadList("GetStorageDevicesByVdsId", + storageDeviceRowMapper, + getCustomMapSqlParameterSource().addValue("vds_id", hostId)); + } + + @Override + protected MapSqlParameterSource createFullParametersMapper(StorageDevice entity) { + return getCustomMapSqlParameterSource() + .addValue("id", entity.getId()) + .addValue("name", entity.getName()) + .addValue("device_uuid", entity.getDevUuid()) + .addValue("filesystem_uuid", entity.getFsUuid()) + .addValue("vds_id", entity.getVdsId()) + .addValue("description", entity.getDescription()) + .addValue("device_type", entity.getDevType()) + .addValue("device_path", entity.getDevPath()) + .addValue("filesystem_type", entity.getFsType()) + .addValue("mount_point", entity.getMountPoint()) + .addValue("size", entity.getSize()) + .addValue("is_free", entity.getCanCreateBrick()); + } + + @Override + protected MapSqlParameterSource createIdParameterMapper(Guid id) { + return getCustomMapSqlParameterSource().addValue("id", id); + } + + @Override + protected RowMapper<StorageDevice> createEntityRowMapper() { + return storageDeviceRowMapper; + } + + @Override + public void remove(Guid id) { + getCallsHandler().executeModification("DeleteStorageDeviceById", + createIdParameterMapper(id)); + } + + @Override + public void removeByName(Guid vds_id, String name) { + getCallsHandler().executeModification("DeleteStorageDeviceByName", + getCustomMapSqlParameterSource() + .addValue("vds_id", vds_id) + .addValue("name", name)); + } + + @Override + public void removeByDeviceUuid(Guid vds_id, String deviceUuid) { + getCallsHandler().executeModification("DeleteStorageDeviceByDeviceUuid", + getCustomMapSqlParameterSource() + .addValue("vds_id", vds_id) + .addValue("device_uuid", deviceUuid)); + + } + + @Override + public void updateStorageDevice(StorageDevice storageDevice) { + getCallsHandler().executeModification("UpdateStorageDevice", + getCustomMapSqlParameterSource() + .addValue("id", storageDevice.getId()) + .addValue("name", storageDevice.getName()) + .addValue("device_uuid", storageDevice.getDevUuid()) + .addValue("filesystem_uuid", storageDevice.getFsUuid()) + .addValue("description", storageDevice.getDescription()) + .addValue("device_type", storageDevice.getDevType()) + .addValue("device_path", storageDevice.getDevPath()) + .addValue("filesystem_type", storageDevice.getFsType()) + .addValue("mount_point", storageDevice.getMountPoint()) + .addValue("size", storageDevice.getSize()) + .addValue("is_free", storageDevice.getCanCreateBrick())); + + } +} 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 670f1a3..2316d9d 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 @@ -90,3 +90,4 @@ VdsKdumpStatusDao=org.ovirt.engine.core.dao.VdsKdumpStatusDaoDbFacadeImpl DiskProfileDao=org.ovirt.engine.core.dao.profiles.DiskProfileDaoDbFacadeImpl CpuProfileDao=org.ovirt.engine.core.dao.profiles.CpuProfileDaoDbFacadeImpl +StorageDeviceDao=org.ovirt.engine.core.dao.gluster.StorageDeviceDaoDbFacadeImpl diff --git a/packaging/dbscripts/storage_device_sp.sql b/packaging/dbscripts/storage_device_sp.sql new file mode 100644 index 0000000..dd70e10 --- /dev/null +++ b/packaging/dbscripts/storage_device_sp.sql @@ -0,0 +1,138 @@ +/* ---------------------------------------------------------------- + Stored procedures for database operations on Storage Device + related table: storage_device +----------------------------------------------------------------*/ + +Create or replace FUNCTION InsertStorageDevice(v_id UUID, + v_name VARCHAR(1000), + v_device_uuid VARCHAR(38), + v_filesystem_uuid VARCHAR(38), + v_vds_id UUID, + v_description VARCHAR(2000), + v_device_type VARCHAR(50), + v_device_path VARCHAR(4096), + v_filesystem_type VARCHAR(50), + v_mount_point VARCHAR(4096), + v_size BIGINT, + v_is_free BOOLEAN) +RETURNS VOID +AS $procedure$ +BEGIN + INSERT INTO storage_device(id, name, device_uuid, filesystem_uuid, vds_id, + description, device_type, device_path, filesystem_type, mount_point, size, is_free) + VALUES (v_id, v_name, v_device_uuid, v_filesystem_uuid, v_vds_id, v_description, v_device_type, + v_device_path, v_filesystem_type, v_mount_point, v_size, v_is_free); +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION UpdateStorageDevice(v_id UUID, + v_name VARCHAR(1000), + v_device_uuid VARCHAR(38), + v_filesystem_uuid VARCHAR(38), + v_description VARCHAR(2000), + v_device_type VARCHAR(50), + v_device_path VARCHAR(4096), + v_filesystem_type VARCHAR(50), + v_mount_point VARCHAR(4096), + v_size BIGINT, + v_is_free BOOLEAN) +RETURNS VOID +AS $procedure$ +BEGIN + UPDATE storage_device + SET name = v_name, + device_uuid = v_device_uuid, + filesystem_uuid = v_filesystem_uuid, + description = v_description, + device_type = v_device_type, + device_path = v_device_path, + filesystem_type = v_filesystem_type, + mount_point = v_mount_point, + size = v_size, + is_free = v_is_free, + _update_date = LOCALTIMESTAMP + WHERE id = v_id; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION GetStorageDeviceById(v_id UUID) +RETURNS SETOF storage_device STABLE +AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM storage_device + WHERE id = v_id; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION GetStorageDeviceByName(v_vds_id UUID, + v_name VARCHAR(1000)) +RETURNS SETOF storage_device STABLE +AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM storage_device + WHERE vds_id = v_vds_id and name = v_name; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION GetStorageDeviceByDeviceUuid(v_vds_id UUID, + v_device_uuid VARCHAR(38)) +RETURNS SETOF storage_device STABLE +AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM storage_device + WHERE vds_id = v_vds_id and device_uuid = v_device_uuid; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION GetStorageDevicesByVdsId(v_vds_id UUID) +RETURNS SETOF storage_device STABLE +AS $procedure$ +BEGIN + RETURN QUERY SELECT * + FROM storage_device + WHERE vds_id = v_vds_id; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION DeleteStorageDeviceById(v_id UUID) + RETURNS VOID + AS $procedure$ +BEGIN + DELETE FROM storage_device + WHERE id = v_id; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION DeleteStorageDeviceByIds(v_ids VARCHAR(5000)) + RETURNS VOID + AS $procedure$ +BEGIN + DELETE FROM storage_device + WHERE id in (select * from fnSplitterUuid(v_ids)); +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION DeleteStorageDeviceByName(v_vds_id UUID, + v_name VARCHAR(1000)) + RETURNS VOID + AS $procedure$ +BEGIN + DELETE FROM storage_device + WHERE vds_id = v_vds_id + AND name = v_name; +END; $procedure$ +LANGUAGE plpgsql; + +Create or replace FUNCTION DeleteStorageDeviceByDeviceUuid(v_vds_id UUID, + v_device_uuid VARCHAR(38)) + RETURNS VOID + AS $procedure$ +BEGIN + DELETE FROM storage_device + WHERE vds_id = v_vds_id + AND device_uuid = v_device_uuid; +END; $procedure$ +LANGUAGE plpgsql; diff --git a/packaging/dbscripts/upgrade/03_06_0590_storage_device_tables.sql b/packaging/dbscripts/upgrade/03_06_0590_storage_device_tables.sql new file mode 100644 index 0000000..83650c4 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_06_0590_storage_device_tables.sql @@ -0,0 +1,20 @@ +-- Add storage_device table +CREATE TABLE storage_device +( + id UUID NOT NULL, + name VARCHAR(1000) NOT NULL, + device_uuid VARCHAR(38) NOT NULL, + filesystem_uuid VARCHAR(38), + vds_id UUID NOT NULL, + description VARCHAR(2000), + device_type VARCHAR(50), + device_path VARCHAR(4096), + filesystem_type VARCHAR(50), + mount_point VARCHAR(4096), + size BIGINT, + is_free BOOLEAN, + _create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP, + _update_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP, + CONSTRAINT pk_storage_device PRIMARY KEY(id), + FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE +) WITH OIDS; -- To view, visit http://gerrit.ovirt.org/36428 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie95a12239429dd0c7f3282161221e8b8f639cee9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ramesh N <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
