ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject ambari git commit: AMBARI-20358. NPE during Ambari server schema upgrade while updating hbase_master_cpu alert definition (rlevas)
Date Wed, 08 Mar 2017 12:50:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 934f3f182 -> 8eaaf8086


AMBARI-20358. NPE during Ambari server schema upgrade while updating hbase_master_cpu alert
definition (rlevas)


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

Branch: refs/heads/branch-2.5
Commit: 8eaaf8086502890ef5d1c3ad88ca5fee8311f599
Parents: 934f3f1
Author: Robert Levas <rlevas@hortonworks.com>
Authored: Wed Mar 8 07:50:13 2017 -0500
Committer: Robert Levas <rlevas@hortonworks.com>
Committed: Wed Mar 8 07:50:13 2017 -0500

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog250.java       | 64 +++++++++++---------
 .../server/upgrade/UpgradeCatalog250Test.java   | 33 ++++++++++
 2 files changed, 70 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8eaaf808/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
index e244925..36160ca 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
@@ -216,36 +216,46 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog {
 
         if(source != null) {
           JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject();
-          LOG.debug("Source before update : {}", sourceJson);
-
-          JsonObject uriJson = sourceJson.get("uri").getAsJsonObject();
-          JsonPrimitive primitive;
-
-          // Replace
-          //  "kerberos_keytab": "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}"
-          // With
-          //  "kerberos_keytab": "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}"
-          primitive = uriJson.getAsJsonPrimitive("kerberos_keytab");
-          if(primitive.isString() && "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}".equals(primitive.getAsString()))
{
-            uriJson.remove("kerberos_keytab");
-            uriJson.addProperty("kerberos_keytab", "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}");
-          }
 
-          // Replace
-          //  "kerberos_principal": "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}"
-          // With
-          //  "kerberos_principal": "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}"
-          primitive = uriJson.getAsJsonPrimitive("kerberos_principal");
-          if(primitive.isString() && "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}".equals(primitive.getAsString()))
{
-            uriJson.remove("kerberos_principal");
-            uriJson.addProperty("kerberos_principal", "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}");
-          }
+          if(sourceJson != null) {
+            boolean changesExist = false;
+            LOG.debug("Source before update : {}", sourceJson);
+
+            JsonObject uriJson = sourceJson.get("uri").getAsJsonObject();
+            JsonPrimitive primitive;
+
+            if (uriJson != null) {
+              // Replace
+              //  "kerberos_keytab": "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}"
+              // With
+              //  "kerberos_keytab": "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}"
+              primitive = uriJson.getAsJsonPrimitive("kerberos_keytab");
+              if ((primitive != null) && primitive.isString() && "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}".equals(primitive.getAsString()))
{
+                uriJson.remove("kerberos_keytab");
+                uriJson.addProperty("kerberos_keytab", "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}");
+                changesExist = true;
+              }
+
+              // Replace
+              //  "kerberos_principal": "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}"
+              // With
+              //  "kerberos_principal": "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}"
+              primitive = uriJson.getAsJsonPrimitive("kerberos_principal");
+              if ((primitive != null) && primitive.isString() && "{{hbase-site/hbase.security.authentication.spnego.kerberos.keytab}}".equals(primitive.getAsString()))
{
+                uriJson.remove("kerberos_principal");
+                uriJson.addProperty("kerberos_principal", "{{hbase-site/hbase.security.authentication.spnego.kerberos.principal}}");
+                changesExist = true;
+              }
+            }
 
-          LOG.debug("Source after update : {}", sourceJson);
-          alertDefinition.setSource(sourceJson.toString());
-          alertDefinition.setHash(UUID.randomUUID().toString());
+            LOG.debug("Source after update : {}", sourceJson);
+            if(changesExist) {
+              alertDefinition.setSource(sourceJson.toString());
+              alertDefinition.setHash(UUID.randomUUID().toString());
 
-          alertDefinitionDAO.merge(alertDefinition);
+              alertDefinitionDAO.merge(alertDefinition);
+            }
+          }
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8eaaf808/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
index 3dfc32f..cb2e5f6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
@@ -508,6 +508,39 @@ public class UpgradeCatalog250Test {
   }
 
   @Test
+  public void testFixHBaseMasterCPUUtilizationAlertDefinitionMissingKerberosInfo() {
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
+    final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
+    final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
+    final AlertDefinitionDAO mockAlertDefinitionDAO = easyMockSupport.createNiceMock(AlertDefinitionDAO.class);
+    final AlertDefinitionEntity hbaseMasterCPUAlertMock = easyMockSupport.createNiceMock(AlertDefinitionEntity.class);
+
+    String brokenSource = "{\"uri\":{\"http\":\"{{hbase-site/hbase.master.info.port}}\",\"default_port\":60010,\"connection_timeout\":5.0},\"jmx\":{\"property_list\":[\"java.lang:type\\u003dOperatingSystem/SystemCpuLoad\",\"java.lang:type\\u003dOperatingSystem/AvailableProcessors\"],\"value\":\"{0}
* 100\"},\"type\":\"METRIC\",\"reporting\":{\"ok\":{\"text\":\"{1} CPU, load {0:.1%}\"},\"warning\":{\"text\":\"{1}
CPU, load {0:.1%}\",\"value\":200.0},\"critical\":{\"text\":\"{1} CPU, load {0:.1%}\",\"value\":250.0},\"units\":\"%\",\"type\":\"PERCENT\"}}";
+
+    Capture<String> capturedFixedSource = newCapture();
+
+    final Injector mockInjector = createInjector(mockAmbariManagementController, mockClusters,
mockAlertDefinitionDAO);
+    long clusterId = 1;
+
+    expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
+    expect(mockClusters.getClusters()).andReturn(Collections.singletonMap("normal", mockClusterExpected)).atLeastOnce();
+    expect(mockClusterExpected.getClusterId()).andReturn(clusterId).anyTimes();
+    expect(mockAlertDefinitionDAO.findByName(eq(clusterId), eq("hbase_master_cpu"))).andReturn(hbaseMasterCPUAlertMock).atLeastOnce();
+    expect(hbaseMasterCPUAlertMock.getDefinitionName()).andReturn("hbase_master_cpu").once();
+    expect(hbaseMasterCPUAlertMock.getSource()).andReturn(brokenSource).once();
+
+    expect(mockAlertDefinitionDAO.merge(hbaseMasterCPUAlertMock)).andReturn(hbaseMasterCPUAlertMock).anyTimes();
+
+    easyMockSupport.replayAll();
+
+    mockInjector.getInstance(UpgradeCatalog250.class).fixHBaseMasterCPUUtilizationAlertDefinition();
+    easyMockSupport.verifyAll();
+
+    Assert.assertFalse(capturedFixedSource.hasCaptured());
+  }
+
+  @Test
   public void testUpdateYarnSite() throws Exception {
     EasyMockSupport easyMockSupport = new EasyMockSupport();
 


Mime
View raw message