ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-9084 Refine Smoke test for AMS (dsen)
Date Fri, 16 Jan 2015 13:10:22 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 111b2e533 -> 0a1d66488


AMBARI-9084 Refine Smoke test for AMS (dsen)


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

Branch: refs/heads/trunk
Commit: 0a1d66488ea4a512c23baacd7e629772afd2f717
Parents: 111b2e5
Author: Dmytro Sen <dsen@apache.org>
Authored: Fri Jan 16 14:19:34 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Fri Jan 16 15:09:40 2015 +0200

----------------------------------------------------------------------
 ambari-server/pom.xml                           |  1 +
 .../AMS/0.1.0/package/scripts/params.py         |  3 +-
 .../AMS/0.1.0/package/scripts/service_check.py  | 96 ++++++++++++++++++++
 .../package/templates/smoketest_metrics.json.j2 | 15 +++
 4 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0a1d6648/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 43832c9..21b65af 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -166,6 +166,7 @@
             <exclude>src/main/resources/stacks/HDP/2.1.GlusterFS/services/YARN/package/templates/exclude_hosts_list.j2</exclude>
             <exclude>src/main/windows/ambari-server.cmd</exclude>
             <exclude>src/main/windows/ambari-server.ps1</exclude>
+            <exclude>src/main/resources/common-services/AMS/0.1.0/package/templates/smoketest_metrics.json.j2</exclude>
             <exclude>src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/balancer-emulator/balancer-err.log</exclude>
             <exclude>src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/balancer-emulator/balancer.log</exclude>
             <exclude>src/main/resources/stacks/BIGTOP/0.8/services/HDFS/package/scripts/balancer-emulator/balancer.log</exclude>

http://git-wip-us.apache.org/repos/asf/ambari/blob/0a1d6648/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/params.py
b/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/params.py
index 84c2dce..4e7f0c3 100644
--- a/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/params.py
@@ -38,7 +38,8 @@ ams_collector_script = "/usr/sbin/ambari-metrics-collector"
 ams_collector_pid_dir = status_params.ams_collector_pid_dir
 ams_collector_hosts = default("/clusterHostInfo/metric_collector_hosts", [])
 ams_collector_host_single = ams_collector_hosts[0] #TODO cardinality is 1+ so we can have
more than one host
-metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address",
"0.0.0.0:8188")
+metric_collector_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address",
"0.0.0.0:6188")
+metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address",
"0.0.0.0:6188")
 if metric_collector_port and metric_collector_port.find(':') != -1:
   metric_collector_port = metric_collector_port.split(':')[1]
 pass

http://git-wip-us.apache.org/repos/asf/ambari/blob/0a1d6648/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/service_check.py
b/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/service_check.py
index 5561e10..cc45aeb 100644
--- a/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/service_check.py
+++ b/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/scripts/service_check.py
@@ -17,3 +17,99 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 """
+
+from resource_management.core.logger import Logger
+from resource_management.core.base import Fail
+from resource_management import Script
+from resource_management import Template
+import httplib
+import urllib
+import json
+import random
+import time
+
+
+class AMSServiceCheck(Script):
+
+  AMS_METRICS_POST_URL = "/ws/v1/timeline/metrics/"
+  AMS_METRICS_GET_URL = "/ws/v1/timeline/metrics?%s"
+
+  def service_check(self, env):
+    import params
+
+    Logger.info("AMS service check was started.")
+    env.set_params(params)
+
+    random_value1 = random.random()
+    current_time = time.time()
+    metric_json = Template('smoketest_metrics.json.j2', hostname=params.hostname, random1=random_value1,
+                           current_time=current_time).get_content()
+    Logger.info("Generated metrics:\n%s" % metric_json)
+
+    Logger.info("Connecting (POST) to %s%s" % (params.metric_collector_address, self.AMS_METRICS_POST_URL))
+    headers = {"Content-type": "application/json"}
+    conn = httplib.HTTPConnection(params.metric_collector_address)
+
+    conn.request("POST", self.AMS_METRICS_POST_URL, metric_json, headers)
+    response = conn.getresponse()
+    Logger.info("Http response: %s %s" % (response.status, response.reason))
+
+    data = response.read()
+    Logger.info("Http data: %s" % data)
+    conn.close()
+
+    if response.status == 200:
+      Logger.info("AMS metrics were saved.")
+    else:
+      Logger.info("AMS metrics were not saved. Service check has failed.")
+      raise Fail("AMS metrics were not saved. Service check has failed. POST request status:
%s %s \n%s" %
+                 (response.status, response.reason, data))
+
+    get_metrics_parameters = {
+      "metricNames": "AMS.SmokeTest.FakeMetric",
+      "appId": "amssmoketestfake",
+      "hostname": params.hostname,
+      "startTime": 1419860000000,
+      "precision": "seconds",
+      "grouped": "false",
+    }
+    encoded_get_metrics_parameters = urllib.urlencode(get_metrics_parameters)
+
+    Logger.info("Connecting (GET) to %s%s" % (params.metric_collector_address,
+                                              self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters))
+
+    conn = httplib.HTTPConnection(params.metric_collector_address)
+    conn.request("GET", self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters)
+    response = conn.getresponse()
+    Logger.info("Http response: %s %s" % (response.status, response.reason))
+
+    data = response.read()
+    Logger.info("Http data: %s" % data)
+    conn.close()
+
+    if response.status == 200:
+      Logger.info("AMS metrics were retrieved.")
+    else:
+      Logger.info("AMS metrics were not retrieved. Service check has failed.")
+      raise Fail("AMS metrics were not retrieved. Service check has failed. GET request status:
%s %s \n%s" %
+                 (response.status, response.reason, data))
+    data_json = json.loads(data)
+
+    def floats_eq(f1, f2, delta):
+      return abs(f1-f2) < delta
+
+    for metrics_data in data_json["metrics"]:
+      if (floats_eq(metrics_data["metrics"]["1419860001000"], random_value1, 0.0000001)
+          and floats_eq(metrics_data["metrics"]["1419860002000"], current_time, 1)):
+        Logger.info("Values %s and %s were found in response." % (random_value1, current_time))
+        break
+      pass
+    else:
+      Logger.info("Values %s and %s were not found in response." % (random_value1, current_time))
+      raise Fail("Values %s and %s were not found in response." % (random_value1, current_time))
+
+    Logger.info("AMS service check is finished.")
+
+if __name__ == "__main__":
+  AMSServiceCheck().execute()
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/0a1d6648/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/templates/smoketest_metrics.json.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/templates/smoketest_metrics.json.j2
b/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/templates/smoketest_metrics.json.j2
new file mode 100644
index 0000000..e2e8501
--- /dev/null
+++ b/ambari-server/src/main/resources/common-services/AMS/0.1.0/package/templates/smoketest_metrics.json.j2
@@ -0,0 +1,15 @@
+{
+  "metrics": [
+    {
+      "metricname": "AMS.SmokeTest.FakeMetric",
+      "appid": "amssmoketestfake",
+      "hostname": "{{hostname}}",
+      "timestamp": 1419860001000,
+      "starttime": 1419860001000,
+      "metrics": {
+        "1419860001000": {{random1}},
+        "1419860002000": {{current_time}}
+      }
+    }
+  ]
+}


Mime
View raw message