Ejemplo n.º 1
0
def determineTargets(targetList, alphas, deeperList):
    totalTraffic = long(sumTraffic(targetList) / numNonZero(targetList))
    newTargetList = []
    oldTargetList = []

    Globals.ASSIGNLOG.write('Threshold: ' + str(totalTraffic * Globals.MINTGTTHRESH) + " < x < " + str(totalTraffic * Globals.MAXTGTTHRESH) + '\n')
    for i in range(0, len(targetList)):
        if targetList[i]['traffic'] > (totalTraffic * Globals.MAXTGTTHRESH) or Alphas.sumAllAlphaAssign(alphas) < Alphas.sumAllAlphaTarget(alphas):
	    Globals.ASSIGNLOG.write('\t' + str(targetList[i]['ip']) + " Beyond Threshold " + str(targetList[i]['traffic']) + '\n')
	    # Beyond Threshold: Need more rules
            childList = IPRules.findChildRules(deeperList, targetList[i]['ip'], targetList[i]['wild'])
            for j, child in enumerate(childList):
                newTargetList.append(child)
            if childList != []:
	        oldTargetList.append(targetList[i])
	elif targetList[i]['traffic'] < (totalTraffic * Globals.MINTGTTHRESH):
	    Globals.ASSIGNLOG.write('\t' + str(targetList[i]['ip']) + " Under Threshold " + str(targetList[i]['traffic']) + '\n')
	    # Below Theshold: Reduce rules
	    (siblingIP, siblingWild) = IPRules.findSiblingRule(targetList[i])
	    siblingRule = IPRules.findMatch(targetList, siblingIP, siblingWild)
	    if siblingRule != []:
	        if siblingRule[0]['traffic'] <= (totalTraffic * Globals.MINTGTTHRESH) and \
                   targetList.index(siblingRule[0]) < i:
		    parentRule = IPRules.getParentRule(siblingRule[0])
		    Globals.ASSIGNLOG.write('\t' + str(parentRule['ip']) + '/' + str(parentRule['wild']) + ' combined\n')
	            newTargetList.append(parentRule)
		    oldTargetList.append(targetList[i])
		    oldTargetList.append(siblingRule[0])
	else:
	    Globals.ASSIGNLOG.write('\t' + str(targetList[i]['ip']) + " Fine Threshold " + str(targetList[i]['traffic']) + '\n')
	    if targetList[i]['replica'] == -1:
	        newTargetList.append(targetList[i])
		oldTargetList.append(targetList[i])

    return (oldTargetList, newTargetList)
Ejemplo n.º 2
0
def updateAlphas():
    oldTargetRules = copyTargets(Globals.TARGETRULES)      
    oldInstallRules = copyTargets(Globals.INSTALLEDRULES) 

    newAlphas = Alphas.getAlphas(Globals.ALPHAFILE)
    Globals.log.info("NEW ALPHAS " + str(newAlphas))
    Globals.log.info("OLD ALPHAS" + str(Globals.ALPHAS))
    (oldTargetList, newTargetList) = Bins.determineTargets(oldTargetRules, Globals.ALPHAS, oldInstallRules)
    (oldTargetList, newTargetList) = Bins.redistributeTargets(oldTargetRules, Globals.ALPHAS, newAlphas, oldTargetList, newTargetList)
#    Bins.printTargetList(newTargetList)
    totalAssignments = len(newTargetList)
    Globals.log.info("Total Assigns: " + str(totalAssignments))

    newAlphas = Alphas.distributeAlphas(newAlphas, Globals.ALPHAS, totalAssignments)
    Globals.log.info("DISTRIBUTE NEW ALPHAS " + str(newAlphas))
    newAlphas = Alphas.distributeEven(newAlphas, totalAssignments)
#    newAlphas = Alphas.distributeOld(newAlphas, Globals.ALPHAS, totalAssignments)
    Globals.log.info("DISTRIBUTE OLD ALPHAS " + str(newAlphas))
    newAlphas = Alphas.distributeRemaining(newAlphas, totalAssignments)
    Globals.log.info("REMAINING NEW ALPHAS " + str(newAlphas))
    Alphas.updateAlphas(newAlphas, oldTargetList)

    newTargetList = IPRules.assignReplicas(newAlphas, newTargetList)
    Bins.printTargetList(newTargetList)

    newRuleList = IPRules.getNewRules(Globals.TARGETRULES, newTargetList)
    IPRules.printRules(newRuleList)

#    (oldRules, newRules) = IPRules.redistributeRules(Globals.TARGETRULES, Globals.ALPHAS, newAlphas)
#    newRuleList.extend(newRules)

#    IPRules.updateAssigns(newRuleList, oldRules)
    IPRules.updateAssigns(newRuleList)
    Alphas.printAlphas(Globals.ALPHAS)

    return newRuleList