Ejemplo n.º 1
0
 def connection_listener(self, state):
     if state == "LOST":
         LoggerHelper().info("zookeeper connect lost!")
         # Register somewhere that the session was lost
     elif state == "SUSPENDED":
         LoggerHelper().info("zookeeper connect disconnected!")
         # Handle being disconnected from Zookeeper
     else:
         LoggerHelper().info("zookeeper connect connected!")
Ejemplo n.º 2
0
if __name__ == "__main__":
    host = ConfigHelper().getConfig("zookeeper", "host")
    port = ConfigHelper().getConfig("zookeeper", "port")
    rs = RegisterCenter("{}:{}".format(host, port))
    rs.connect()
    try:
        rs.service_register("hello_provider", "provider", {
            "host": "127.0.0.1",
            "port": 8000
        })
        rs.service_register("hello_provider", "provider", {
            "host": "127.0.0.1",
            "port": 8001
        })
        rs.service_register("hello_provider", "provider", {
            "host": "127.0.0.1",
            "port": 8002
        })
        LoggerHelper().info(rs.get_register("hello_provider", "provider"))
        LoggerHelper().info("****")
        LoggerHelper().info(rs.get("/hello_provider/provider/ID0000000002"))
        rs.set("/hello_provider/provider/ID0000000002", b"123")
        LoggerHelper().info(rs.get("/hello_provider/provider/ID0000000002"))
        LoggerHelper().info(rs.get_children("/hello_provider/provider"))
        os.system("pause")
    except Exception as e:
        LoggerHelper().error(e)
    finally:
        rs.delete("/hello_provider")
    rs.close()
Ejemplo n.º 3
0
# =============================================================================
#     FileName:
#         Desc:
#       Author:
#        Email:
#     HomePage:
#      Version:
#   LastChange:
#      History:
# =============================================================================
import paramiko
import traceback
from logger_helper import LoggerHelper

MAX_CONNECT_TIMEOUT = 3
logger = LoggerHelper.get_logger()


class LinuxServer(object):
    def __init__(self, ssh_host, ssh_port, ssh_user, ssh_password):
        self.ssh_host = ssh_host
        self.ssh_port = ssh_port
        self.ssh_user = ssh_user
        self.ssh_password = ssh_password

    def ssh_connection_check(self):
        echo_flag = '====ssh==check===='
        cmd_output, cmd_error = self.remote_exec_cmd(
            cmd="echo '{0}'".format(echo_flag))
        if cmd_output is None:
            return False
Ejemplo n.º 4
0
#       Author:
#        Email:
#     HomePage:
#      Version:
#   LastChange:
#      History:
# =============================================================================
import os, time, datetime
import traceback
from base_config import BaseConfig
from base_server import BaseServer
from binlog_server import BinlogServer
from linux_server import LinuxServer
from logger_helper import LoggerHelper

logger = LoggerHelper.get_logger(__name__)


class MasterServer(BaseServer):
    def __init__(self,
                 mysql_host,
                 mysql_port=None,
                 mysql_user=None,
                 mysql_password=None,
                 repl_user=None,
                 repl_password=None,
                 ssh_port=None,
                 ssh_user=None,
                 ssh_password=None,
                 binlog_dir=None,
                 working_dir=None,
Ejemplo n.º 5
0
 def return_service_type(self, type):
     if type not in ["provider", "consumer"]:
         LoggerHelper().warning("type is not provider or consumer!")
         raise Exception("type must be provider or consumer!")
     return 1
Ejemplo n.º 6
0
            self.zk.ensure_path("/%s/%s" % (servicename, type))
            self.zk.create("/%s/%s/ID" % (servicename, type),
                           json.dumps(address).encode('utf-8'),
                           ephemeral=ephemeral,
                           sequence=sequence)

    def get_register(self, servicename, type):
        if self.return_service_type(type):
            result = self.zk.get_children("/%s/%s" % (servicename, type))
            register = []
            if result:
                for i in result:
                    data, stat = self.zk.get("/%s/%s/%s" %
                                             (servicename, type, i))
                    register.append(data.decode("utf-8"))
        return register


if __name__ == "__main__":
    host = ConfigHelper().getConfig("zookeeper", "host")
    port = ConfigHelper().getConfig("zookeeper", "port")
    rs = RegisterCenter("{}:{}".format(host, port))
    rs.connect()
    rs.service_register("hello_provider", "provider", {
        "host": "127.0.0.1",
        "port": 8002
    })
    LoggerHelper().info("============get_register:")
    LoggerHelper().info(rs.get_register("hello_provider", "provider"))
    rs.close()
Ejemplo n.º 7
0
# -*- coding:utf-8 -*-

import os
from singleton_helper import Singleton
import configparser
from logger_helper import LoggerHelper


@Singleton
class ConfigHelper:
    def getConfig(self, section, key):
        config = configparser.ConfigParser()
        configpath = os.path.split(os.path.realpath(__file__))[0] + "/conf"
        config.read(configpath + "/service.conf")
        return config.get(section, key)


if __name__ == "__main__":
    LoggerHelper().info(ConfigHelper().getConfig("database", "dbname"))
Ejemplo n.º 8
0
#        Email:
#     HomePage:
#      Version:
#   LastChange:
#      History:
# =============================================================================

import datetime, time
from mysql_cluster import MySQLCluster
from binlog_server import BinlogServer
from master_server import MasterServer
from slave_server import SlaveServer
from logger_helper import LoggerHelper
from multiprocessing import Process

logger = LoggerHelper.get_logger()


class ClusterManager(object):
    def __init__(self):
        self.cluster_list = []

    def init_clusters(self):
        mysql_cluster1 = MySQLCluster()
        mysql_cluster1.master_server = MasterServer(
            mysql_host="192.168.199.238")
        mysql_cluster1.slave_servers.append(
            SlaveServer(mysql_host="192.168.199.123", master_server_rank=100))
        mysql_cluster1.slave_servers.append(
            SlaveServer(mysql_host="192.168.199.118", master_server_rank=200))
        self.cluster_list.append(mysql_cluster1)