ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-502-PROXY-ERROR - Alert History Cannot Insert Into Oracle Database (jonathanhurley)
Date Fri, 05 Jun 2015 15:51:06 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a22f819d4 -> d65accdcf


AMBARI-502-PROXY-ERROR - Alert History Cannot Insert Into Oracle Database (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: d65accdcf859616d942754c87b12bec46ccd099b
Parents: a22f819
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Thu Jun 4 23:25:34 2015 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Fri Jun 5 10:49:17 2015 -0400

----------------------------------------------------------------------
 .../server/orm/entities/AlertHistoryEntity.java |   4 +-
 .../server/upgrade/UpgradeCatalog210.java       |  52 +++++----
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |   2 +-
 .../server/upgrade/UpgradeCatalog210Test.java   | 112 ++++++++++++++-----
 4 files changed, 116 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d65accdc/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
index 8423abe..9091398 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertHistoryEntity.java
@@ -25,6 +25,7 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
 import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
@@ -68,7 +69,8 @@ public class AlertHistoryEntity {
   @Column(name = "alert_state", nullable = false, length = 255)
   private AlertState alertState;
 
-  @Column(name = "alert_text", length = 32672)
+  @Lob
+  @Column(name = "alert_text")
   private String alertText;
 
   @Column(name = "alert_timestamp", nullable = false)

http://git-wip-us.apache.org/repos/asf/ambari/blob/d65accdc/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 d83940e..a7a8cee 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
@@ -18,12 +18,22 @@
 
 package org.apache.ambari.server.upgrade;
 
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.persist.Transactional;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaDelete;
+import javax.persistence.criteria.Root;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
@@ -50,20 +60,12 @@ import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaDelete;
-import javax.persistence.criteria.Root;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.persist.Transactional;
 
 
 /**
@@ -118,7 +120,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
 
   @Inject
   private OsFamily osFamily;
-  
+
   /**
    * {@inheritDoc}
    */
@@ -163,7 +165,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
    */
   @Override
   protected void executeDDLUpdates() throws AmbariException, SQLException {
-    executeDDLFixes();
+    executeAlertDDLUpdates();
     executeHostsDDLUpdates();
     executeWidgetDDLUpdates();
     executeStackDDLUpdates();
@@ -258,13 +260,15 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     cleanupStackUpdates();
   }
 
-  private void executeDDLFixes() throws AmbariException, SQLException {
+  private void executeAlertDDLUpdates() 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));
+      dbAccessor.alterColumn("alert_history", new DBColumnInfo("alert_text", new FieldTypeDefinition("TEXT"),
null));
     } else {
       dbAccessor.alterColumn("alert_current", new DBColumnInfo("latest_text", Character[].class,
null));
+      dbAccessor.alterColumn("alert_history", new DBColumnInfo("alert_text", Character[].class,
null));
     }
 
   }
@@ -1038,7 +1042,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     updateHiveConfigs();
     updateHdfsConfigs();
   }
-  
+
   protected void updateHdfsConfigs() throws AmbariException {
     /***
      * Append -Dorg.mortbay.jetty.Request.maxFormContentSize=-1 to HADOOP_NAMENODE_OPTS from
hadoop-env.sh

http://git-wip-us.apache.org/repos/asf/ambari/blob/d65accdc/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 fdd5ef8..93d6f6e 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -768,7 +768,7 @@ CREATE TABLE alert_history (
   alert_timestamp NUMBER(19) NOT NULL,
   alert_label VARCHAR2(1024),
   alert_state VARCHAR2(255) NOT NULL,
-  alert_text VARCHAR2(4000),
+  alert_text CLOB,
   PRIMARY KEY (alert_id),
   FOREIGN KEY (alert_definition_id) REFERENCES alert_definition(definition_id),
   FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id)

http://git-wip-us.apache.org/repos/asf/ambari/blob/d65accdc/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index e41ce0b..d8a2565 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -18,12 +18,29 @@
 
 package org.apache.ambari.server.upgrade;
 
-import com.google.inject.Binder;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-import com.google.inject.Provider;
-import com.google.inject.persist.PersistService;
+import static junit.framework.Assert.assertEquals;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -54,27 +71,13 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import javax.persistence.EntityManager;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import static junit.framework.Assert.assertEquals;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMockBuilder;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
+
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+import com.google.inject.persist.PersistService;
 
 /**
  * {@link org.apache.ambari.server.upgrade.UpgradeCatalog210} unit tests.
@@ -110,17 +113,18 @@ public class UpgradeCatalog210Test {
   @Test
   public void testExecuteDDLUpdates() throws Exception {
     final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
-    Connection connection = createNiceMock(Connection.class);
     Configuration configuration = createNiceMock(Configuration.class);
     ResultSet resultSet = createNiceMock(ResultSet.class);
     expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes();
 
     // Create DDL sections with their own capture groups
+    AlertSectionDDL alertSectionDDL = new AlertSectionDDL();
     HostSectionDDL hostSectionDDL = new HostSectionDDL();
     WidgetSectionDDL widgetSectionDDL = new WidgetSectionDDL();
     ViewSectionDDL viewSectionDDL = new ViewSectionDDL();
 
     // Execute any DDL schema changes
+    alertSectionDDL.execute(dbAccessor);
     hostSectionDDL.execute(dbAccessor);
     widgetSectionDDL.execute(dbAccessor);
     viewSectionDDL.execute(dbAccessor);
@@ -138,6 +142,7 @@ public class UpgradeCatalog210Test {
     verify(dbAccessor, configuration, resultSet);
 
     // Verify sections
+    alertSectionDDL.verify(dbAccessor);
     hostSectionDDL.verify(dbAccessor);
     widgetSectionDDL.verify(dbAccessor);
     viewSectionDDL.verify(dbAccessor);
@@ -537,4 +542,55 @@ public class UpgradeCatalog210Test {
       Assert.assertEquals("cluster_config", clusterConfigColumn.getName());
     }
   }
+
+  /**
+   * Verify view changes
+   */
+  class AlertSectionDDL implements SectionDDL {
+
+    HashMap<String, Capture<DBColumnInfo>> captures;
+
+    public AlertSectionDDL() {
+      captures = new HashMap<String, Capture<DBColumnInfo>>();
+
+      Capture<DBAccessor.DBColumnInfo> alertCurrentColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> alertHistoryColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+
+      captures.put("alert_current", alertCurrentColumnCapture);
+      captures.put("alert_history", alertHistoryColumnCapture);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void execute(DBAccessor dbAccessor) throws SQLException {
+      Capture<DBColumnInfo> alertCurrentColumnCapture = captures.get("alert_current");
+      Capture<DBColumnInfo> alertHistoryColumnCapture = captures.get("alert_history");
+
+      dbAccessor.alterColumn(eq("alert_current"), capture(alertCurrentColumnCapture));
+      dbAccessor.alterColumn(eq("alert_history"), capture(alertHistoryColumnCapture));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void verify(DBAccessor dbAccessor) throws SQLException {
+      verifyAlertCurrent(captures.get("alert_current"));
+      verifyAlertHistory(captures.get("alert_history"));
+    }
+
+    private void verifyAlertCurrent(Capture<DBAccessor.DBColumnInfo> alertCurrentColumnCapture)
{
+      DBColumnInfo latestTextColumn = alertCurrentColumnCapture.getValue();
+      Assert.assertEquals(Character[].class, latestTextColumn.getType());
+      Assert.assertEquals("latest_text", latestTextColumn.getName());
+    }
+
+    private void verifyAlertHistory(Capture<DBAccessor.DBColumnInfo> alertHistoryColumnCapture)
{
+      DBColumnInfo alertTextColumn = alertHistoryColumnCapture.getValue();
+      Assert.assertEquals(Character[].class, alertTextColumn.getType());
+      Assert.assertEquals("alert_text", alertTextColumn.getName());
+    }
+  }
 }


Mime
View raw message