Ver código fonte

AMBARI-15898 : Grafana fails to start when using custom data directory (avijayan)

Aravindan Vijayan 9 anos atrás
pai
commit
56377d4e2b

+ 21 - 0
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java

@@ -1689,11 +1689,32 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
             }
             updateConfigurationPropertiesForCluster(cluster, AMS_SITE, newProperties, true, true);
           }
+
+          Config amsGrafanaIni = cluster.getDesiredConfigByType("ams-grafana-ini");
+          if (amsGrafanaIni != null) {
+            Map<String, String> amsGrafanaIniProperties = amsGrafanaIni.getProperties();
+            String content = amsGrafanaIniProperties.get("content");
+            Map<String, String> newProperties = new HashMap<>();
+            newProperties.put("content", updateAmsGrafanaIni(content));
+            updateConfigurationPropertiesForCluster(cluster, "ams-grafana-ini", newProperties, true, true);
+          }
         }
       }
     }
   }
 
+  protected String updateAmsGrafanaIni(String content) {
+
+    if (content == null) {
+      return null;
+    }
+    String regSearch = "/var/lib/ambari-metrics-grafana";
+    String replacement = "{{ams_grafana_data_dir}}";
+    content = content.replaceAll(regSearch, replacement);
+
+    return content;
+  }
+
   /**
    * Create blueprint_setting table for storing the "settings" section
    * in the blueprint. Auto start information is specified in the "settings" section.

+ 1 - 1
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-ini.xml

@@ -57,7 +57,7 @@
 # Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
 #
 ;data = /var/lib/grafana
-data = /var/lib/ambari-metrics-grafana
+data = {{ams_grafana_data_dir}}
 #
 # Directory where grafana can store logs
 #

+ 20 - 0
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java

@@ -31,6 +31,7 @@ import static org.junit.Assert.assertNull;
 
 import java.io.File;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -1605,5 +1606,24 @@ public class UpgradeCatalog240Test {
     assertTrue(upgradeCatalog240.isAtLeastHdp25(new StackId("HDP-2.6")));
     assertFalse(upgradeCatalog240.isAtLeastHdp25(new StackId("SOMETHINGELSE-1.4")));
   }
+
+  @Test
+  public void testUpdateAmsGrafanaIniContent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
+  {
+    Method updateAmsEnvContent = UpgradeCatalog240.class.getDeclaredMethod("updateAmsGrafanaIni", String.class);
+    UpgradeCatalog240 upgradeCatalog240 = new UpgradeCatalog240(injector);
+    String oldContent = "# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)\n" +
+      "#\n" +
+      ";data = /var/lib/grafana\n" +
+      "data = /var/lib/ambari-metrics-grafana";
+
+    String expectedContent = "# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)\n" +
+      "#\n" +
+      ";data = /var/lib/grafana\n" +
+      "data = {{ams_grafana_data_dir}}";
+
+    String result = (String) updateAmsEnvContent.invoke(upgradeCatalog240, oldContent);
+    Assert.assertEquals(expectedContent, result);
+  }
 }