Example #1
0
    def generate_container_names(self, component_type, count, cluster):

        names, container_numbers = [], []
        mid_name = _name.get(component_type)
        zk_opers = Container_ZkOpers()
        exists = zk_opers.check_containerCluster_exists(cluster)
        if not exists:
            for i in range(int(count)):
                container_name = 'd-%s-%s-n-%s' % (mid_name, cluster,
                                                   str(i + 1))
                names.append(container_name)
        else:
            containers = zk_opers.retrieve_container_list(cluster)
            for container in containers:
                container_value = zk_opers.retrieve_container_node_value(
                    cluster, container)
                container_name = container_value.get('containerName')
                container_prefix, container_number = re.findall(
                    '(.*-n-)(\d+)', container_name)[0]
                container_numbers.append(int(container_number))
            max_number = max(container_numbers)
            if max_number < 4:
                max_number = 4
            for i in range(int(count)):
                max_number += 1
                add_container_name = container_prefix + str(max_number)
                names.append(add_container_name)
        return names
    def __get_params(self):
        """
            two containers may be with a host_ip
        """

        params, container_info, container_nodes = {}, {}, []

        zkOper = Container_ZkOpers()
        if self.containers:
            for container in self.containers:
                container_node = self.container_opers.get_container_node_from_container_name(
                    self.cluster, container)
                container_nodes.append(container_node)
        else:
            container_nodes = zkOper.retrieve_container_list(self.cluster)
        self.container_nodes = container_nodes
        for container_node in self.container_nodes:
            container_name_list = []
            container_info = zkOper.retrieve_container_node_value(
                self.cluster, container_node)
            container_name = container_info.get('containerName')
            host_ip = container_info.get('hostIp')
            container_name_list.append(container_name)
            if host_ip in params:
                container_name_list.extend(params[host_ip])
            params[host_ip] = container_name_list
        return params
 def do_when_remove_cluster(self):
     zkOper = Container_ZkOpers()
     cluster_info = zkOper.retrieve_container_cluster_info(self.cluster)
     use_ip = cluster_info.get('isUseIp')
     if use_ip:
         container_ip_list = zkOper.retrieve_container_list(self.cluster)
         logging.info('container_ip_list:%s' % str(container_ip_list))
         zkOper.recover_ips_to_pool(container_ip_list)
 def __exclude_servers(self, cluster):
     host_ip_list = []
     zk_opers = Container_ZkOpers()
     container_list = zk_opers.retrieve_container_list(cluster)
     for container in container_list:
         container_value = zk_opers.retrieve_container_node_value(
             cluster, container)
         host_ip = container_value.get('hostIp')
         host_ip_list.append(host_ip)
     return host_ip_list
    def __is_containers_started(self, container_cluster_name, sum_count):

        zkOper = Container_ZkOpers()
        container_list = zkOper.retrieve_container_list(container_cluster_name)
        if len(container_list) != sum_count:
            logging.info('container length:%s, sum_count :%s' %
                         (len(container_list), sum_count))
            return False
        logging.info('sum_count is created: %s' % sum_count)
        status = self.component_container_cluster_validator.container_cluster_status_validator(
            container_cluster_name)
        logging.info('cluster status: %s' % status)
        return status.get('status') == Status.started
    def container_cluster_status_validator(self, cluster):
        zkOper = Container_ZkOpers()

        container_node_list = zkOper.retrieve_container_list(cluster)
        status_list, result = [], {}
        for container_node in container_node_list:
            status_node_value = zkOper.retrieve_container_status_value(
                cluster, container_node)
            status_list.append(status_node_value.get('status'))

        status = self.__get_cluster_status(status_list)
        result.setdefault('status', status)

        if status == Status.destroyed:
            logging.info('delete containerCluster: %s record in zookeeper' %
                         cluster)
            zkOper.delete_container_cluster(cluster)

        return result
Example #7
0
    def get_container_node_from_container_name(self, cluster, container_name):
        con_node = ''
        zkOper = Container_ZkOpers()
        cluster_info = zkOper.retrieve_container_cluster_info(cluster)
        use_ip = cluster_info.get('isUseIp')
        if use_ip:
            container_node_list = zkOper.retrieve_container_list(cluster)
            for container_node in container_node_list:
                container_info = zkOper.retrieve_container_node_value(
                    cluster, container_node)
                inspect = container_info.get('inspect')
                con = Container_Model(inspect=inspect)
                con_name = con.name()
                if container_name == con_name:
                    con_node = container_node
                    break
        else:
            con_node = container_name

        return con_node