Example #1
0
    def cluster_resoure(self, cluster, resource_type):
        zkOper = Requests_ZkOpers()

        exists = zkOper.check_containerCluster_exists(cluster)
        if not exists:
            error_message = 'container cluster %s not exist, please check your cluster name' % cluster
            raise HTTPAPIError(status_code=417, error_detail=error_message,
                               notification="direct",
                               log_message=error_message,
                               response=error_message)

        container_node_list = zkOper.retrieve_container_list(cluster)
        result = []

        for container_node in container_node_list:
            resource = {}
            resource_value = zkOper.retrieve_container_resource(cluster, container_node, resource_type)
            host_ip = self.container_opers.get_host_ip_from_zk(cluster, container_node)
            container_name = self.container_opers.get_container_name_from_zk(cluster, container_node)
            resource.setdefault('value', resource_value)
            resource.setdefault('hostIp', host_ip)
            resource.setdefault('containerName', container_name)
            result.append(resource)

        return result
Example #2
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 #3
0
    def post(self):
        requestParam = self.get_all_arguments()

        zkOper = Requests_ZkOpers()

        existCluster = zkOper.existCluster()
        if existCluster:
            clusterUUID = zkOper.getClusterUUID()
        else:
            clusterUUID = str(uuid.uuid1())
            requestParam.setdefault("clusterUUID", clusterUUID)

        if requestParam != {}:
            self.confOpers.setValue(options.server_cluster_property,
                                    requestParam)
            self.confOpers.setValue(options.data_node_property, requestParam)

        clusterProps = self.confOpers.getValue(options.server_cluster_property)
        dataNodeProprs = self.confOpers.getValue(options.data_node_property)
        zkOper.writeClusterInfo(clusterUUID, clusterProps)
        zkOper.writeDataNodeInfo(clusterUUID, dataNodeProprs)

        return_message = {}
        return_message.setdefault("message",
                                  "creating server cluster successful!")
        self.finish(return_message)
Example #4
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
 def get_server_resource(host_ip, resource_type):
     zk_opers = Requests_ZkOpers()
     result = {}
     resource_value = zk_opers.retrieve_server_resource(
         host_ip, resource_type)
     result.setdefault(resource_type, resource_value)
     return result
    def get_clusters_zk(self):
        zkOper = Requests_ZkOpers()
        cluster_name_list = zkOper.retrieve_cluster_list()
        clusters_zk_info = {}
        for cluster_name in cluster_name_list:
            cluster_info_dict = self.get_cluster_zk(cluster_name)
            clusters_zk_info.setdefault(cluster_name, cluster_info_dict)

        return clusters_zk_info
Example #7
0
    def check(self, containerClusterName):
        zkOper = Requests_ZkOpers()
        exists = zkOper.check_containerCluster_exists(containerClusterName)
        if not exists:
            raise UserVisiableException('containerCluster %s not existed' %
                                        containerClusterName)

        cluster_status = self.component_container_cluster_validator.container_cluster_status_validator(
            containerClusterName)
        return cluster_status
Example #8
0
    def get(self):
        args = self.get_all_arguments()
        host_ip = args.get('hostIp')
        logging.info('get server %s ports' % host_ip)

        zkOper = Requests_ZkOpers()
        ports = zkOper.get_ports_from_portPool(host_ip)

        result = {}
        result.setdefault('ports', ports)
        self.finish(result)
Example #9
0
    def get(self):
        zkOper = Requests_ZkOpers()

        clusterUUID = zkOper.getClusterUUID()
        data, _ = zkOper.retrieveClusterProp(clusterUUID)
        self.confOpers.setValue(options.server_cluster_property, eval(data))

        result = {}
        result.setdefault("message",
                          "sync server cluster info to local successful!")
        self.finish(result)
    def get_container_resource(self, container_name, resource_type):
        zk_opers = Requests_ZkOpers()

        result = {}
        cluster_name = get_containerClusterName_from_containerName(
            container_name)
        node_name = self.container_opers.get_container_node_from_container_name(
            cluster_name, container_name)
        resource_value = zk_opers.retrieve_container_resource(
            cluster_name, node_name, resource_type)

        result.setdefault('value', resource_value)
        result.setdefault('containerName', container_name)
        return result
Example #11
0
 def get_cluster_zk(self, cluster_name):
     cluster_zk_info = {}
     zkOper = Requests_ZkOpers()
     container_ip_list = zkOper.retrieve_container_list(cluster_name)
     for container_ip in container_ip_list:
         container_node = {}
         create_info = zkOper.retrieve_container_node_value(
             cluster_name, container_ip)
         status = zkOper.retrieve_container_status_value(
             cluster_name, container_ip)
         container_node.setdefault('container_info', create_info)
         container_node.setdefault('status', status)
         cluster_zk_info.setdefault(container_ip, container_node)
     return cluster_zk_info
    def __cluster_created_info(self, cluster):
        zkOper = Requests_ZkOpers()
        message_list = []

        container_node_list = zkOper.retrieve_container_list(cluster)
        result = {}
        for container_node in container_node_list:
            container_node_value = zkOper.retrieve_container_node_value(
                cluster, container_node)
            con = Container_Model()
            create_info = con.create_info(container_node_value)
            message_list.append(create_info)
        result.setdefault('containers', message_list)
        return result
    def do(self):
        zkOper = Requests_ZkOpers()
        monitor_types = zkOper.retrieve_monitor_type()
        stat_dict = {}
        for monitor_type in monitor_types:
            monitor_status_list = zkOper.retrieve_monitor_status_list(
                monitor_type)

            monitor_type_sub_dict = {}
            for monitor_status_key in monitor_status_list:
                monitor_status_value = zkOper.retrieve_monitor_status_value(
                    monitor_type, monitor_status_key)
                monitor_type_sub_dict.setdefault(monitor_status_key,
                                                 monitor_status_value)

            stat_dict.setdefault(monitor_type, monitor_type_sub_dict)
        return stat_dict
Example #14
0
    def __update_white_list(self, conf_dict):
        error_msg = ''
        conf_white_str = conf_dict.get('servers')
        ip_pattern = '(((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?),)+((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)'
        if not re.match(ip_pattern, conf_white_str):
            error_msg = 'the values of the params is not correct'
            logging.error(error_msg)
            return error_msg

        zkOper = Requests_ZkOpers()
        conf_white_list = conf_white_str.split(',')
        privs_white_list = zkOper.retrieve_servers_white_list()
        add = list(set(conf_white_list) - set(privs_white_list))
        delete = list(set(privs_white_list) - set(conf_white_list))
        both = list(set(privs_white_list) & set(conf_white_list))
        for item in add:
            zkOper.add_server_into_white_list(item)

        for item in delete:
            zkOper.del_server_from_white_list(item)
        return error_msg
Example #15
0
    def __created_info(self, cluster, container_names=[]):
        zkOper = Requests_ZkOpers()
        message_list, container_nodes = [], []
        if container_names:
            for container_name in container_names:
                container_node = self.container_opers.get_container_node_from_container_name(
                    cluster, container_name)
                if not container_node:
                    raise UserVisiableException('container :%s not existed' %
                                                container_name)
                container_nodes.append(container_node)
        else:
            container_nodes = zkOper.retrieve_container_list(cluster)

        result = {}
        for container_node in container_nodes:
            container_node_value = zkOper.retrieve_container_node_value(
                cluster, container_node)
            con = Container_Model()
            create_info = con.create_info(container_node_value)
            message_list.append(create_info)
        result.setdefault('containers', message_list)
        return result
Example #16
0
 def get(self):
     zkOper = Requests_ZkOpers()
     ips = zkOper.get_ips_from_ipPool()
     result = {}
     result.setdefault('ips', ips)
     self.finish(result)