Ejemplo n.º 1
0
def insertnewstg(cid, load_id):
    insert_load_sql = '''
        INSERT INTO `strategy` 
            (`server_id`, `server_ip`, `domain_key`, `resource_ids`, `owner_type`, `owner_value`, `for_test_msg`, `switch_type`, `switch_value`, `init_group_size`, `min_group_size`, `last_update_time`, `from_domains`, `remark`) 
        VALUES 
            ('%s', '%s', 'qqdomain', '%s', '%s', '%s', 0, 'ByGroup', 12, %s, 1, '2013-03-22 16:28:00', NULL, NULL);
    '''
    if int(cid) < 3000:
        owner_type = 'Branch'
    else:
        owner_type = 'Client'
    #load_array = load[load_id]
    load_array = getLoadInfo(load_id)
    #print load_array
    #print insert_load_sql % (load_list[0], load_list[1], load_list[2], owner_type, cid, load_list[3]) 
    for load_list in load_array:
        try:
            #print load_list
            resource_conn = mdb.get_resource_conn()
            load_list['server_ip'] = getServerIp(load_list['server_id'])
            #print insert_load_sql % (load_list['server_id'], load_list['server_ip'], load_list['rids'], owner_type, cid, load_list['count'])
            row_info = mdb.exe_update_sql(resource_conn, insert_load_sql % (load_list['server_id'], load_list['server_ip'], load_list['rids'], owner_type, cid, load_list['count']), False, True, False, False)
            print row_info
        except Exception,e:
            print e
            sys.exit()
Ejemplo n.º 2
0
def updateresource(src,tag):
    sql = '''
        update resource rc set rc.domains = replace(domains, '%s', '%s') where rc.id in (%s)
    '''

    resource_conn = mdb.get_resource_conn()
    row_info = mdb.exe_update_sql(resource_conn, sql % (src, tag, resource_ids), False, True, False, False)
    print row_info
Ejemplo n.º 3
0
def selectstg(cid):
    sql = " select * from strategy s where s.domain_key = 'qqdomain' and s.owner_value = %s "
    try:
        resource_conn = mdb.get_resource_conn()
        result = mdb.exe_sql(resource_conn, sql % (cid), False, True)
        return result
    except Exception,e:
        print e
        sys.exit()
Ejemplo n.º 4
0
def deloldstg(cid):
    sql = " delete from strategy where domain_key = 'qqdomain' and owner_value = %s " 
    try:
        resource_conn = mdb.get_resource_conn()
        row_info = mdb.exe_update_sql(resource_conn, sql % (cid), False, True, False, False)
        print row_info
    except Exception,e:
        print e
        sys.exit()
Ejemplo n.º 5
0
def showshortstrategy():
    sql = '''
        select 
            st.resource_ids, st.server_ip, st.owner_type, group_concat(st.owner_value) as owner_values
        from 
            strategy st 
        where 
            st.domain_key = 'qqdomain' and owner_value <> '' and st.for_test_msg = 0 and st.owner_value not like '-%' 
        group by 
            st.resource_ids, st.owner_type
    '''
    resource_conn = mdb.get_resource_conn()
    datas = list(mdb.exe_sql(resource_conn, sql, True, True))
    return datas
Ejemplo n.º 6
0
def insertnewstg(server_id, server_ip, domainkey, resource_ids, owner_type, owner_value, for_test_msg, switch_type, switch_value, init_group_size, min_group_size):
    insert_load_sql = '''
        INSERT INTO `strategy` 
            (`server_id`, `server_ip`, `domain_key`, `resource_ids`, `owner_type`, `owner_value`, `for_test_msg`, `switch_type`, `switch_value`, `init_group_size`, `min_group_size`, `last_update_time`, `from_domains`, `remark`) 
        VALUES 
            ('%s', '%s', '%s', '%s', '%s', %s, %s, '%s', %s, %s, %s, '2015-03-22 16:28:00', NULL, NULL);
    '''
    try:
        resource_conn = mdb.get_resource_conn()
        #print insert_load_sql % (server_id, server_ip, domainkey, resource_ids, owner_type, owner_value, for_test_msg, switch_type, switch_value, init_group_size, min_group_size)
        row_info = mdb.exe_update_sql(resource_conn, insert_load_sql % (server_id, server_ip, domainkey, resource_ids, owner_type, owner_value, for_test_msg, switch_type, switch_value, init_group_size, min_group_size), False, True, False, False)
        print row_info
    except Exception,e:
        print e
        sys.exit()
Ejemplo n.º 7
0
def showstrategy():
    sql = '''
        select 
            st.server_id,st.domain_key,st.resource_ids,st.owner_type,st.owner_value,st.for_test_msg
        from 
            strategy st 
        where 
            st.domain_key = 'qqdomain' and st.owner_value not like '-%' and owner_type <> 'Common'
        order by 
            st.resource_ids 
    '''

    resource_conn = mdb.get_resource_conn()
    datas = list(mdb.exe_sql(resource_conn, sql, True, True))
    return datas
Ejemplo n.º 8
0
def showresource():
    sql = '''
	select 
		r.domains,group_concat(r.id) as rids, r.server_id, sum(to_index+1) - sum(from_index) as count
	from 
		resource r 
	group by 
		r.domains,r.server_id 
	order by 
        r.domains 
    '''
    
    try:
        resource_conn = mdb.get_resource_conn()
        loadinfo = mdb.exe_sql(resource_conn, sql, True, True)
        return loadinfo
    except Exception,e:
        print e
        sys.exit()
Ejemplo n.º 9
0
def showLoadInfo():
    sql = '''
	select 
		r.domains,group_concat(r.id) as rids
	from 
		resource r 
	where 
		r.id <> 796 and r.domains like 'load%%'
	group by 
		r.domains,r.server_id 
	order by r.domains 
    '''
    
    try:
        resource_conn = mdb.get_resource_conn()
        loadinfo = mdb.exe_sql(resource_conn, sql, True, True)
        return loadinfo
    except Exception,e:
        print e
        sys.exit()
Ejemplo n.º 10
0
def getLoadInfo(id):
    sql = '''
	select 
		r.domains,group_concat(r.id) as rids, r.server_id, sum(to_index+1) - sum(from_index) as count
	from 
		resource r 
	where 
		r.id <> 796 and r.domains = "load%s.com"
	group by 
		r.domains,r.server_id 
	order by r.domains 
    '''
    
    #print sql % (id)

    try:
        resource_conn = mdb.get_resource_conn()
        loadinfo = mdb.exe_sql(resource_conn, sql % id, True, True)
        return loadinfo
    except Exception,e:
        print e
        sys.exit()
Ejemplo n.º 11
0
def showshortstrategy():
    sql = '''
        select case st.resource_ids 
                when '764,776' then '通道1' 
                when '756,797' then '通道2' 
                when '781' then '通道3' 
                when '765,777' then '通道4' 
                when '747' then '通道6' 
                when '780' then '通道7' 
                when '782' then '通道8' 
                when '798' then '通道9' 
                end 'load', st.server_ip, st.owner_type, group_concat(st.owner_value) as client_list
        from 
            strategy st 
        where 
            st.domain_key = 'qqdomain' and owner_value <> '' and st.for_test_msg = 0 and st.owner_value not like '-%' 
        group by 
            st.resource_ids, st.owner_type
    '''
    resource_conn = mdb.get_resource_conn()
    datas = mdb.exe_sql(resource_conn, sql, True, True)
    return datas
Ejemplo n.º 12
0
    for_test_msg = args.for_test_msg

    flag = selectstg(domainkey, owner_value)
    if(flag):
        deloldstg(domainkey, owner_value)
    
    if args.resource_ids:
        rids = args.resource_ids
        rinfos = getresource(rids)
        for rinfo in rinfos:
            server_id = rinfo['server_id']
            server_ip = getServerIp(rinfo['server_id'])
            resource_ids = rinfo['rids']
            init_group_size = rinfo['count']
            try:
                resource_conn = mdb.get_resource_conn()
                insertnewstg(server_id, server_ip, domainkey, resource_ids, owner_type, owner_value, for_test_msg, 
                            switch_type, switch_value, init_group_size, min_group_size)
                print "Done! Add a new strategy at client_id: %s on %s " % (owner_value, domainkey)
            except Exception,e:
                print e
                sys.exit()
    elif args.load_id:
        load_id = args.load_id
        load_array = getLoadInfo(load_id)
        for load_list in load_array:
            try:
                resource_conn = mdb.get_resource_conn()
                server_id = load_list['server_id']
                server_ip = getServerIp(load_list['server_id'])
                resource_ids = load_list['rids']