Example #1
0
    def create_result(self, containerClusterName, container_names=[]):
        create_successful = {'code': "000000"}
        creating = {'code': "000001"}
        create_failed = {'code': "000002", 'status': Status.create_failed}

        zkOper = Requests_ZkOpers()
        exists = zkOper.check_containerCluster_exists(containerClusterName)
        if not exists:
            raise UserVisiableException('containerCluster %s not existed' %
                                        containerClusterName)

        result = {}

        container_cluster_info = zkOper.retrieve_container_cluster_info(
            containerClusterName)
        start_flag = container_cluster_info.get('start_flag')

        if start_flag == Status.failed:
            result.update(create_failed)
            result.setdefault('error_msg', 'create containers failed!')

        elif start_flag == Status.succeed:
            create_info = self.__created_info(containerClusterName,
                                              container_names)
            result.update(create_successful)
            result.update(create_info)
        else:
            result.update(creating)
        return result
Example #2
0
    def sync(self):
        clusters_zk_info = self.get_clusters_zk()

        clusters = []
        for cluster_name, nodes in clusters_zk_info.items():
            try:
                cluster, nodeInfo = {}, []
                logging.info('sync action, cluster name:%s' % cluster)
                cluster_status = self.component_container_cluster_validator.container_cluster_status_validator(
                    cluster_name)
                cluster.update(cluster_status)
                cluster.setdefault('clusterName', cluster_name)

                zkOper = Requests_ZkOpers()
                cluster_info = zkOper.retrieve_container_cluster_info(
                    cluster_name)
                _type = cluster_info.get('type')
                cluster.setdefault('type', _type)

                for _, node_value in nodes.items():
                    container_info = node_value.get('container_info')
                    con = Container_Model()
                    create_info = con.create_info(container_info)
                    nodeInfo.append(create_info)
                cluster.setdefault('nodeInfo', nodeInfo)
                clusters.append(cluster)

            except:
                self.threading_exception_queue.put(sys.exc_info())
                continue

        return clusters