Ejemplo n.º 1
0
@author: lan (www.9miao.com)
'''
from gfirefly.utils import services
from gfirefly.distributed.node import RemoteObject
from gtwisted.core import reactor
from gtwisted.utils import log
import sys

log.startLogging(sys.stdout)

reactor = reactor

addr = ('localhost', 9090)  #目标主机的地址
remote = RemoteObject('test_node')  #实例化远程调用对象

service = services.CommandService('reference')  #实例化一条服务对象
remote.addServiceChannel(service)


def serviceHandle(target):
    '''服务处理
    @param target: func Object
    '''
    service.mapTarget(target)


@serviceHandle
def printOK_1(data):
    print data
    print "############################"
    #     raise
Ejemplo n.º 2
0
    def config(self,
               config,
               servername=None,
               dbconfig=None,
               memconfig=None,
               masterconf=None):
        '''配置服务器
        '''
        GlobalObject().json_config = config
        GlobalObject().remote_connect = self.remote_connect
        netport = config.get('netport')  #客户端连接
        webport = config.get('webport')  #http连接
        rootport = config.get('rootport')  #root节点配置
        self.remoteportlist = config.get('remoteport', [])  #remote节点配置列表
        if not servername:
            servername = config.get('name')  #服务器名称
        logpath = config.get('log')  #日志
        hasdb = config.get('db')  #数据库连接
        hasmem = config.get('mem')  #memcached连接
        app = config.get('app')  #入口模块名称
        cpuid = config.get('cpu')  #绑定cpu
        mreload = config.get('reload')  #重新加载模块名称
        self.servername = servername

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = Flask("servername")
            GlobalObject().webroot = self.webroot
            reactor.listenWSGI(webport, self.webroot)

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername)

        if hasdb and dbconfig:
            if dbconfig.has_key("user") and dbconfig.has_key(
                    "host") and dbconfig.has_key("host"):
                dbpool.initPool({"default": dbconfig})
            else:
                dbpool.initPool(dbconfig)

        if hasmem and memconfig:
            urls = memconfig.get('urls')
            #             hostname = str(memconfig.get('hostname'))
            memcached_connect(urls)
            from gfirefly.dbentrust.util import M2DB_PORT, M2DB_HOST, ToDBAddress
            ToDBAddress().setToDBHost(memconfig.get("pubhost", M2DB_HOST))
            ToDBAddress().setToDBPort(memconfig.get("pubport", M2DB_PORT))

        if logpath:
            log.addObserver(loogoo(logpath))  #日志处理
        log.startLogging(sys.stdout)

        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)
        GlobalObject().config(netfactory=self.netfactory,
                              root=self.root,
                              remote=self.remote)

        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload,
                                                     fromlist=_path_list[:1])

        if masterconf:
            masterport = masterconf.get('rootport')
            masterhost = masterconf.get('roothost')
            self.master_remote = RemoteObject(servername)
            GlobalObject().masterremote = self.master_remote
            import admin
            addr = ('localhost',
                    masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
Ejemplo n.º 3
0
    def config(self, config, servername=None, dbconfig=None,
               memconfig=None, redis_config=None, masterconf=None, model_default_config=None,
               model_config=None):
        """配置服务器"""
        GlobalObject().json_config = config
        GlobalObject().json_model_config = model_default_config
        GlobalObject().json_model_config = model_config
        netport = config.get('netport')  # 客户端连接
        webport = config.get('webport')  # http连接
        rootport = config.get('rootport')  # root节点配置
        self.remoteportlist = config.get('remoteport', [])  # remote节点配置列表
        if not servername:
            servername = config.get('name')  # 服务器名称
        logpath = config.get('log')  # 日志
        hasdb = config.get('db')  # 数据库连接
        hasmem = config.get('mem')  # memcached连接
        hasredis = config.get('redis') # redis连接
        app = config.get('app')  # 入口模块名称
        cpuid = config.get('cpu')  # 绑定cpu
        mreload = config.get('reload')  # 重新加载模块名称
        self.servername = servername

        if logpath:
            log_init(logpath)  # 日志处理

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = Flask("master")
            GlobalObject().webroot = self.webroot
            self.webroot.debug = True
            # reactor.listenTCP(webport, self.webroot)
            reactor.listenWSGI(webport, self.webroot)

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername)

        if hasdb and dbconfig:
            # logger.info(str(dbconfig))
            dbpool.initPool(**dbconfig)

        if hasmem and memconfig:
            urls = memconfig.get('urls')
            hostname = str(memconfig.get('hostname'))
            mclient.connect(urls, hostname)

        if hasredis and redis_config:
            host = redis_config.get("host")
            port = redis_config.get("port")
            db = redis_config.get("db", 0)
            redis_client.connect(host, port, db)

        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)
        GlobalObject().config(netfactory=self.netfactory, root=self.root,
                              remote=self.remote)
        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload, fromlist=_path_list[:1])
        GlobalObject().remote_connect = self.remote_connect

        if masterconf:
            masterport = masterconf.get('rootport')
            masterhost = masterconf.get('roothost')
            self.master_remote = RemoteObject(servername)
            addr = ('localhost', masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
            GlobalObject().masterremote = self.master_remote

        import admin
Ejemplo n.º 4
0
#coding:utf8
'''
Created on 2011-10-3

@author: lan (www.9miao.com)
'''
import sys
from gtwisted.core import reactor
        
from gtwisted.utils import log
from gfirefly.utils import services
from gfirefly.netconnect.protoc import LiberateFactory

reactor = reactor
service = services.CommandService("loginService")

def serviceHandle(target):
    '''服务处理
    @param target: func Object
    '''
    service.mapTarget(target)
    
factory = LiberateFactory()

def doConnectionLost(conn):
    print conn.transport

factory.doConnectionLost = doConnectionLost

def serverstart():
    '''服务配置
Ejemplo n.º 5
0
    def config(self,
               config,
               servername=None,
               dbconfig=None,
               memconfig=None,
               redis_config=None,
               masterconf=None,
               model_default_config=None,
               model_config=None,
               msdk_config=None):
        """配置服务器"""
        GlobalObject().json_config = config
        GlobalObject().json_model_config = model_default_config
        GlobalObject().json_model_config = model_config
        netport = config.get('netport')  # 客户端连接
        webport = config.get('webport')  # http连接
        rootport = config.get('rootport')  # root节点配置
        self.remoteportlist = config.get('remoteport', [])  # remote节点配置列表
        if not servername:
            servername = config.get('name')  # 服务器名称
        logpath = config.get('log')  # 日志
        hasdb = config.get('db')  # 数据库连接
        # hasmem = config.get('mem')  # memcached连接
        hasredis = config.get('redis')  # redis连接
        app = config.get('app')  # 入口模块名称
        cpuid = config.get('cpu')  # 绑定cpu
        mreload = config.get('reload')  # 重新加载模块名称
        self.servername = servername
        #if servername == 'net':
        #time.sleep(6)
        #if servername == 'gate':
        #time.sleep(16)

        if logpath:
            log_init(logpath)  # 日志处理

        if netport:
            self.netfactory = LiberateFactory()
            netservice = services.CommandService("netservice")
            self.netfactory.addServiceChannel(netservice)
            reactor.listenTCP(netport, self.netfactory)

        if webport:
            self.webroot = Flask("master")
            GlobalObject().webroot = self.webroot
            self.webroot.debug = True
            # reactor.listenTCP(webport, self.webroot)
            reactor.listenWSGI(webport, self.webroot)

        if rootport:
            self.root = PBRoot()
            rootservice = services.Service("rootservice")
            self.root.addServiceChannel(rootservice)
            reactor.listenTCP(rootport, BilateralFactory(self.root))

        for cnf in self.remoteportlist:
            rname = cnf.get('rootname')
            self.remote[rname] = RemoteObject(self.servername)

        if hasdb and dbconfig:
            # logger.info(str(dbconfig))
            dbpool.initPool(**dbconfig)

        if hasredis and redis_config:
            connection_setting = redis_config.get('urls')
            redis_manager.connection_setup(connection_setting)

        if cpuid:
            affinity.set_process_affinity_mask(os.getpid(), cpuid)
        GlobalObject().config(netfactory=self.netfactory,
                              root=self.root,
                              remote=self.remote)
        if app:
            __import__(app)
        if mreload:
            _path_list = mreload.split(".")
            GlobalObject().reloadmodule = __import__(mreload,
                                                     fromlist=_path_list[:1])
        GlobalObject().remote_connect = self.remote_connect

        if masterconf:
            masterport = masterconf.get('rootport')
            masterhost = masterconf.get('roothost')
            self.master_remote = RemoteObject(servername)
            addr = ('localhost',
                    masterport) if not masterhost else (masterhost, masterport)
            self.master_remote.connect(addr)
            GlobalObject().masterremote = self.master_remote

        if msdk_config:
            #zone_id = msdk_config.get("zone_id")
            host = msdk_config.get("host")
            #pay_host = msdk_config.get("pay_host")
            goods_host = msdk_config.get("buy_goods_host")
            valid_host = msdk_config.get("valid_host")
            qq_appid = msdk_config.get("qq_appid")
            qq_appkey = msdk_config.get("qq_appkey")
            wx_appid = msdk_config.get("wx_appid")
            wx_appkey = msdk_config.get("wx_appkey")
            log = logger_sdk.new_log('TxApi')
            GlobalObject().msdk = Msdk(host,
                                       qq_appid,
                                       qq_appkey,
                                       wx_appid,
                                       wx_appkey,
                                       log=log)
            GlobalObject().pay = MidasApi(host,
                                          goods_host,
                                          valid_host,
                                          log=log)
        import admin