ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avija...@apache.org
Subject [1/4] ambari git commit: AMBARI-16862 : [Grafana] Rename HBase - Performance dashboard to HBase - RegionServers (avijayan, prao)
Date Wed, 25 May 2016 15:50:02 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk b5220e30d -> f4d9fdecb


http://git-wip-us.apache.org/repos/asf/ambari/blob/f4d9fdec/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 a02c100..e8c12ed 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
@@ -140,6 +140,37 @@ def perform_grafana_post_call(url, payload, server):
 
   return (response, data)
 
+def perform_grafana_delete_call(url, server):
+  grafana_https_enabled = server.protocol.lower() == 'https'
+  response = None
+
+  for i in xrange(0, GRAFANA_CONNECT_TRIES):
+    try:
+      conn = network.get_http_connection(server.host,
+                                         int(server.port),
+                                         grafana_https_enabled)
+
+      userAndPass = b64encode('{0}:{1}'.format(server.user, server.password))
+      headers = { 'Authorization' : 'Basic %s' %  userAndPass }
+
+      Logger.info("Connecting (DELETE) to %s:%s%s" % (server.host, server.port, url))
+
+      conn.request("DELETE", url, headers = headers)
+      response = conn.getresponse()
+      Logger.info("Http response: %s %s" % (response.status, response.reason))
+      break
+    except (httplib.HTTPException, socket.error) as ex:
+      if i < GRAFANA_CONNECT_TRIES - 1:
+        time.sleep(GRAFANA_CONNECT_TIMEOUT)
+        Logger.info("Connection to Grafana failed. Next retry in %s seconds."
+                    % (GRAFANA_CONNECT_TIMEOUT))
+        continue
+      else:
+        raise Fail("Ambari Metrics Grafana update failed due to: %s" % str(ex))
+      pass
+
+  return response
+
 def is_unchanged_datasource_url(datasource_url):
   import params
   parsed_url = urlparse(datasource_url)
@@ -252,18 +283,21 @@ def create_ams_dashboards():
   if response and response.status == 200:
     data = response.read()
     try:
-      datasources = json.loads(data)
+      dashboards = json.loads(data)
     except:
       Logger.error("Unable to parse JSON response from grafana request: %s" %
                    GRAFANA_SEARCH_BULTIN_DASHBOARDS)
       Logger.info(data)
       return
 
-    for datasource in datasources:
-      existing_dashboards.append(
-          Dashboard(uri = datasource['uri'], id = datasource['id'],
-                    title = datasource['title'], tags = datasource['tags'])
-        )
+    for dashboard in dashboards:
+      if dashboard['title'] == 'HBase - Performance':
+        perform_grafana_delete_call("/api/dashboards/" + dashboard['uri'], server)
+      else:
+        existing_dashboards.append(
+            Dashboard(uri = dashboard['uri'], id = dashboard['id'],
+                    title = dashboard['title'], tags = dashboard['tags'])
+          )
     pass
   else:
     Logger.error("Failed to execute search query on Grafana dashboards. "


Mime
View raw message