AMBARI-18579. Grafana fails to start after deployment (aonishuk)

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

Branch: refs/heads/branch-2.4
Commit: 4550f94c78822883207e9408e63f8bd280f91c69
Parents: 9196e42
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Wed Oct 12 20:14:23 2016 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Wed Oct 12 20:14:23 2016 +0300

----------------------------------------------------------------------
 .../AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana.py  | 6 ++++--
 .../AMBARI_METRICS/0.1.0/package/scripts/params_linux.py     | 7 +++++++
 .../stacks/2.0.6/AMBARI_METRICS/test_metrics_grafana.py      | 5 +++--
 .../python/stacks/2.0.6/configs/default_ams_embedded.json    | 8 ++++++++
 4 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4550f94c/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana.py
 
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana.py
index ae2a635..0c9bb08 100644
--- 
a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana.py
+++ 
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana.py
@@ -43,7 +43,8 @@ class AmsGrafana(Script):
 
     start_cmd = format("{ams_grafana_script} start")
     Execute(start_cmd,
-            user=params.ams_user
+            user=params.ams_user,
+            not_if = params.grafana_process_exists_cmd,
             )
     # Create datasource
     create_ams_datasource()
@@ -55,7 +56,8 @@ class AmsGrafana(Script):
     env.set_params(params)
     self.configure(env, action = 'stop')
     Execute((format("{ams_grafana_script}"), 'stop'),
-            sudo=True
+            sudo=True,
+            only_if = params.grafana_process_exists_cmd,
             )
 
   def status(self, env):

http://git-wip-us.apache.org/repos/asf/ambari/blob/4550f94c/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params_linux.py
 
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params_linux.py
index 4ef719c..c2111b4 100644
--- 
a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params_linux.py
+++ 
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params_linux.py
@@ -18,8 +18,10 @@ limitations under the License.
 
 """
 
+import status_params
 from resource_management import *
 from resource_management.libraries.functions import conf_select
+from resource_management.core.shell import as_user
 from ambari_commons import OSCheck
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 from resource_management.libraries.functions.expect import expect
@@ -32,6 +34,8 @@ ams_user = 
config['configurations']['ams-env']['ambari_metrics_user']
 #RPM versioning support
 rpm_version = default("/configurations/hadoop-env/rpm_version", None)
 
+ams_grafana_pid_dir = 
config['configurations']['ams-grafana-env']['metrics_grafana_pid_dir']
+
 #hadoop params
 if rpm_version is not None:
   #RPM versioning support
@@ -54,3 +58,6 @@ dfs_type = default("/commandParams/dfs_type", "")
 
 hbase_regionserver_shutdown_timeout = 
expect('/configurations/ams-hbase-env/hbase_regionserver_shutdown_timeout', int,
                                              30)
+
+grafana_pid_file = format("{ams_grafana_pid_dir}/grafana-server.pid")
+grafana_process_exists_cmd = as_user(format("test -f {grafana_pid_file} && ps 
-p `cat {grafana_pid_file}`"), ams_user)

http://git-wip-us.apache.org/repos/asf/ambari/blob/4550f94c/ambari-server/src/test/python/stacks/2.0.6/AMBARI_METRICS/test_metrics_grafana.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/python/stacks/2.0.6/AMBARI_METRICS/test_metrics_grafana.py
 
b/ambari-server/src/test/python/stacks/2.0.6/AMBARI_METRICS/test_metrics_grafana.py
index 2e24d82..9ac14c4 100644
--- 
a/ambari-server/src/test/python/stacks/2.0.6/AMBARI_METRICS/test_metrics_grafana.py
+++ 
b/ambari-server/src/test/python/stacks/2.0.6/AMBARI_METRICS/test_metrics_grafana.py
@@ -70,8 +70,9 @@ class TestMetricsGrafana(RMFTestCase):
     self.assertResourceCalled('Execute', 'ambari-sudo.sh rm -rf /some_tmp_dir',
                               )
     self.assertResourceCalled('Execute', '/usr/sbin/ambari-metrics-grafana 
start',
-                              user = 'ams'
-                              )
+        not_if = "ambari-sudo.sh su ams -l -s /bin/bash -c 
'[RMF_EXPORT_PLACEHOLDER]test -f 
/var/run/ambari-metrics-grafana/grafana-server.pid && ps -p `cat 
/var/run/ambari-metrics-grafana/grafana-server.pid`'",
+        user = 'ams',
+    )
     create_ams_datasource_mock.assertCalled()
     create_ams_dashboards_mock.assertCalled()
     self.assertNoMoreResources()

http://git-wip-us.apache.org/repos/asf/ambari/blob/4550f94c/ambari-server/src/test/python/stacks/2.0.6/configs/default_ams_embedded.json
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/python/stacks/2.0.6/configs/default_ams_embedded.json 
b/ambari-server/src/test/python/stacks/2.0.6/configs/default_ams_embedded.json
index ceedb67..1d5a6b9 100644
--- 
a/ambari-server/src/test/python/stacks/2.0.6/configs/default_ams_embedded.json
+++ 
b/ambari-server/src/test/python/stacks/2.0.6/configs/default_ams_embedded.json
@@ -42,6 +42,14 @@
     "taskId": 152, 
     "public_hostname": "c6401.ambari.apache.org", 
     "configurations": {
+        "ams-grafana-env": {
+            "metrics_grafana_username": "admin", 
+            "metrics_grafana_pid_dir": "/var/run/ambari-metrics-grafana", 
+            "metrics_grafana_data_dir": "/var/lib/ambari-metrics-grafana", 
+            "content": "\n# Set environment variables here.\n\n# AMS UI Server 
Home Dir\nexport AMS_GRAFANA_HOME_DIR={{ams_grafana_home_dir}}\n\n# AMS UI 
Server Data Dir\nexport AMS_GRAFANA_DATA_DIR={{ams_grafana_data_dir}}\n\n# AMS 
UI Server Log Dir\nexport AMS_GRAFANA_LOG_DIR={{ams_grafana_log_dir}}\n\n# AMS 
UI Server PID Dir\nexport AMS_GRAFANA_PID_DIR={{ams_grafana_pid_dir}}", 
+            "metrics_grafana_password": "admin", 
+            "metrics_grafana_log_dir": "/var/log/ambari-metrics-grafana"
+        },
         "mapred-site": {
             "mapreduce.jobhistory.address": "c6402.ambari.apache.org:10020", 
             "mapreduce.cluster.administrators": " hadoop", 

Reply via email to