Exemple #1
0
def _reloadrestsrv(keys=[]):
    '''
    重新加载REST SERVICE数据
    @return:
    '''

    # sql查询回调函数
    def reloadservice(cur):
        field = [
            'serviceid', 'type', 'servicename', 'url', 'enabled', 'cachetype',
            'origialurl', 'secret', 'msglog'
        ]

        for item in cur.fetchall():
            d = dict(zip(field, item))
            redistip.put2redis("SRV_URL_" + d["url"], d)
            if ("SRV_URL_" + d["url"]).encode(encoding="utf-8") in keys:
                keys.remove(("SRV_URL_" + d["url"]).encode(encoding="utf-8"))
            if settings.DEBUG:
                settings.infoLogger.info("app rest service,key:%s" %
                                         ("SRV_URL_" + d["url"]))

    sql = "select " \
          "USERVICE_DATA.SERVICEID," \
          "USERVICE_DATA.TYPE," \
          "USERVICE_DATA.SERVICENAME," \
          "USERVICE_DATA.URL," \
          "USERVICE_DATA.ENABLED," \
          "USERVICE_DATA.CACHETYPE, " \
          "USERVICE_REST.ORIGIALURL, " \
          "USERVICE_DATA.SECRET, " \
          "USERVICE_DATA.MSGLOG " \
          "from USERVICE_DATA " \
          "inner join USERVICE_REST on USERVICE_REST.serviceid=USERVICE_DATA.serviceid"
    db.querySQL(sql, reloadservice)
Exemple #2
0
def _reloadAppky(appkey=None):
    """
    重新加载AppKey
    :return:
    redis中
            appkey的生成逻辑是“APPKEY_”与appid的字符串连接
            rest服务的redis key 是SRV_URL_
    """

    if appkey is None:
        appsrv = db.querySQL2map(
            "select APP_ID,SERVICE_ID from uservice_servicerole")
    else:
        appsrv = db.querySQL2map(
            "select APP_ID,SERVICE_ID from uservice_servicerole where APP_ID=:APPID",
            {"APPID": appkey})

    def reloadAppkey(cur):
        """
        重新加载appkey回调句柄
        :param cur:
        :return:
        """
        preKey = "APPKEY_"
        ks = GLOBAREDIS.keys(preKey + "*")
        field = ['app_id', 'publickey', 'privatekey', 'uname', 'pwd']
        appkeys = []
        for item in cur.fetchall():
            d = dict(zip(field, item))
            srvs = []
            for srv in appsrv:
                if srv["APP_ID"] == d['app_id']:
                    srvs.append(srv["SERVICE_ID"])
            d["services"] = srvs
            key = preKey + d['app_id']
            redistip.put2redis(key, d)
            if key in ks:
                ks.remove(key)
            appkeys.append(key)
            if settings.DEBUG:
                settings.infoLogger.info("add app data,appkey:%s" %
                                         (preKey + d['app_id']))
        for k in ks:
            GLOBAREDIS.delete(k)

    if appkey is None:
        db.querySQL(
            "SELECT APP_ID,PUBLICKEY,PRIVATEKEY,UNAME,PWD FROM P_APPKEY",
            reloadAppkey)
    else:
        db.querySQL(
            "SELECT APP_ID,PUBLICKEY,PRIVATEKEY,UNAME,PWD FROM P_APPKEY where APP_ID=:APP_ID",
            {"APP_ID": appkey}, reloadAppkey)
Exemple #3
0
def _reloadPlant():
    '''
    加载平台信息
    @return:
    '''
    def reloadplant(cur):
        field = [
            'platid', 'area', 'contacts', 'pluguel', 'sysusername', 'syspwd'
        ]
        for item in cur.fetchall():
            redistip.put2redis("PC_" + item[4], dict(zip(field, item)))
            if settings.DEBUG:
                settings.infoLogger.info("add plantfrom,key:%s" %
                                         ("PC_" + item[4]))

    db.querySQL(
        "select PLATID, AREA, CONTACTS, PLUGURL, SYSUSERNAME, SYSPWD from P_PLATFORM",
        reloadplant)
Exemple #4
0
def _reloadcloudSrv():
    '''
    加载云服务
    @return:
    '''
    def reloadcloudSrv(cur):
        field = [
            "SERVICEID", "TYPE", "SERVICENAME", "URL", "ENABLED", "CACHETYPE",
            "SECRET", "MSGLOG", "NOTE", "SERVICETYPE", "ORIGIALURL", "META",
            "ORIGIALSECURITY", "PLANTID"
        ]
        for item in cur.fetchall():
            redistip.put2redis("SC_" + str(item[0]), dict(zip(field, item)))
            if settings.DEBUG:
                settings.infoLogger.info("add cloud service,key:%s" %
                                         ("PC_" + str(item[0])))

    db.querySQL(
        "SELECT a.SERVICEID,a.TYPE,a.SERVICENAME,a.URL,a.ENABLED,a.CACHETYPE,a.SECRET,a.MSGLOG,a.NOTE,b.SERVICETYPE,b.ORIGIALURL,b.META,b.ORIGIALSECURITY,b.PLANTID FROM USERVICE_DATA a\
                    inner join USERVICE_CLOUD b on a.serviceid=b.serviceid",
        reloadcloudSrv)