Changed the logic to retrieve member ID in the configuration
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/1c69a9aa Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1c69a9aa Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1c69a9aa Branch: refs/heads/master Commit: 1c69a9aa76986093970d01e0a22ef6218e483735 Parents: 19f9227 Author: Chamila de Alwis <[email protected]> Authored: Fri Oct 10 13:17:39 2014 +0530 Committer: Chamila de Alwis <[email protected]> Committed: Fri Oct 10 13:17:39 2014 +0530 ---------------------------------------------------------------------- .../config/cartridgeagentconfiguration.py | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/1c69a9aa/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py ---------------------------------------------------------------------- diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py b/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py index 17b6c78..fde28e8 100644 --- a/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py +++ b/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py @@ -16,8 +16,8 @@ # under the License. import ConfigParser -import logging import os +import socket from ..util.log import LogFactory @@ -114,7 +114,7 @@ class CartridgeAgentConfiguration: self.cluster_id = self.read_property(cartridgeagentconstants.CLUSTER_ID) self.network_partition_id = self.read_property(cartridgeagentconstants.NETWORK_PARTITION_ID) self.partition_id = self.read_property(cartridgeagentconstants.PARTITION_ID) - self.member_id = self.read_property(cartridgeagentconstants.MEMBER_ID) + self.member_id = self.get_member_id(cartridgeagentconstants.MEMBER_ID, self.cluster_id) self.cartridge_key = self.read_property(cartridgeagentconstants.CARTRIDGE_KEY) self.app_path = self.read_property(cartridgeagentconstants.APP_PATH) self.repo_url = self.read_property(cartridgeagentconstants.REPO_URL) @@ -231,6 +231,27 @@ class CartridgeAgentConfiguration: self.log.debug("lb-private-ip: %r" % self.lb_private_ip) self.log.debug("lb-public-ip: %r" % self.lb_public_ip) + def get_member_id(self, member_id_field): + """ + Reads the member id from the payload file or configuration file. If neither of + these sources contain the member id, the hostname is assigned to it and returned. + :param str member_id_field: the key of the member id to lookup + :return: The member id + :rtype : str + """ + try: + member_id = self.read_property(member_id_field) + except ParameterNotFoundException: + try: + self.log.info("Reading hostname from container") + member_id = socket.gethostname() + except: + self.log.exception("Hostname can not be resolved") + member_id = "unknown" + + self.log.debug("MemberId is taking the value of hostname : [" + member_id + "] ") + return member_id + def __read_conf_file(self): """ Reads and stores the agent's configuration file
