[05/50] [abbrv] git commit: AMBARI-7051 - Alerts: Expose Creation and Updating of Group Targets Definitions (jonathanhurley)
AMBARI-7051 - Alerts: Expose Creation and Updating of Group Targets Definitions (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/76fc94ec Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/76fc94ec Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/76fc94ec Branch: refs/heads/trunk Commit: 76fc94ec1ab6ee904e0efa254c19521a201c06d4 Parents: ae8f1e7 Author: Jonathan Hurley jhur...@hortonworks.com Authored: Wed Aug 27 21:07:43 2014 -0400 Committer: Jonathan Hurley jhur...@hortonworks.com Committed: Thu Aug 28 09:38:28 2014 -0400 -- .../python/ambari_agent/alerts/base_alert.py| 45 ++- .../python/ambari_agent/alerts/port_alert.py| 42 +-- .../server/api/services/AlertGroupService.java | 10 + .../controller/AlertDefinitionResponse.java | 143 + .../internal/AlertGroupResourceProvider.java| 144 - .../server/orm/dao/AlertDefinitionDAO.java | 16 + .../ambari/server/orm/dao/AlertDispatchDAO.java | 18 +- .../orm/entities/AlertDefinitionEntity.java | 37 ++- .../server/orm/entities/AlertGroupEntity.java | 56 +++- .../server/orm/entities/AlertTargetEntity.java | 3 +- .../ambari/server/state/alert/AlertTarget.java | 37 ++- .../AlertGroupResourceProviderTest.java | 295 +++ .../AlertTargetResourceProviderTest.java| 2 +- .../server/orm/dao/AlertDefinitionDAOTest.java | 18 +- .../server/orm/dao/AlertDispatchDAOTest.java| 53 ++-- 15 files changed, 773 insertions(+), 146 deletions(-) -- http://git-wip-us.apache.org/repos/asf/ambari/blob/76fc94ec/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py -- diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py index 88c7f92..bf8ada6 100644 --- a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py +++ b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py @@ -34,7 +34,7 @@ class BaseAlert(object): self.alert_meta = alert_meta self.alert_source_meta = alert_source_meta self.cluster = '' -self.hostName = '' +self.host_name = '' self._lookup_keys = [] @@ -54,7 +54,7 @@ class BaseAlert(object): def set_cluster(self, cluster, host): ''' sets cluster information for the alert ''' self.cluster = cluster -self.hostName = host +self.host_name = host def collect(self): ''' method used for collection. defers to _collect() ''' @@ -123,4 +123,43 @@ class BaseAlert(object): res[0] = the result code res[1] = the list of arguments supplied to the reporting text for the result code ''' -raise NotImplementedError \ No newline at end of file +raise NotImplementedError + + ''' + See RFC3986, Appendix B + Tested on the following cases: +192.168.54.1 +192.168.54.2:7661 +hdfs://192.168.54.3/foo/bar +ftp://192.168.54.4:7842/foo/bar; + +Returns None if only a port is passsed in + ''' + @staticmethod + def get_host_from_url(uri): +# RFC3986, Appendix B +parts = re.findall('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?', uri) + +# index of parts +# scheme= 1 +# authority = 3 +# path = 4 +# query = 6 +# fragment = 8 + +host_and_port = uri +if 0 == len(parts[0][1]): + host_and_port = parts[0][4] +elif 0 == len(parts[0][2]): + host_and_port = parts[0][1] +elif parts[0][2].startswith(//): + host_and_port = parts[0][3] + +if -1 == host_and_port.find(':'): + # if no : then it might only be a port; if it's a port, return this host + if host_and_port.isdigit(): +return None + + return host_and_port +else: + return host_and_port.split(':')[0] http://git-wip-us.apache.org/repos/asf/ambari/blob/76fc94ec/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py -- diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py index eaf744a..1d34410 100644 --- a/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py +++ b/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py @@ -39,9 +39,11 @@ class PortAlert(BaseAlert): def _collect(self): urivalue = self._lookup_property_value(self.uri) -host = get_host_from_url(self, urivalue) port = self.port - +host = BaseAlert.get_host_from_url(urivalue) +if host is None: + host = self.host_name + try: port = int(get_port_from_url(urivalue)) except: @@ -67,39 +69,3 @@ class
git commit: AMBARI-7051 - Alerts: Expose Creation and Updating of Group Targets Definitions (jonathanhurley)
Repository: ambari Updated Branches: refs/heads/branch-alerts-dev ae8f1e77e - 76fc94ec1 AMBARI-7051 - Alerts: Expose Creation and Updating of Group Targets Definitions (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/76fc94ec Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/76fc94ec Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/76fc94ec Branch: refs/heads/branch-alerts-dev Commit: 76fc94ec1ab6ee904e0efa254c19521a201c06d4 Parents: ae8f1e7 Author: Jonathan Hurley jhur...@hortonworks.com Authored: Wed Aug 27 21:07:43 2014 -0400 Committer: Jonathan Hurley jhur...@hortonworks.com Committed: Thu Aug 28 09:38:28 2014 -0400 -- .../python/ambari_agent/alerts/base_alert.py| 45 ++- .../python/ambari_agent/alerts/port_alert.py| 42 +-- .../server/api/services/AlertGroupService.java | 10 + .../controller/AlertDefinitionResponse.java | 143 + .../internal/AlertGroupResourceProvider.java| 144 - .../server/orm/dao/AlertDefinitionDAO.java | 16 + .../ambari/server/orm/dao/AlertDispatchDAO.java | 18 +- .../orm/entities/AlertDefinitionEntity.java | 37 ++- .../server/orm/entities/AlertGroupEntity.java | 56 +++- .../server/orm/entities/AlertTargetEntity.java | 3 +- .../ambari/server/state/alert/AlertTarget.java | 37 ++- .../AlertGroupResourceProviderTest.java | 295 +++ .../AlertTargetResourceProviderTest.java| 2 +- .../server/orm/dao/AlertDefinitionDAOTest.java | 18 +- .../server/orm/dao/AlertDispatchDAOTest.java| 53 ++-- 15 files changed, 773 insertions(+), 146 deletions(-) -- http://git-wip-us.apache.org/repos/asf/ambari/blob/76fc94ec/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py -- diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py index 88c7f92..bf8ada6 100644 --- a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py +++ b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py @@ -34,7 +34,7 @@ class BaseAlert(object): self.alert_meta = alert_meta self.alert_source_meta = alert_source_meta self.cluster = '' -self.hostName = '' +self.host_name = '' self._lookup_keys = [] @@ -54,7 +54,7 @@ class BaseAlert(object): def set_cluster(self, cluster, host): ''' sets cluster information for the alert ''' self.cluster = cluster -self.hostName = host +self.host_name = host def collect(self): ''' method used for collection. defers to _collect() ''' @@ -123,4 +123,43 @@ class BaseAlert(object): res[0] = the result code res[1] = the list of arguments supplied to the reporting text for the result code ''' -raise NotImplementedError \ No newline at end of file +raise NotImplementedError + + ''' + See RFC3986, Appendix B + Tested on the following cases: +192.168.54.1 +192.168.54.2:7661 +hdfs://192.168.54.3/foo/bar +ftp://192.168.54.4:7842/foo/bar; + +Returns None if only a port is passsed in + ''' + @staticmethod + def get_host_from_url(uri): +# RFC3986, Appendix B +parts = re.findall('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?', uri) + +# index of parts +# scheme= 1 +# authority = 3 +# path = 4 +# query = 6 +# fragment = 8 + +host_and_port = uri +if 0 == len(parts[0][1]): + host_and_port = parts[0][4] +elif 0 == len(parts[0][2]): + host_and_port = parts[0][1] +elif parts[0][2].startswith(//): + host_and_port = parts[0][3] + +if -1 == host_and_port.find(':'): + # if no : then it might only be a port; if it's a port, return this host + if host_and_port.isdigit(): +return None + + return host_and_port +else: + return host_and_port.split(':')[0] http://git-wip-us.apache.org/repos/asf/ambari/blob/76fc94ec/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py -- diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py index eaf744a..1d34410 100644 --- a/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py +++ b/ambari-agent/src/main/python/ambari_agent/alerts/port_alert.py @@ -39,9 +39,11 @@ class PortAlert(BaseAlert): def _collect(self): urivalue = self._lookup_property_value(self.uri) -host = get_host_from_url(self, urivalue) port = self.port - +host = BaseAlert.get_host_from_url(urivalue) +if host is None: + host = self.host_name +