You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2016/04/07 18:00:02 UTC

ambari git commit: AMBARI-15761. While creating WEB URLs for Alerts, if we add http/https then we should not drop the URL path past port number (aonishuk)

Repository: ambari
Updated Branches:
  refs/heads/trunk 73472dc1c -> 1c737d3a2


AMBARI-15761. While creating WEB URLs for Alerts, if we add http/https then we should not drop the URL path past port number (aonishuk)


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

Branch: refs/heads/trunk
Commit: 1c737d3a29d42640cd16ffef1c179f6856a9ec76
Parents: 73472dc
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Thu Apr 7 18:59:43 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Thu Apr 7 18:59:43 2016 +0300

----------------------------------------------------------------------
 .../python/ambari_agent/alerts/web_alert.py     | 11 ++++--
 .../src/test/python/ambari_agent/TestAlerts.py  |  4 +--
 .../resource_management/TestGetPathFromUrl.py   | 31 ++++++++++++++++
 .../libraries/functions/__init__.py             |  2 ++
 .../libraries/functions/get_path_from_url.py    | 37 ++++++++++++++++++++
 5 files changed, 81 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1c737d3a/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
index 3f201c8..42ad96b 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
@@ -30,6 +30,7 @@ from tempfile import gettempdir
 from alerts.base_alert import BaseAlert
 from collections import namedtuple
 from resource_management.libraries.functions.get_port_from_url import get_port_from_url
+from resource_management.libraries.functions.get_path_from_url import get_path_from_url
 from resource_management.libraries.functions.curl_krb_request import curl_krb_request
 from ambari_commons import OSCheck
 from ambari_commons.inet_utils import resolve_address
@@ -129,6 +130,10 @@ class WebAlert(BaseAlert):
     if string_uri.startswith('http://') or string_uri.startswith('https://'):
       return alert_uri.uri
 
+    uri_path = None
+    if string_uri and string_uri != str(None):
+      uri_path = get_path_from_url(string_uri)
+
     # start building the URL manually
     host = BaseAlert.get_host_from_url(alert_uri.uri)
     if host is None:
@@ -153,8 +158,10 @@ class WebAlert(BaseAlert):
       # on windows 0.0.0.0 is invalid address to connect but on linux it resolved to 127.0.0.1
       host = resolve_address(host)
 
-    return "{0}://{1}:{2}".format(scheme, host, str(port))
-
+    if uri_path:
+      return "{0}://{1}:{2}/{3}".format(scheme, host, str(port), uri_path)
+    else:
+      return "{0}://{1}:{2}".format(scheme, host, str(port))
 
   def _make_web_request(self, url):
     """

http://git-wip-us.apache.org/repos/asf/ambari/blob/1c737d3a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
index e5f6a41..9caee8a 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
@@ -548,7 +548,7 @@ class TestAlerts(TestCase):
     configuration = {'hdfs-site' :
       { 'dfs.http.policy' : 'HTTPS_ONLY',
         'dfs.datanode.http.address' : 'c6401.ambari.apache.org:80',
-        'dfs.datanode.https.address' : 'c6401.ambari.apache.org:443' }
+        'dfs.datanode.https.address' : 'c6401.ambari.apache.org:443/test/path' }
     }
 
     self.__update_cluster_configuration(cluster_configuration, configuration)
@@ -565,7 +565,7 @@ class TestAlerts(TestCase):
     
     # SSL assertion
     self.assertEquals('CRITICAL', alerts[0]['state'])
-    self.assertEquals('(Unit Tests) critical: https://c6401.ambari.apache.org:443. error message', alerts[0]['text'])
+    self.assertEquals('(Unit Tests) critical: https://c6401.ambari.apache.org:443/test/path. error message', alerts[0]['text'])
 
   def test_reschedule(self):
     test_file_path = os.path.join('ambari_agent', 'dummy_files')

http://git-wip-us.apache.org/repos/asf/ambari/blob/1c737d3a/ambari-agent/src/test/python/resource_management/TestGetPathFromUrl.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestGetPathFromUrl.py b/ambari-agent/src/test/python/resource_management/TestGetPathFromUrl.py
new file mode 100644
index 0000000..7550a00
--- /dev/null
+++ b/ambari-agent/src/test/python/resource_management/TestGetPathFromUrl.py
@@ -0,0 +1,31 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+from unittest import TestCase
+
+from resource_management.libraries.functions.get_path_from_url import get_path_from_url
+
+
+class TestGetPathFromUlr(TestCase):
+
+  def test_get_path_from_url(self):
+    self.assertEquals(get_path_from_url("http://test.host:8888/test/path"), "test/path")
+    self.assertEquals(get_path_from_url("http://test.host/test/path"), "test/path")
+    self.assertEquals(get_path_from_url("test.host:8888/test/path"), "test/path")
+    self.assertEquals(get_path_from_url("test.host/test/path"), "test/path")
+    self.assertEquals(get_path_from_url("/test/path"), "test/path")

http://git-wip-us.apache.org/repos/asf/ambari/blob/1c737d3a/ambari-common/src/main/python/resource_management/libraries/functions/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/__init__.py b/ambari-common/src/main/python/resource_management/libraries/functions/__init__.py
index ff4fddf..f0c2e13 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/__init__.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/__init__.py
@@ -43,7 +43,9 @@ from resource_management.libraries.functions.get_lzo_packages import *
 from resource_management.libraries.functions.setup_ranger_plugin import *
 from resource_management.libraries.functions.curl_krb_request import *
 from resource_management.libraries.functions.get_bare_principal import *
+from resource_management.libraries.functions.get_path_from_url import *
 from resource_management.libraries.functions.show_logs import *
+
 IS_WINDOWS = platform.system() == "Windows"
 
 if IS_WINDOWS:

http://git-wip-us.apache.org/repos/asf/ambari/blob/1c737d3a/ambari-common/src/main/python/resource_management/libraries/functions/get_path_from_url.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/get_path_from_url.py b/ambari-common/src/main/python/resource_management/libraries/functions/get_path_from_url.py
new file mode 100644
index 0000000..0cc5782
--- /dev/null
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/get_path_from_url.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Ambari Agent
+
+"""
+
+from resource_management.libraries.functions.is_empty import is_empty
+import re
+
+def get_path_from_url(address):
+  """
+  Return port from URL. If the address is numeric, the address is assumed to be a port and is returned.
+  If address is UnknownConfiguration, UnknownConfiguration will be returned.
+  """
+  if is_empty(address):
+    return address
+
+  result = re.findall("^((.+)://)?(([a-zA-Z0-9]|\.|-)*)(:([\d]{2,}))?/(.*)$", address)
+  if result:
+    return result[0][6]
+  return None
\ No newline at end of file