From 210ea683d127139e7f469c3c622db38fcaff460a Mon Sep 17 00:00:00 2001 From: Artem Osadchyi Date: Fri, 7 Aug 2015 14:29:49 +0300 Subject: [PATCH] Update cluster UI info in MapR plugin Now cluster UI info is updated every time cluster changes it's size. Change-Id: I8d6c59964afe9ecb4ebcebf996e343240ddb00f8 Closes-Bug: #1481764 --- .../mapr/base/base_cluster_configurer.py | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/sahara/plugins/mapr/base/base_cluster_configurer.py b/sahara/plugins/mapr/base/base_cluster_configurer.py index 9d4adccf..6ecb4051 100644 --- a/sahara/plugins/mapr/base/base_cluster_configurer.py +++ b/sahara/plugins/mapr/base/base_cluster_configurer.py @@ -34,7 +34,6 @@ from sahara.topology import topology_helper as th import sahara.utils.configs as sahara_configs import sahara.utils.files as files - LOG = logging.getLogger(__name__) conductor = conductor.API @@ -87,6 +86,7 @@ class BaseConfigurer(ac.AbstractConfigurer): self._write_config_files(cluster_context, existing) self._update_services(cluster_context, existing) self._restart_services(cluster_context) + self._update_cluster_info(cluster_context) LOG.info(_LI('Existing instances successfully configured')) def _configure_services(self, cluster_context, instances): @@ -208,14 +208,21 @@ class BaseConfigurer(ac.AbstractConfigurer): LOG.debug('Updating UI information.') info = {} for service in cluster_context.cluster_services: - for uri_info in service.ui_info: - title, process, url = uri_info - instance = cluster_context.get_instance(process) - info.update({ - title: { - 'WebUI': url % instance.management_ip - } - }) + for title, node_process, url_template in service.ui_info: + removed = cluster_context.removed_instances(node_process) + instances = cluster_context.get_instances(node_process) + instances = [i for i in instances if i not in removed] + + if len(instances) == 1: + display_name_template = "%(title)s" + else: + display_name_template = "%(title)s %(index)s" + + for index, instance in enumerate(instances, start=1): + args = {"title": title, "index": index} + display_name = display_name_template % args + url = url_template % instance.management_ip + info.update({display_name: {"WebUI": url}}) ctx = context.ctx() conductor.cluster_update(ctx, cluster_context.cluster, {'info': info}) @@ -291,10 +298,10 @@ class BaseConfigurer(ac.AbstractConfigurer): util.execute_on_instances(instances, keep_alive_connection) def mapr_user_exists(self, instance): - with instance.remote() as r: - ec, out = r.execute_command( - 'id -u mapr', run_as_root=True, raise_when_error=False) - return ec == 0 + with instance.remote() as r: + ec, __ = r.execute_command( + "id -u mapr", run_as_root=True, raise_when_error=False) + return ec == 0 def post_start(self, c_context, instances=None): instances = instances or c_context.get_instances()