ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: AMBARI-15237. Create Grafana user through Ambari and add user to Grafana. (avijayan, swagle via swagle)
Date Tue, 01 Mar 2016 01:40:25 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 50c61d602 -> fbbc855d3


AMBARI-15237. Create Grafana user through Ambari and add user to Grafana. (avijayan, swagle
via swagle)


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

Branch: refs/heads/branch-2.2
Commit: fbbc855d3adcdfc0abd92e4cb3d00ee994782491
Parents: 50c61d6
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Mon Feb 29 17:27:58 2016 -0800
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Mon Feb 29 17:40:07 2016 -0800

----------------------------------------------------------------------
 .../conf/unix/ams-grafana.ini                   |  6 +--
 .../0.1.0/configuration/ams-grafana-env.xml     | 28 +++++++++++++
 .../0.1.0/configuration/ams-grafana-ini.xml     |  4 +-
 .../package/scripts/metrics_grafana_util.py     | 43 +++++++++++++-------
 .../0.1.0/package/scripts/params.py             |  2 +
 .../AMBARI_METRICS/test_metrics_grafana.py      |  4 +-
 .../python/stacks/2.0.6/configs/default.json    |  4 +-
 ambari-web/app/data/HDP2/site_properties.js     | 14 +++++++
 8 files changed, 83 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-metrics/ambari-metrics-grafana/conf/unix/ams-grafana.ini
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-grafana/conf/unix/ams-grafana.ini b/ambari-metrics/ambari-metrics-grafana/conf/unix/ams-grafana.ini
index c0ccf1a..78f30b5 100644
--- a/ambari-metrics/ambari-metrics-grafana/conf/unix/ams-grafana.ini
+++ b/ambari-metrics/ambari-metrics-grafana/conf/unix/ams-grafana.ini
@@ -145,13 +145,13 @@ static_root_path = /usr/lib/ambari-metrics-grafana/public
 #################################### Anonymous Auth ##########################
 [auth.anonymous]
 # enable anonymous access
-enabled = true
+;enabled = true
 
 # specify organization name that should be used for unauthenticated users
-org_name = Main Org.
+;org_name = Main Org.
 
 # specify role for unauthenticated users
-org_role = Admin
+;org_role = Admin
 
 #################################### Github Auth ##########################
 [auth.github]

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-env.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-env.xml
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-env.xml
index de32ead..f15cd20 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-env.xml
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-env.xml
@@ -38,6 +38,34 @@
     <description>Metrics Grafana data directory.</description>
   </property>
   <property>
+    <name>metrics_grafana_username</name>
+    <value>admin</value>
+    <display-name>Metrics Grafana Admin Username</display-name>
+    <description>
+      Metrics Grafana Username. This value cannot be modified by Ambari
+      except on initial install. Please make sure the username change in
+      Grafana is reflected in Ambari.
+    </description>
+    <value-attributes>
+      <type>db_user</type>
+      <overridable>false</overridable>
+    </value-attributes>
+  </property>
+  <property require-input="true">
+    <name>metrics_grafana_password</name>
+    <value> </value>
+    <property-type>PASSWORD</property-type>
+    <display-name>Metrics Grafana Admin Password</display-name>
+    <description>
+      Metrics Grafana password. This value cannot be modified by Ambari
+      except on initial install. Please make sure the password change in
+      Grafana is reflected back in Ambari.
+    </description>
+    <value-attributes>
+      <overridable>false</overridable>
+    </value-attributes>
+  </property>
+  <property>
     <name>content</name>
     <value>
 # Set environment variables here.

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-ini.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-ini.xml
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-ini.xml
index 0a1ff32..3a0e86b 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-ini.xml
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-grafana-ini.xml
@@ -153,10 +153,10 @@ cert_key = {{ams_grafana_cert_key}}
 #################################### Security ####################################
 [security]
 # default admin user, created on startup
-;admin_user = admin
+admin_user = {{ams_grafana_admin_user}}
 
 # default admin password, can be changed before first start of grafana,  or in profile settings
-;admin_password = admin
+admin_password = {{ams_grafana_admin_pwd}}
 
 # used for signing
 ;secret_key = SW2YcwTIb9zpOOhoPsMm

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
index 3309878..eb0b691 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_grafana_util.py
@@ -23,6 +23,7 @@ from resource_management.core.base import Fail
 from resource_management import Template
 from collections import namedtuple
 from urlparse import urlparse
+from base64 import b64encode
 import time
 import socket
 import ambari_simplejson as json
@@ -35,7 +36,7 @@ GRAFANA_DATASOURCE_URL = "/api/datasources"
 GRAFANA_DASHBOARDS_URL = "/api/dashboards/db"
 METRICS_GRAFANA_DATASOURCE_NAME = "AMBARI_METRICS"
 
-Server = namedtuple('Server', [ 'protocol', 'host', 'port' ])
+Server = namedtuple('Server', [ 'protocol', 'host', 'port', 'user', 'password' ])
 
 def perform_grafana_get_call(url, server):
   grafana_https_enabled = server.protocol.lower() == 'https'
@@ -44,10 +45,12 @@ def perform_grafana_get_call(url, server):
                                      int(server.port),
                                      grafana_https_enabled)
 
-  Logger.info("Connecting (GET) to %s:%s%s" % (server.host,
-                                               server.port,
-                                               url))
-  conn.request("GET", url)
+  userAndPass = b64encode('{0}:{1}'.format(server.user, server.password))
+  headers = { 'Authorization' : 'Basic %s' %  userAndPass }
+
+  Logger.info("Connecting (GET) to %s:%s%s" % (server.host, server.port, url))
+
+  conn.request("GET", url, headers = headers)
   response = conn.getresponse()
   Logger.info("Http response: %s %s" % (response.status, response.reason))
 
@@ -56,7 +59,9 @@ def perform_grafana_get_call(url, server):
 def perform_grafana_put_call(url, id, payload, server):
   response = None
   data = None
-  headers = {"Content-Type": "application/json"}
+  userAndPass = b64encode('{0}:{1}'.format(server.user, server.password))
+  headers = {"Content-Type": "application/json",
+             'Authorization' : 'Basic %s' %  userAndPass }
   grafana_https_enabled = server.protocol.lower() == 'https'
 
   for i in xrange(0, GRAFANA_CONNECT_TRIES):
@@ -82,8 +87,10 @@ def perform_grafana_put_call(url, id, payload, server):
 def perform_grafana_post_call(url, payload, server):
   response = None
   data = None
+  userAndPass = b64encode('{0}:{1}'.format(server.user, server.password))
   Logger.debug('POST payload: %s' % payload)
-  headers = {"Content-Type": "application/json", "Content-Length" : len(payload)}
+  headers = {"Content-Type": "application/json", "Content-Length" : len(payload),
+             'Authorization' : 'Basic %s' %  userAndPass}
   grafana_https_enabled = server.protocol.lower() == 'https'
 
   for i in xrange(0, GRAFANA_CONNECT_TRIES):
@@ -115,21 +122,24 @@ def perform_grafana_post_call(url, payload, server):
 def is_unchanged_datasource_url(datasource_url):
   import params
   parsed_url = urlparse(datasource_url)
-  Logger.debug("parsed url, scheme = %s, host = %s, port = %s" % (
+  Logger.debug("parsed url: scheme = %s, host = %s, port = %s" % (
     parsed_url.scheme, parsed_url.hostname, parsed_url.port))
-  Logger.debug("collector, scheme = %s, host = %s, port = %s" %
+  Logger.debug("collector: scheme = %s, host = %s, port = %s" %
               (params.metric_collector_protocol, params.metric_collector_host,
                params.metric_collector_port))
 
-  return (parsed_url.scheme == params.metric_collector_protocol.strip()) and \
-         (parsed_url.hostname == params.metric_collector_host.strip()) and \
-         (parsed_url.port == params.metric_collector_port)
+  return parsed_url.scheme.strip() == params.metric_collector_protocol.strip() and \
+         parsed_url.hostname.strip() == params.metric_collector_host.strip() and \
+         str(parsed_url.port) == params.metric_collector_port
+
 
 def create_ams_datasource():
   import params
   server = Server(protocol = params.ams_grafana_protocol.strip(),
                   host = params.ams_grafana_host.strip(),
-                  port = params.ams_grafana_port)
+                  port = params.ams_grafana_port,
+                  user = params.ams_grafana_admin_user,
+                  password = params.ams_grafana_admin_pwd)
 
   """
   Create AMS datasource in Grafana, if exsists make sure the collector url is accurate
@@ -206,7 +216,9 @@ def create_ams_dashboards():
   import params
   server = Server(protocol = params.ams_grafana_protocol.strip(),
                   host = params.ams_grafana_host.strip(),
-                  port = params.ams_grafana_port)
+                  port = params.ams_grafana_port,
+                  user = params.ams_grafana_admin_user,
+                  password = params.ams_grafana_admin_pwd)
 
   dashboard_files = params.get_grafana_dashboard_defs()
   version = params.get_ambari_version()
@@ -283,7 +295,8 @@ def create_ams_dashboards():
           else:
             Logger.error("Failed creating dashboard: %s" % dashboard_def['title'])
           pass
-        pass
+        else:
+          Logger.info('No update needed for dashboard = %s' % dashboard_def['title'])
       pass
     pass
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
index 3bd98a2..294c025 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
@@ -127,6 +127,8 @@ ams_grafana_log_dir = default("/configurations/ams-grafana-env/metrics_grafana_l
 ams_grafana_pid_dir = status_params.ams_grafana_pid_dir
 ams_grafana_conf_dir = '/etc/ambari-metrics-grafana/conf'
 ams_grafana_data_dir = default("/configurations/ams-grafana-env/metrics_grafana_data_dir",
'/var/lib/ambari-metrics-grafana')
+ams_grafana_admin_user = config['configurations']['ams-grafana-env']['metrics_grafana_username']
+ams_grafana_admin_pwd = config['configurations']['ams-grafana-env']['metrics_grafana_password']
 
 metrics_grafana_hosts = default('/clusterHostInfo/metrics_grafana_hosts', None)
 ams_grafana_host = None

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/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 38ce90f..3810b07 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
@@ -38,7 +38,8 @@ class TestMetricsGrafana(RMFTestCase):
   import  metrics_grafana_util
 
   @patch("metrics_grafana_util.create_ams_datasource")
-  def test_start(self, create_ams_datasource_mock):
+  @patch("metrics_grafana_util.create_ams_dashboards")
+  def test_start(self, create_ams_datasource_mock, create_ams_dashboards_mock):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/metrics_grafana.py",
                        classname = "AmsGrafana",
                        command = "start",
@@ -64,6 +65,7 @@ class TestMetricsGrafana(RMFTestCase):
                               user = 'ams'
                               )
     create_ams_datasource_mock.assertCalled()
+    create_ams_dashboards_mock.assertCalled()
     self.assertNoMoreResources()
 
   def assert_configure(self):

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/configs/default.json b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
index 7626056..f35e8f7 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
+++ b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
@@ -861,7 +861,9 @@
             "metrics_grafana_log_dir": "/var/log/ambari-metrics-grafana",
             "metrics_grafana_pid_dir": "/var/run/ambari-metrics-grafana",
             "metrics_grafana_data_dir": "/var/lib/ambari-metrics-grafana",
-            "content": "\n"
+            "content": "\n",
+            "metrics_grafana_username" : "admin",
+            "metrics_grafana_password" : "admin"
         },
         "ams-ssl-server": {
             "content": "\n"

http://git-wip-us.apache.org/repos/asf/ambari/blob/fbbc855d/ambari-web/app/data/HDP2/site_properties.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/data/HDP2/site_properties.js b/ambari-web/app/data/HDP2/site_properties.js
index e061c96..54dfde0 100644
--- a/ambari-web/app/data/HDP2/site_properties.js
+++ b/ambari-web/app/data/HDP2/site_properties.js
@@ -1696,6 +1696,20 @@ var hdp2properties = [
     "index": 5
   },
   {
+    "name": "metrics_grafana_username",
+    "serviceName": "AMBARI_METRICS",
+    "filename": "ams-grafana-env.xml",
+    "category": "General",
+    "index": 6
+  },
+  {
+    "name": "metrics_grafana_password",
+    "serviceName": "AMBARI_METRICS",
+    "filename": "ams-grafana-env.xml",
+    "category": "General",
+    "index": 7
+  },
+  {
     "name": "timeline.metrics.aggregator.checkpoint.dir",
     "serviceName": "AMBARI_METRICS",
     "filename": "ams-site.xml",


Mime
View raw message