You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2015/05/15 18:16:16 UTC

ambari git commit: AMBARI-10412. Incorrect datatype of alert_current.latest_text in Oracle DDL and upgrade catalog.. (mpapirkovskyy)

Repository: ambari
Updated Branches:
  refs/heads/trunk 4ade1cd85 -> 21a74e9f8


AMBARI-10412. Incorrect datatype of alert_current.latest_text in Oracle DDL and upgrade catalog.. (mpapirkovskyy)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/21a74e9f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/21a74e9f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/21a74e9f

Branch: refs/heads/trunk
Commit: 21a74e9f890d75cfc8f5d294bceb600dc6bb46ac
Parents: 4ade1cd
Author: Myroslav Papirkovskyy <mp...@hortonworks.com>
Authored: Thu May 14 19:45:09 2015 +0300
Committer: Myroslav Papirkovskyy <mp...@hortonworks.com>
Committed: Fri May 15 19:14:03 2015 +0300

----------------------------------------------------------------------
 .../apache/ambari/server/orm/DBAccessor.java    | 30 ++++++++++++++------
 .../server/orm/entities/AlertCurrentEntity.java |  6 ++--
 .../orm/helpers/dbms/GenericDbmsHelper.java     |  6 ++--
 .../server/upgrade/UpgradeCatalog210.java       | 15 +++++++++-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  2 +-
 5 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/21a74e9f/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
index 2b01c72..2c9277a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
@@ -23,6 +23,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.List;
 
+import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
 import org.eclipse.persistence.sessions.DatabaseSession;
 
 /**
@@ -400,11 +401,12 @@ public interface DBAccessor {
   public class DBColumnInfo {
     private String name;
     private Class type;
-//    private DBColumnType type;
     private Integer length;
     private Object defaultValue;
     private boolean isNullable;
 
+    private FieldTypeDefinition dbType = null;
+
     public DBColumnInfo(String name, Class type, Integer length) {
       this(name, type, length, null, true);
     }
@@ -418,6 +420,18 @@ public interface DBAccessor {
       isNullable = nullable;
     }
 
+    public DBColumnInfo(String name, FieldTypeDefinition dbType, Integer length, Object defaultValue, boolean isNullable) {
+      this.name = name;
+      this.length = length;
+      this.isNullable = isNullable;
+      this.defaultValue = defaultValue;
+      this.dbType = dbType;
+    }
+
+    public DBColumnInfo(String name, FieldTypeDefinition dbType, Integer length) {
+      this(name, dbType, length, null, true);
+    }
+
     public String getName() {
       return name;
     }
@@ -458,14 +472,12 @@ public interface DBAccessor {
       isNullable = nullable;
     }
 
-    public enum DBColumnType {
-      VARCHAR,
-      CHAR,
-      INT,
-      LONG,
-      BOOL,
-      TIME,
-      BLOB
+    public FieldTypeDefinition getDbType() {
+      return dbType;
+    }
+
+    public void setDbType(FieldTypeDefinition dbType) {
+      this.dbType = dbType;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/21a74e9f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertCurrentEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertCurrentEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertCurrentEntity.java
index 26e0d00..66b2a83 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertCurrentEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertCurrentEntity.java
@@ -26,6 +26,7 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
@@ -75,7 +76,8 @@ public class AlertCurrentEntity {
   @Column(name = "original_timestamp", nullable = false)
   private Long originalTimestamp;
 
-  @Column(name = "latest_text", length = 4000)
+  @Lob
+  @Column(name = "latest_text")
   private String latestText = null;
 
   /**
@@ -250,4 +252,4 @@ public class AlertCurrentEntity {
     int result = null != alertId ? alertId.hashCode() : 0;
     return result;
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/21a74e9f/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
index 9816133..5783f44 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
@@ -90,9 +90,11 @@ public class GenericDbmsHelper implements DbmsHelper {
   }
 
   public StringBuilder writeColumnType(StringBuilder builder, DBAccessor.DBColumnInfo columnInfo) {
-    FieldTypeDefinition fieldType;
+    FieldTypeDefinition fieldType = columnInfo.getDbType();
 
-    fieldType = databasePlatform.getFieldTypeDefinition(columnInfo.getType());
+    if (fieldType == null) {
+      fieldType = databasePlatform.getFieldTypeDefinition(columnInfo.getType());
+    }
 
     if (fieldType == null) {
       throw new IllegalArgumentException("Unable to convert data type");

http://git-wip-us.apache.org/repos/asf/ambari/blob/21a74e9f/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
index c023ae1..b10d3a5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
@@ -41,6 +41,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.apache.commons.lang.StringUtils;
+import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -147,6 +148,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
    */
   @Override
   protected void executeDDLUpdates() throws AmbariException, SQLException {
+    executeDDLFixes();
     executeHostsDDLUpdates();
     executeWidgetDDLUpdates();
     executeStackDDLUpdates();
@@ -239,6 +241,17 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     cleanupStackUpdates();
   }
 
+  private void executeDDLFixes() throws AmbariException, SQLException {
+    //Fix latest_text column type to match for all DBMS
+    Configuration.DatabaseType databaseType = configuration.getDatabaseType();
+    if (Configuration.DatabaseType.MYSQL == databaseType) {
+      dbAccessor.alterColumn("alert_current", new DBColumnInfo("latest_text", new FieldTypeDefinition("TEXT"), null));
+    } else {
+      dbAccessor.alterColumn("alert_current", new DBColumnInfo("latest_text", Character[].class, null));
+    }
+
+  }
+
   /**
    * Execute all of the hosts DDL updates.
    *
@@ -513,7 +526,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     columns.add(new DBColumnInfo("layout_name", String.class,  255,   null, false));
     columns.add(new DBColumnInfo("section_name", String.class,  255,   null, false));
     columns.add(new DBColumnInfo("cluster_id", Long.class,  null,   null, false));
-    columns.add(new DBColumnInfo("scope", String.class,  255,   null, false));
+    columns.add(new DBColumnInfo("scope", String.class, 255, null, false));
     columns.add(new DBColumnInfo("user_name", String.class,  255,   null, false));
     columns.add(new DBColumnInfo("display_name", String.class,  255,   null, true));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/21a74e9f/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 5d79618..d092e76 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -781,7 +781,7 @@ CREATE TABLE alert_current (
   maintenance_state VARCHAR2(255) NOT NULL,
   original_timestamp NUMBER(19) NOT NULL,
   latest_timestamp NUMBER(19) NOT NULL,
-  latest_text VARCHAR2(4000),
+  latest_text CLOB,
   PRIMARY KEY (alert_id),
   FOREIGN KEY (definition_id) REFERENCES alert_definition(definition_id),
   FOREIGN KEY (history_id) REFERENCES alert_history(alert_id)