def generateRandomLogEvent(self):
        """
          Creates some random event in the proper dictionary format for log events, and returns it.
        """

        # Get a random node, severity, and facility
        machineName = getRandomElement(self.weightedMachineNamesList)

        if machineName in self.badMachines:
            randomSeverity = getRandomElement(self.weightedSeverities)
            randomFacility = getRandomElement(self.weightedFacilities)
        else:
            randomSeverity = getRandomElement(self.severities)
            randomFacility = getRandomElement(self.facilities)

        # Generate a random ascii string
        randomLength = int(random() * 50)
        randomString = ''.join(choice(string.ascii_letters) for x in range(randomLength))

        logEvent = {
            'message': randomString,
            'severity': randomSeverity,
            'facility': randomFacility,
            'location': machineName,
            'timestamp': datetime.strftime(datetime.now(), self.TIMESTAMP_FORMAT)
        }

        return logEvent
Example #2
0
    def randomizeProperty(self, nodeName, propertyName, associatedData=None):
        """
            Randomizes a property for a given node, returning its new value
        """

        # rack1 will have low CPU & memory utilization
        if propertyName == "cpuUsage" and "machine1" in nodeName:
            return normalizeValue(self.nodeState[nodeName][propertyName] + getRandomElement(self.lowCpuUsageDelta))

        # rack3 will have high CPU utilization
        elif propertyName == "cpuUsage" and "machine3" in nodeName:
            return normalizeValue(self.nodeState[nodeName][propertyName] + getRandomElement(self.highCpuUsageDelta))

        if propertyName == "contextSwitchRate":
            return normalizeValue(self.nodeState[nodeName]["cpuUsage"] + numpy.random.normal(loc=0, scale=0.10))

        else:
            return RandomSimulator.randomizeProperty(self, nodeName, propertyName, associatedData)
    def __init__(self, machineNames, taskName, time):
        RandomSimulator.__init__(self, [])

        self.taskName = taskName

        numberOfMapJobs = 10
        self.map = []
        for i in xrange(0, numberOfMapJobs):
            mapJob = {
                'id': i,
                'name': "%s%s%d" % (self.taskName, "-mapJob", i),
                'start': time + 0,
                'duration': int(numpy.random.normal(loc=60, scale=5)),
                'location': getRandomElement(machineNames)
            }
            if mapJob['duration'] <= 0:
                mapJob['duration'] = 1
            mapJob['end'] = int(mapJob['start'] + mapJob['duration'])
            self.map.append(mapJob)

        numberOfReduceJobs = 10
        self.reduce = []
        for i in xrange(0, numberOfReduceJobs):
            reduceJob = {
                'id': numberOfMapJobs + i,
                'name': "%s%s%d" % (self.taskName, "-reduceJob", i),
                'start': time + int(numpy.random.normal(loc=60, scale=5)),
                'duration': int(numpy.random.normal(loc=60, scale=5)),
                'location': getRandomElement(machineNames)
            }
            if reduceJob['duration'] <= 0:
                reduceJob['duration'] = 1
            reduceJob['end'] = int(reduceJob['start'] + reduceJob['duration'])
            self.reduce.append(reduceJob)

        self.time = time
Example #4
0
    def addRandomStateChanges(self, stateChange):
        """
            randomly changes the state of various properties
        """

        # Randomly update between 0 and 1/2 of the usage statistics of the nodes
        # numberOfMachinesToUpdate = int(random() * len(self.machineNames) / 2.0) + 1
        numberOfMachinesToUpdate = len(self.machineNames)
        for nodeNum in xrange(0, numberOfMachinesToUpdate):
            nodeName = getRandomElement(self.machineNames)
            nodeInfo = stateChange[nodeName]

            # Update this node's cpu/memory/context-switch stats
            nodeInfo['cpuUsage'] = self.randomizeProperty(nodeName, 'cpuUsage')
            nodeInfo['memoryUsage'] = self.randomizeProperty(nodeName, 'memoryUsage')
            nodeInfo['contextSwitchRate'] = self.randomizeProperty(nodeName, 'contextSwitchRate')
Example #5
0
    def randomizeProperty(self, nodeName, propertyName, associatedData=None):
        """
            Randomizes a property for a given node, returning its new value
        """

        if propertyName == 'predictedSeverityProbabilities':
            return {
                'FATAL' : normalizeValue(self.nodeState[nodeName]['predictedSeverityProbabilities']['FATAL'] + getRandomElement(self.deltaMap['predictedFatal'])),
                'ERROR': normalizeValue(self.nodeState[nodeName]['predictedSeverityProbabilities']['ERROR'] + getRandomElement(self.deltaMap['predictedError'])),
                'WARN': normalizeValue(self.nodeState[nodeName]['predictedSeverityProbabilities']['WARN'] + getRandomElement(self.deltaMap['predictedWarn'])),
                'INFO': normalizeValue(self.nodeState[nodeName]['predictedSeverityProbabilities']['INFO'] + getRandomElement(self.deltaMap['predictedInfo']))
            }
        elif propertyName == 'health':
            return normalizeValue(self.nodeState[nodeName]['health'] + self.deltaMap['health'][associatedData['severity']])
        else:
            return normalizeValue(self.nodeState[nodeName][propertyName] + getRandomElement(self.deltaMap[propertyName]))
    def randomizeProperty(self, nodeName, propertyName, associatedData=None):
        """
            Randomizes a property for a given node, returning its new value
        """

        # the following machines will have poor health
        if nodeName in self.badMachines:
            if propertyName == "health":
                return normalizeValue(self.nodeState[nodeName][propertyName] + self.badNodeHealthDelta[associatedData['severity']])
            elif propertyName == "memoryUsage":
                return normalizeValue(self.nodeState[nodeName][propertyName] + getRandomElement(self.badNodeMemoryDelta))

        if propertyName == "memoryUsage":
            return normalizeValue(self.nodeState[nodeName][propertyName] + numpy.random.normal(loc=-0.025, scale=0.05))

        return RandomSimulator.randomizeProperty(self, nodeName, propertyName, associatedData)