Liran Zelkha has uploaded a new change for review.

Change subject: WIP: core: Make VDSStatic a JPA entity
......................................................................

WIP: core: Make VDSStatic a JPA entity

Make VDSStatic a JPA entity

Change-Id: I5d7aa140e20dcd9468ae1ed00af1df0cf3e8b9e6
Signed-off-by: lzel...@redhat.com <lzel...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsStaticDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsStaticDAOTest.java
M packaging/dbscripts/vds_sp.sql
5 files changed, 52 insertions(+), 251 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/36600/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
index 66dc484..51b1a71 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java
@@ -4,11 +4,19 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.persistence.Cacheable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.Table;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
+import org.hibernate.annotations.Type;
 import org.hibernate.validator.constraints.Range;
 import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.common.validation.annotation.HostnameOrIp;
@@ -17,6 +25,9 @@
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
 
+@Entity
+@Table(name = "vds_static")
+@Cacheable(true)
 public class VdsStatic implements BusinessEntity<Guid>, Commented {
 
     private static final long serialVersionUID = -1425566208615075937L;
@@ -24,23 +35,30 @@
     private static final int DEFAULT_SSH_PORT = 22;
     private static final String DEFAULT_SSH_USERNAME = "root";
 
+    @Id
+    @Column(name = "vds_id")
+    @Type(type = "org.ovirt.engine.core.dao.GuidMapper")
     private Guid id;
 
     @EditableField
     @Size(min = 1, max = BusinessEntitiesDefinitions.HOST_NAME_SIZE)
     @ValidNameWithDot(message = "VALIDATION_VDS_NAME_INVALID", groups = { 
CreateEntity.class, UpdateEntity.class })
+    @Column(name = "vds_name")
     private String name;
 
     @EditableField
+    @Column(name = "free_text_comment")
     private String comment;
 
     @EditableField
     @HostnameOrIp(message = "VALIDATION.VDS.CONSOLEADDRESSS.HOSTNAME_OR_IP",
             groups = { CreateEntity.class, UpdateEntity.class })
     @Size(max = BusinessEntitiesDefinitions.CONSOLE_ADDRESS_SIZE)
+    @Column(name = "console_address")
     private String consoleAddress;
 
     @Size(max = BusinessEntitiesDefinitions.HOST_UNIQUE_ID_SIZE)
+    @Column(name = "vds_unique_id")
     private String uniqueId;
 
     @EditableOnVdsStatus
@@ -48,46 +66,62 @@
             groups = { CreateEntity.class, UpdateEntity.class })
     @NotNull(groups = { CreateEntity.class, UpdateEntity.class })
     @Size(max = BusinessEntitiesDefinitions.HOST_HOSTNAME_SIZE)
+    @Column(name = "host_name")
     private String hostName;
 
     @EditableField
     @Range(min = BusinessEntitiesDefinitions.NETWORK_MIN_LEGAL_PORT,
             max = BusinessEntitiesDefinitions.NETWORK_MAX_LEGAL_PORT,
             message = "VALIDATION.VDS.PORT.RANGE")
+    @Column(name = "port")
     private int port;
 
     @EditableField
+    @Column(name = "protocol")
+    @Enumerated(EnumType.ORDINAL)
     private VdsProtocol protocol;
 
     @EditableOnVdsStatus
     @Range(min = BusinessEntitiesDefinitions.NETWORK_MIN_LEGAL_PORT,
             max = BusinessEntitiesDefinitions.NETWORK_MAX_LEGAL_PORT,
             message = "VALIDATION.VDS.SSH_PORT.RANGE")
+    @Column(name = "ssh_port")
     private int sshPort;
 
     @EditableField
     @Size(min = 1, max = BusinessEntitiesDefinitions.HOST_NAME_SIZE)
     @ValidNameWithDot(message = "VALIDATION_VDS_SSH_USERNAME_INVALID", groups 
= { CreateEntity.class,
             UpdateEntity.class })
+    @Column(name = "ssh_username")
     private String sshUsername;
 
+    // TODO: Change to actual vds group
     @EditableOnVdsStatus
+    @Column(name = "vds_group_id")
+    @Type(type = "org.ovirt.engine.core.dao.GuidMapper")
     private Guid vdsGroupId;
 
+    @Column(name = "server_ssl_enabled")
     private Boolean serverSslEnabled;
 
+    @Column(name = "vds_type")
+    @Enumerated(EnumType.ORDINAL)
     private VDSType vdsType;
 
+    @Column(name = "vds_strength")
     private Integer vdsStrength;
 
     @EditableField
+    @Column(name = "pm_enabled")
     private boolean pmEnabled;
 
     @EditableField
     @Size(max = BusinessEntitiesDefinitions.GENERAL_NAME_SIZE)
+    @Column(name = "pm_proxy_preferences")
     private String pmProxyPreferences;
 
     @EditableField
+    @Column(name = "pm_detect_kdump")
     private boolean pmKdumpDetection;
 
     /**
@@ -95,22 +129,29 @@
      * is not allowed to touch this host.
      */
     @EditableField
+    @Column(name = "disable_auto_pm")
     private boolean disablePowerManagementPolicy;
 
     @EditableField
-    private long otpValidity;
+    @Column(name = "otp_validity")
+    private Long otpValidity;
 
     @EditableField
     @Min(BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY)
     @Max(BusinessEntitiesDefinitions.HOST_MAX_SPM_PRIORITY)
+    @Column(name = "vds_spm_priority")
     private int vdsSpmPriority;
 
+    @Column(name = "recoverable")
     private boolean autoRecoverable;
 
     @EditableField
     @Size(max = BusinessEntitiesDefinitions.SSH_KEY_FINGERPRINT_SIZE)
+    @Column(name = "sshkeyfingerprint")
     private String sshKeyFingerprint;
 
+    @Column(name = "host_provider_id")
+    @Type(type = "org.ovirt.engine.core.dao.GuidMapper")
     private Guid hostProviderId;
 
     public boolean isAutoRecoverable() {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
index 6e86d7c..ea7d807 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDAODbFacadeImpl.java
@@ -39,7 +39,7 @@
  */
 @Named
 @Singleton
-public class VdsDAODbFacadeImpl extends BaseDAODbFacade implements VdsDAO {
+public class VdsDAODbFacadeImpl extends HibernateFacade<Guid, VDS> implements 
VdsDAO {
 
     @Override
     public VDS get(Guid id) {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsStaticDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsStaticDAODbFacadeImpl.java
index a1221be..7c1c15d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsStaticDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsStaticDAODbFacadeImpl.java
@@ -12,30 +12,18 @@
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import org.ovirt.engine.core.compat.Guid;
 import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.simple.SimpleJdbcCall;
 
 /**
  * <code>VdsDAODbFacadeImpl</code> provides an implementation of {@link 
VdsDAO} that uses previously written code from
  * {@code DbFacade}.
  */
 @Named
-public class VdsStaticDAODbFacadeImpl extends BaseDAODbFacade implements 
VdsStaticDAO {
-
-    @Override
-    public VdsStatic get(Guid id) {
-        return getCallsHandler().executeRead("GetVdsStaticByVdsId",
-                VdsStaticRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_id", id));
-    }
+public class VdsStaticDAODbFacadeImpl extends HibernateFacade<VdsStatic, Guid> 
implements VdsStaticDAO {
 
     @Override
     public VdsStatic getByHostName(String host) {
-        return getCallsHandler().executeRead("GetVdsStaticByHostName",
-                VdsStaticRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("host_name", host));
+        return super.singleResult(em.createQuery("select v from VdsStatic v 
where v.hostName = :hostName")
+                .setParameter("hostName", host));
     }
 
     @Override
@@ -48,61 +36,10 @@
 
     @Override
     public List<VdsStatic> getAllForVdsGroup(Guid vdsGroup) {
-        return getCallsHandler().executeReadList("GetVdsStaticByVdsGroupId",
-                VdsStaticRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("vds_group_id", vdsGroup));
+        return super.multiResults(em.createQuery("select v from VdsStatic v 
where v.vdsGroupId = :vdsGroupId")
+                .setParameter("vdsGroupId", vdsGroup));
     }
-
-    @Override
-    public void save(VdsStatic vds) {
-        Guid id = vds.getId();
-        if (Guid.isNullOrEmpty(id)) {
-            id = Guid.newGuid();
-            vds.setId(id);
-        }
-        new 
SimpleJdbcCall(jdbcTemplate).withProcedureName("InsertVdsStatic").execute(getInsertOrUpdateParams(vds));
-    }
-
-    @Override
-    public void update(VdsStatic vds) {
-        getCallsHandler().executeModification("UpdateVdsStatic", 
getInsertOrUpdateParams(vds));
-    }
-
-    private MapSqlParameterSource getInsertOrUpdateParams(final VdsStatic vds) 
{
-        return getCustomMapSqlParameterSource()
-                .addValue("host_name", vds.getHostName())
-                .addValue("free_text_comment", vds.getComment())
-                .addValue("vds_unique_id", vds.getUniqueID())
-                .addValue("port", vds.getPort())
-                .addValue("protocol", vds.getProtocol())
-                .addValue("vds_group_id", vds.getVdsGroupId())
-                .addValue("vds_id", vds.getId())
-                .addValue("vds_name", vds.getName())
-                .addValue("server_SSL_enabled", vds.isServerSslEnabled())
-                .addValue("vds_type", vds.getVdsType())
-                .addValue("vds_strength", vds.getVdsStrength())
-                .addValue("pm_enabled", vds.isPmEnabled())
-                .addValue("pm_proxy_preferences", vds.getPmProxyPreferences())
-                .addValue("pm_detect_kdump", vds.isPmKdumpDetection())
-                .addValue("otp_validity", vds.getOtpValidity())
-                .addValue("vds_spm_priority", vds.getVdsSpmPriority())
-                .addValue("console_address", vds.getConsoleAddress())
-                .addValue("sshKeyFingerprint", vds.getSshKeyFingerprint())
-                .addValue("ssh_port", vds.getSshPort())
-                .addValue("ssh_username", vds.getSshUsername())
-                .addValue("disable_auto_pm", 
vds.isDisablePowerManagementPolicy())
-                .addValue("host_provider_id", vds.getHostProviderId());
-    }
-
-    @Override
-    public void remove(Guid id) {
-        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
-                .addValue("vds_id", id);
-
-        getCallsHandler().executeModification("DeleteVdsStatic", 
parameterSource);
-    }
-
+    
     @Override
     public List<VdsStatic> getAll() {
         throw new NotImplementedException();
@@ -148,10 +85,7 @@
 
     @Override
     public VdsStatic getByVdsName(String vdsName) {
-        return getCallsHandler().executeRead("GetVdsStaticByVdsName",
-                VdsStaticRowMapper.instance,
-                getCustomMapSqlParameterSource()
-                        .addValue("host_name", vdsName));
+        return super.singleResult(em.createQuery("select v.name from VdsStatic 
v where v.name = :name")
+                .setParameter("name", vdsName));
     }
-
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsStaticDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsStaticDAOTest.java
index c8a7cc1..ba912ce 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsStaticDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsStaticDAOTest.java
@@ -15,7 +15,7 @@
 import org.ovirt.engine.core.compat.Guid;
 
 
-public class VdsStaticDAOTest extends BaseDAOTestCase {
+public class VdsStaticDAOTest extends BaseHibernateDAOTestCase {
     private VdsStaticDAO dao;
     private VdsDynamicDAO dynamicDao;
     private VdsStatisticsDAO statisticsDao;
diff --git a/packaging/dbscripts/vds_sp.sql b/packaging/dbscripts/vds_sp.sql
index 5aaf8ef..2706100 100644
--- a/packaging/dbscripts/vds_sp.sql
+++ b/packaging/dbscripts/vds_sp.sql
@@ -394,125 +394,6 @@
 ----------------------------------------------------------------
 -- [vds_static] Table
 --
-
-
-Create or replace FUNCTION InsertVdsStatic(
-    v_free_text_comment text,
-    v_vds_id UUID,
-    v_host_name VARCHAR(255),
-    v_vds_unique_id VARCHAR(128) ,
-    v_port INTEGER,
-    v_protocol SMALLINT,
-    v_vds_group_id UUID,
-    v_vds_name VARCHAR(255),
-    v_server_SSL_enabled BOOLEAN ,
-    v_vds_type INTEGER,
-    v_vds_strength INTEGER,
-    v_pm_enabled BOOLEAN,
-    v_pm_proxy_preferences VARCHAR(255),
-    v_pm_detect_kdump BOOLEAN,
-    v_vds_spm_priority INTEGER,
-    v_sshKeyFingerprint VARCHAR(128),
-    v_console_address VARCHAR(255),
-    v_ssh_port INTEGER,
-    v_ssh_username VARCHAR(255),
-    v_disable_auto_pm BOOLEAN,
-    v_host_provider_id UUID)
-RETURNS VOID
-
-   AS $procedure$
-BEGIN
-   IF v_vds_unique_id IS NULL OR NOT EXISTS(SELECT vds_name FROM vds_static 
WHERE vds_unique_id = v_vds_unique_id) then
-      BEGIN
-         INSERT INTO vds_static(vds_id,host_name, free_text_comment, 
vds_unique_id, port, protocol, vds_group_id, vds_name, server_SSL_enabled,
-                               vds_type,vds_strength,pm_enabled, 
pm_proxy_preferences, pm_detect_kdump, vds_spm_priority, sshKeyFingerprint, 
console_address, 
-                               ssh_port, ssh_username, disable_auto_pm, 
host_provider_id)
-                       VALUES(v_vds_id,v_host_name, v_free_text_comment, 
v_vds_unique_id, v_port, v_protocol, v_vds_group_id, v_vds_name, 
v_server_SSL_enabled,
-                               v_vds_type,v_vds_strength,v_pm_enabled, 
v_pm_proxy_preferences, v_pm_detect_kdump, v_vds_spm_priority, 
v_sshKeyFingerprint, 
-                               v_console_address, v_ssh_port, v_ssh_username, 
v_disable_auto_pm, v_host_provider_id);
-      END;
-   end if;
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-
-
-
-Create or replace FUNCTION UpdateVdsStatic(v_host_name VARCHAR(255),
-    v_free_text_comment text,
-    v_vds_unique_id VARCHAR(128),
-    v_port INTEGER,
-    v_protocol SMALLINT,
-    v_vds_group_id UUID,
-    v_vds_id UUID,
-    v_vds_name VARCHAR(255),
-    v_server_SSL_enabled BOOLEAN ,
-    v_vds_type INTEGER,
-    v_vds_strength INTEGER,
-    v_pm_enabled BOOLEAN,
-    v_pm_proxy_preferences VARCHAR(255),
-    v_pm_detect_kdump BOOLEAN,
-    v_otp_validity BIGINT,
-    v_vds_spm_priority INTEGER,
-    v_sshKeyFingerprint VARCHAR(128),
-    v_console_address VARCHAR(255),
-    v_ssh_port INTEGER,
-    v_ssh_username VARCHAR(255),
-    v_disable_auto_pm BOOLEAN,
-    v_host_provider_id UUID)
-RETURNS VOID
-
-       --The [vds_static] table doesn't have a timestamp column. Optimistic 
concurrency logic cannot be generated
-   AS $procedure$
-BEGIN
-
-   BEGIN
-      UPDATE vds_static
-      SET host_name = v_host_name, free_text_comment = 
v_free_text_comment,vds_unique_id = v_vds_unique_id,
-      port = v_port, protocol = v_protocol, vds_group_id = 
v_vds_group_id,vds_name = v_vds_name,server_SSL_enabled = v_server_SSL_enabled,
-      vds_type = v_vds_type, _update_date = LOCALTIMESTAMP,vds_strength = 
v_vds_strength,
-      pm_enabled = v_pm_enabled, pm_proxy_preferences = 
v_pm_proxy_preferences, pm_detect_kdump = v_pm_detect_kdump,
-      otp_validity = v_otp_validity, vds_spm_priority = v_vds_spm_priority, 
sshKeyFingerprint = v_sshKeyFingerprint, host_provider_id = v_host_provider_id,
-      console_address = v_console_address, ssh_port = v_ssh_port, ssh_username 
= v_ssh_username, disable_auto_pm = v_disable_auto_pm
-      WHERE vds_id = v_vds_id;
-   END;
-
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-
-
-
-Create or replace FUNCTION DeleteVdsStatic(v_vds_id UUID)
-RETURNS VOID
-   AS $procedure$
-BEGIN
-   BEGIN
-      UPDATE vm_static
-      SET dedicated_vm_for_vds = null,
-          migration_support = 0
-      WHERE dedicated_vm_for_vds = v_vds_id;
-      DELETE FROM tags_vds_map
-      WHERE vds_id = v_vds_id;
-   -- Delete all Vds Alerts from the database
-      PERFORM DeleteAuditLogAlertsByVdsID(v_vds_id);
-      DELETE FROM vds_static
-      WHERE vds_id = v_vds_id;
-       -- delete VDS permissions --
-      DELETE FROM permissions where object_id = v_vds_id;
-   END;
-
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-
-
 Create or replace FUNCTION GetAllFromVdsStatic() RETURNS SETOF vds_static 
STABLE
    AS $procedure$
 BEGIN
@@ -540,40 +421,6 @@
 LANGUAGE plpgsql;
 
 
-Create or replace FUNCTION GetVdsStaticByHostName(v_host_name VARCHAR(255)) 
RETURNS SETOF vds_static STABLE
-   AS $procedure$
-BEGIN
-RETURN QUERY SELECT vds_static.*
-   FROM vds_static
-   WHERE host_name = v_host_name;
-
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
-Create or replace FUNCTION GetVdsStaticByVdsId(v_vds_id UUID) RETURNS SETOF 
vds_static STABLE
-   AS $procedure$
-BEGIN
-RETURN QUERY SELECT vds_static.*
-   FROM vds_static
-   WHERE vds_id = v_vds_id;
-
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-Create or replace FUNCTION GetVdsStaticByVdsName(v_host_name VARCHAR(255)) 
RETURNS SETOF vds_static STABLE
-   AS $procedure$
-BEGIN
-RETURN QUERY SELECT vds_static.*
-   FROM vds_static
-   WHERE vds_name = v_host_name;
-
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
 Create or replace FUNCTION GetVdsByUniqueID(v_vds_unique_id VARCHAR(128)) 
RETURNS SETOF vds STABLE
    AS $procedure$
 BEGIN
@@ -586,27 +433,6 @@
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
-
-
-
-
-
-
-Create or replace FUNCTION GetVdsStaticByVdsGroupId(v_vds_group_id UUID) 
RETURNS SETOF vds_static STABLE
-   AS $procedure$
-BEGIN
-BEGIN
-      RETURN QUERY SELECT vds_static.*
-      FROM vds_static vds_static
-      WHERE vds_group_id = v_vds_group_id;
-   END;
-
-   RETURN;
-END; $procedure$
-LANGUAGE plpgsql;
-
-
-
 
 
---------------------------------------------------------------------------------------------------
 --    [vds] - view


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

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

Reply via email to