ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-8330 - API: null value in request results in null string value on resource (tbeerbower)
Date Fri, 14 Nov 2014 15:29:54 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk feab062b8 -> 99a24d8c3


AMBARI-8330 - API: null value in request results in null string value on resource (tbeerbower)


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

Branch: refs/heads/trunk
Commit: 99a24d8c32ad0cc2b8df650b536f1a153c7b97fc
Parents: feab062
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Fri Nov 14 10:29:26 2014 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Fri Nov 14 10:29:39 2014 -0500

----------------------------------------------------------------------
 .../services/parsers/JsonRequestBodyParser.java |  8 ++--
 .../server/upgrade/UpgradeCatalog200.java       |  4 ++
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  4 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  4 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  4 +-
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  4 +-
 .../parsers/JsonRequestBodyParserTest.java      |  4 +-
 .../server/upgrade/UpgradeCatalog200Test.java   | 45 ++++++++++++++++++++
 8 files changed, 64 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
index bbe7647..5e6df6b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
@@ -150,16 +150,18 @@ public class JsonRequestBodyParser implements RequestBodyParser {
         }
       } else {
         // field
+        String value = child.isNull() ? null : child.asText();
+
         if (path.equals(REQUEST_INFO_PATH)) {
            requestInfoProps.put(PropertyHelper.getPropertyId(null, name),
-                   child.asText());
+               value);
         } else if (path.startsWith(REQUEST_INFO_PATH)) {
           requestInfoProps.put(PropertyHelper.getPropertyId(
               path.substring(REQUEST_INFO_PATH.length() + SLASH.length()), name),
-                  child.asText());
+              value);
         } else {
           propertySet.getProperties().put(PropertyHelper.getPropertyId(
-              path.equals(BODY_TITLE) ? "" : path, name), child.asText());
+              path.equals(BODY_TITLE) ? "" : path, name), value);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
index 8250e83..45e7813 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
@@ -90,6 +90,10 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog {
     dbAccessor.addColumn(ALERT_TABLE_DEFINITION, new DBColumnInfo(
         "ignore_host", Short.class, 1, 0, false));
 
+    // Alter column : make viewinstanceproperty.value & viewinstancedata.value nullable
+    dbAccessor.alterColumn("viewinstanceproperty", new DBColumnInfo("value", String.class,
2000, null, true));
+    dbAccessor.alterColumn("viewinstancedata", new DBColumnInfo("value", String.class, 2000,
null, true));
+
     ddlUpdateRepositoryVersion();
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index ca86e20..b2d9221 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -417,7 +417,7 @@ CREATE TABLE viewinstancedata (
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
   user_name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(VIEW_INSTANCE_ID, NAME, USER_NAME));
 
 CREATE TABLE viewinstance (
@@ -437,7 +437,7 @@ CREATE TABLE viewinstanceproperty (
   view_name VARCHAR(255) NOT NULL,
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_name, view_instance_name, name));
 
 CREATE TABLE viewparameter (

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/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 0c99cd2..50f02b8 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -408,7 +408,7 @@ CREATE TABLE viewinstancedata (
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
   user_name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_instance_id, name, user_name));
 
 CREATE TABLE viewinstance (
@@ -428,7 +428,7 @@ CREATE TABLE viewinstanceproperty (
   view_name VARCHAR(255) NOT NULL,
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_name, view_instance_name, name));
 
 CREATE TABLE viewparameter (

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 4c5b89d..d865161 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -408,7 +408,7 @@ CREATE TABLE viewinstancedata (
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
   user_name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_instance_id, name, user_name));
 
 CREATE TABLE viewinstance (
@@ -428,7 +428,7 @@ CREATE TABLE viewinstanceproperty (
   view_name VARCHAR(255) NOT NULL,
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_name, view_instance_name, name));
 
 CREATE TABLE viewparameter (

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 7aa7cab..2e110ce 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -464,7 +464,7 @@ CREATE TABLE ambari.viewinstancedata (
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
   user_name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_instance_id, name, user_name));
 
 CREATE TABLE ambari.viewinstance (
@@ -484,7 +484,7 @@ CREATE TABLE ambari.viewinstanceproperty (
   view_name VARCHAR(255) NOT NULL,
   view_instance_name VARCHAR(255) NOT NULL,
   name VARCHAR(255) NOT NULL,
-  value VARCHAR(2000) NOT NULL,
+  value VARCHAR(2000),
   PRIMARY KEY(view_name, view_instance_name, name));
 
 CREATE TABLE ambari.viewparameter (

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParserTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParserTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParserTest.java
index 1c28452..8b78524 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParserTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParserTest.java
@@ -62,7 +62,7 @@ public class JsonRequestBodyParserTest {
       "{" +
       "\"Clusters\" : {\n" +
       "    \"cluster_name\" : \"unitTestCluster3\"," +
-      "    \"Category\" : { \"property2\" : \"prop2Value\"}" +
+      "    \"Category\" : { \"property2\" : null}" +
       "} } ]";
 
   String arrayJson2 = "{" +
@@ -243,7 +243,7 @@ public class JsonRequestBodyParserTest {
 
     Map<String, String> mapCluster3 = new HashMap<String, String>();
     mapCluster3.put(PropertyHelper.getPropertyId("Clusters", "cluster_name"), "unitTestCluster3");
-    mapCluster3.put(PropertyHelper.getPropertyId("Clusters/Category", "property2"), "prop2Value");
+    mapCluster3.put(PropertyHelper.getPropertyId("Clusters/Category", "property2"), null);
 
 
     for (NamedPropertySet propertySet : setProps) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/99a24d8c/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
index f9f2708..6a5bab7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
@@ -18,10 +18,13 @@
 
 package org.apache.ambari.server.upgrade;
 
+import java.sql.SQLException;
 import java.util.List;
 
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.createStrictMock;
@@ -89,6 +92,8 @@ public class UpgradeCatalog200Test {
     Capture<DBAccessor.DBColumnInfo> hostComponentStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
     Capture<List<DBAccessor.DBColumnInfo>> clusterVersionCapture = new Capture<List<DBAccessor.DBColumnInfo>>();
     Capture<List<DBAccessor.DBColumnInfo>> hostVersionCapture = new Capture<List<DBAccessor.DBColumnInfo>>();
+    Capture<DBAccessor.DBColumnInfo> valueColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+    Capture<DBAccessor.DBColumnInfo> dataValueColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
 
     // Alert Definition
     dbAccessor.addColumn(eq("alert_definition"),
@@ -106,6 +111,9 @@ public class UpgradeCatalog200Test {
     dbAccessor.createTable(eq("host_version"),
         capture(hostVersionCapture), eq("id"));
 
+    setViewInstancePropertyExpectations(dbAccessor, valueColumnCapture);
+    setViewInstanceDataExpectations(dbAccessor, dataValueColumnCapture);
+
     replay(dbAccessor, configuration, resultSet);
 
     AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
@@ -131,6 +139,9 @@ public class UpgradeCatalog200Test {
     // Verify capture group sizes
     assertEquals(8, clusterVersionCapture.getValue().size());
     assertEquals(5, hostVersionCapture.getValue().size());
+
+    assertViewInstancePropertyColumns(valueColumnCapture);
+    assertViewInstanceDataColumns(dataValueColumnCapture);
   }
 
   @Test
@@ -181,4 +192,38 @@ public class UpgradeCatalog200Test {
 
     Assert.assertEquals("2.0.0", upgradeCatalog.getTargetVersion());
   }
+
+  private void setViewInstancePropertyExpectations(DBAccessor dbAccessor,
+                                                   Capture<DBAccessor.DBColumnInfo>
valueColumnCapture)
+      throws SQLException {
+
+    dbAccessor.alterColumn(eq("viewinstanceproperty"), capture(valueColumnCapture));
+  }
+
+  private void setViewInstanceDataExpectations(DBAccessor dbAccessor,
+                                               Capture<DBAccessor.DBColumnInfo> dataValueColumnCapture)
+      throws SQLException {
+
+    dbAccessor.alterColumn(eq("viewinstancedata"), capture(dataValueColumnCapture));
+  }
+
+  private void assertViewInstancePropertyColumns(
+      Capture<DBAccessor.DBColumnInfo> valueColumnCapture) {
+    DBAccessor.DBColumnInfo column = valueColumnCapture.getValue();
+    assertEquals("value", column.getName());
+    assertEquals(2000, (int) column.getLength());
+    assertEquals(String.class, column.getType());
+    assertNull(column.getDefaultValue());
+    assertTrue(column.isNullable());
+  }
+
+  private void assertViewInstanceDataColumns(
+      Capture<DBAccessor.DBColumnInfo> dataValueColumnCapture) {
+    DBAccessor.DBColumnInfo column = dataValueColumnCapture.getValue();
+    assertEquals("value", column.getName());
+    assertEquals(2000, (int) column.getLength());
+    assertEquals(String.class, column.getType());
+    assertNull(column.getDefaultValue());
+    assertTrue(column.isNullable());
+  }
 }


Mime
View raw message