[STRATOS-940] - Raise ThriftReceiverOfflineException when exception occurs while publishing event. Healthstats catch ThriftReceiverOfflineException and tries to reconnect forever.
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/20022bc9 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/20022bc9 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/20022bc9 Branch: refs/heads/master Commit: 20022bc99c54f24b0b6427a794306eb4ed26ef68 Parents: 2efcb97 Author: Chamila de Alwis <[email protected]> Authored: Wed Nov 12 16:01:09 2014 +0530 Committer: Chamila de Alwis <[email protected]> Committed: Wed Nov 12 16:01:09 2014 +0530 ---------------------------------------------------------------------- .../cartridgeagent/modules/databridge/agent.py | 8 ++--- .../exception/parameternotfoundexception.py | 1 + .../exception/thriftreceiverofflineexception.py | 35 ++++++++++++++++++++ .../modules/healthstatspublisher/healthstats.py | 20 +++++++---- 4 files changed, 52 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/20022bc9/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/databridge/agent.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/databridge/agent.py b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/databridge/agent.py index 8674ab3..a4ebfc2 100644 --- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/databridge/agent.py +++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/databridge/agent.py @@ -18,6 +18,7 @@ from thrift.publisher import * from thrift.gen.Exception.ttypes import ThriftSessionExpiredException from ..util.log import * +from ..exception.thriftreceiverofflineexception import ThriftReceiverOfflineException import time @@ -169,12 +170,7 @@ class ThriftPublisher: self.publish(event) except Exception as ex: - self.log.error("Couldn't publish event. Connection to CEP receiver dropped. Reconnecting...") - try: - self.__publisher.connect(self.username, self.password) - except Exception as ex: - if "Connection refused" in ex: - self.log.error("CEP Offline") + raise ThriftReceiverOfflineException(ex) def create_event_bundle(self, event): """ http://git-wip-us.apache.org/repos/asf/stratos/blob/20022bc9/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py index 88deafd..7536544 100644 --- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py +++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py @@ -15,6 +15,7 @@ # specific language governing permissions and limitations # under the License. + class ParameterNotFoundException(Exception): """ Exception raised when a property is not present in the configuration or the payload http://git-wip-us.apache.org/repos/asf/stratos/blob/20022bc9/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/thriftreceiverofflineexception.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/thriftreceiverofflineexception.py b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/thriftreceiverofflineexception.py new file mode 100644 index 0000000..867f58a --- /dev/null +++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/exception/thriftreceiverofflineexception.py @@ -0,0 +1,35 @@ +# 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. + + +class ThriftReceiverOfflineException(Exception): + """ + Exception raised when the connection to the Thrift receiver is dropped when publishing events + """ + __message = None + + def __init__(self, message): + Exception.__init__(self, message) + self.__message = message + + def get_message(self): + """ + The message provided when the exception is raised + :return: message + :rtype: str + """ + return self.__message http://git-wip-us.apache.org/repos/asf/stratos/blob/20022bc9/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py index 6bb574b..3bbb89b 100644 --- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py +++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py @@ -25,6 +25,7 @@ from abstracthealthstatisticspublisher import * from ..databridge.agent import * from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration from ..util import cartridgeagentutils, cartridgeagentconstants +from ..exception.thriftreceiverofflineexception import ThriftReceiverOfflineException class HealthStatisticsPublisherManager(Thread): @@ -62,12 +63,19 @@ class HealthStatisticsPublisherManager(Thread): while not self.terminated: time.sleep(self.publish_interval) - cartridge_stats = self.stats_reader.stat_cartridge_health() - self.log.debug("Publishing memory consumption: %r" % cartridge_stats.memory_usage) - self.publisher.publish_memory_usage(cartridge_stats.memory_usage) - - self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg) - self.publisher.publish_load_average(cartridge_stats.load_avg) + try: + cartridge_stats = self.stats_reader.stat_cartridge_health() + self.log.debug("Publishing memory consumption: %r" % cartridge_stats.memory_usage) + self.publisher.publish_memory_usage(cartridge_stats.memory_usage) + + self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg) + self.publisher.publish_load_average(cartridge_stats.load_avg) + except ThriftReceiverOfflineException: + self.log.error("Couldn't publish health statistics to CEP. Thrift Receiver offline. Reconnecting...") + try: + self.publisher = HealthStatisticsPublisher() + except: + self.log.error("Couldn't connect. CEP Offline.") self.publisher.publisher.disconnect()
