Пример #1
0
    def start(self):
        zkOper = Common_ZkOpers()

        existCluster = zkOper.existCluster()
        if not existCluster:
            raise UserVisiableException("Nginx componentCluster does't exist")

        total_nginx_nodes = zkOper.retrieve_nginx_node_list()
        started_nodes = zkOper.retrieve_started_nodes()
        if len(total_nginx_nodes) == len(started_nodes):
            raise UserVisiableException(
                "all nginx nodes have started. No need to start them.")

        logging.info("all nginx nodes: %s" % (total_nginx_nodes))
        to_start_nginx_nodes = list(
            set(total_nginx_nodes) - set(started_nodes))
        logging.info("nginx needed to start: " + str(to_start_nginx_nodes))

        node_infos = []
        for node in to_start_nginx_nodes:
            info = zkOper.retrieve_nginx_node_info(node)
            node_infos.append(info)

        self.baseOpers(node_infos, OperType.start)

        result_dict = {
            'message': 'cluster start processing, please wait for a moment!'
        }
        return result_dict
Пример #2
0
    def create(self, params):
        if params == {} or params is None:
            raise UserVisiableException("please set the componentNode info!")

        dataNodeInternalPort = params.get('dataNodeInternalPort')
        if dataNodeInternalPort is not None:
            raise UserVisiableException(
                "no need to set the dataNodeInternalPort param!")

        zkOper = Common_ZkOpers()

        local_uuid = getClusterUUID()
        existCluster = zkOper.existCluster(local_uuid)
        if not existCluster:
            raise UserVisiableException(
                "sync componentCluster info error! please check if sync uuid is right!"
            )

        params.setdefault("dataNodeInternalPort", options.port)
        dataNodeExternalPort = params.get('dataNodeExternalPort')
        if dataNodeExternalPort is None or '' == dataNodeExternalPort:
            params.setdefault("dataNodeExternalPort", options.port)

        self.confOpers.setValue(options.data_node_property, params)
        dataNodeProprs = self.confOpers.getValue(options.data_node_property)
        zkOper.writeDataNodeInfo(local_uuid, dataNodeProprs)

        result = {}
        result.setdefault(
            "message",
            "Configuration on this componentNode has been done successfully")
        return result
Пример #3
0
    def sync(self):
        zk_address, zk_port = get_zk_address()
        if not (zk_address and zk_port):
            logging.info('admin zookeeper first!')
            return

        zkOper = Common_ZkOpers()

        existed = zkOper.existCluster()
        if existed:
            self._sync_server_cluster()
            self._sync_data_node()
        else:
            logging.info(
                "cluster does not exist, may be the first time to sync in a new server cluster"
            )
Пример #4
0
    def syncExistedCluster(self, params):
        if params == {}:
            error_message = "please fill the cluster uuid!"
            raise UserVisiableException(error_message)

        clusterUUID = params['clusterUUID']
        zkOper = Common_ZkOpers()

        existCluster = zkOper.existCluster(clusterUUID)
        if not existCluster:
            error_message = "Nginx componentCluster does't exist(cluster id:%s), \
                 please specify the right cluster uuid!" % (clusterUUID)
            raise UserVisiableException(error_message)

        data, _ = zkOper.retrieveClusterProp(clusterUUID)
        logging.info("data in zk %s" % (data))
        json_str_data = data.replace("'", "\"")
        dict_data = json.loads(json_str_data)
        self.confOpers.setValue(options.cluster_property, dict_data)
Пример #5
0
    def create(self, params):
        if params == {} or params is None:
            raise UserVisiableException("please set the componentNode info!")

        dataNodeInternalPort = params.get('dataNodeInternalPort')
        if dataNodeInternalPort:
            raise UserVisiableException(
                "no need to set the dataNodeInternalPort param!")

        zkOper = Common_ZkOpers()

        existCluster = zkOper.existCluster()

        if existCluster:
            raise UserVisiableException(
                "server has belong to a componentCluster,should be not create new componentCluster!"
            )

        clusterUUID = str(uuid.uuid1())
        params.setdefault("clusterUUID", clusterUUID)

        params.setdefault("dataNodeInternalPort", options.port)
        dataNodeExternalPort = params.get('dataNodeExternalPort')
        if dataNodeExternalPort is None or '' == dataNodeExternalPort:
            params.setdefault("dataNodeExternalPort", options.port)

        self.confOpers.setValue(options.cluster_property, params)
        self.confOpers.setValue(options.data_node_property, params)

        clusterProps = self.confOpers.getValue(options.cluster_property)
        dataNodeProprs = self.confOpers.getValue(options.data_node_property)

        zkOper.writeClusterInfo(clusterUUID, clusterProps)
        zkOper.writeDataNodeInfo(clusterUUID, dataNodeProprs)

        return clusterUUID