Esempio n. 1
0
    def initExperimentThree(self, req):
        vmNum = req.params.get('requireCount')

        if vmNum and isNumber(vmNum):
            rc = int(vmNum)

            TomcatInstanceUtil.deleteAllTestingInstance()

            azList = ['az1', 'az2', 'az3', 'az4']
            azLen = len(azList)
            for i in range(rc):
                TomcatInstanceUtil.createTomcatInstance(azName=azList[i % azLen])

            TomcatInstanceUtil.ensureAllUsingInstancesActive()

            for ipEnd in ipEndOfComputes:
                os.system('/home/sk/cloudEx/shellScript/initAllPMUtil.sh ' + str(ipEnd) + ' > /dev/null')

            # 清空与预测相关的数据
            clearAllData()
            PMCPUDBUtil.clearPMCPUTable()
            VMCPUDBUtil.clearVMCPUTable()

            return UsingInstancesDBUtil.getAllUsingInstancesInfo()
        else:
            result = errorResultJson('The Post Body Must be {requireCount:x} (ps:x must be number)')
        return result
Esempio n. 2
0
    def create(self, req):
        rc = req.params.get('requireCount')
        resetFlag = req.params.get('reset')
        if rc and isNumber(rc) and resetFlag and isNumber(resetFlag):
            rc = int(rc)
            resetFlag = int(resetFlag)

            if resetFlag:
                TomcatInstanceUtil.resetAllUsingInstances()

            uic = UsingInstancesDBUtil.getUsingInstancesCount()
            if rc > uic:
                needC = rc - uic
                while needC > 0:
                    TomcatInstanceUtil.createTomcatInstance()
                    needC -= 1
            elif rc < uic:
                deleteC = uic - rc
                TomcatInstanceUtil.deleteSpecifyNumberInstances(deleteC)

            TomcatInstanceUtil.ensureAllUsingInstancesActive()
            return UsingInstancesDBUtil.getAllUsingInstancesInfo()
        else:
            result = errorResultJson('The Post Body Must be {requireCount:x, reset:y} (ps:x must be number, reset must be 0 or 1)')
        return result
Esempio n. 3
0
    def initExperiment(self, req):
        check = 1

        try:
            token = req.headers['X-Auth-Token']
            if token != 'sk':
                check = 0

        except KeyError:
            check = 0

        if check:
            ExperimentInit().getInitialScheme()
            return UsingInstancesDBUtil.getAllUsingInstancesInfo()
        else:
            return errorResultJson('You are not allowed to do this!')
Esempio n. 4
0
    def periodPerformanceDataHandler2(self, req):
        minResponseTime = req.params.get('minResponseTime')
        avgResponseTime = req.params.get('avgResponseTime')
        maxResponseTime = req.params.get('maxResponseTime')
        totalRequestCount = req.params.get('totalRequestCount')
        breakSLACount = req.params.get('breakSLACount')
        jumpServer = req.params.get('jumpServer')
        infos = SampleUtil.getThreadInfosOverAllUsingInstances(jumpServer)
        avgCpuUtil = round(infos[0] / 100.0, 4)
        totalCalculation = round(infos[1] / 100.0, 4)
        avgMemoryUtil = round(SampleUtil.getAllUsingInstancesPeriodAVGMemoryUtil() / 100.0, 4)

        if not (isDecimal(minResponseTime) or isNumber(minResponseTime)) \
                or not (isDecimal(maxResponseTime) or isNumber(maxResponseTime)) \
                or not (isDecimal(avgResponseTime) or isNumber(avgResponseTime)) \
                or not isNumber(totalRequestCount) \
                or not isNumber(breakSLACount):
            return errorResultJson('Please pass the params correctly')
        elif avgCpuUtil == None or avgMemoryUtil == None or totalCalculation == None:
            raise Exception("can not get avgCpuUtil or avgMemoryUtil or totalCalculation data")
        else:
            minResponseTime = float(minResponseTime)
            avgResponseTime = float(avgResponseTime)
            maxResponseTime = float(maxResponseTime)
            totalRequestCount = int(totalRequestCount)
            breakSLACount = int(breakSLACount)

            # 确认periodNo
            periodNoDB = shelve.open(periodRecoderFile)
            periodNo = periodNoDB.get(periodRecoder, None)

            if not periodNo:
                periodNo = 1

            periodNoDB[periodRecoder] = periodNo + 1
            periodNoDB.close()

            # 计算breakSLAPercent
            breakSLAPercent = float(breakSLACount) / totalRequestCount
            breakSLAPercent = round(breakSLAPercent, 4)

            # 计算刚刚过去的这个周期的可用性
            placementTool = ACRCPlacementComponent()
            availabilityData = placementTool.calculateAvailability()

            # 得到刚刚过去这个周期的虚拟机数目
            vmNumbers = UsingInstancesDBUtil.getUsingInstancesCount()

            # 添加上个周期应该提供的虚拟机数目
            shouldVMNumbers = WorkloadVMMapDBUtil.getTargetVMsToSpecificWorkload(totalRequestCount)

            if periodNo == 1:
                ppVMNumbers = vmNumbers
                rpVMNumbers = 0
            else:
                provisionInfoDB = shelve.open(provisionInfoFile)
                ppVMNumbers = provisionInfoDB.get(predictProvisionVMNumbers, None)
                rpVMNumbers = provisionInfoDB.get(reactiveProvisionVMNumbers, None)

            # 添加performanceData
            performanceData = {'minResponseTime': minResponseTime, 'maxResponseTime': maxResponseTime,
                               'avgResponseTime': avgResponseTime, 'breakSLAPercent': breakSLAPercent,
                               'avgCpuUtil': avgCpuUtil, 'avgMemoryUtil': avgMemoryUtil,
                               'availability': availabilityData, 'vmNumbers': vmNumbers,
                               'shouldVMNumbers': shouldVMNumbers, 'predictProvisionVMNumbers': ppVMNumbers,
                               'reactiveProvisionVMNumbers': rpVMNumbers}
            PerformanceDBUtil.addPerformanceDataToSpecificPeriod(periodNo, performanceData)

            # 向数据库中添加workload信息
            if periodNo == 1:
                WorkloadDBUtil.addFirstPeriodRealWorkloadAndRealTotalCalculation(totalRequestCount, totalCalculation)
            else:
                WorkloadDBUtil.addRealWorkloadAndRealTotalCalculationToSpecificPeriod(periodNo, totalRequestCount,
                                                                                      totalCalculation)

            acrCtl = ACRController()
            acrCtl.autonomicPeriodHandler()

            TomcatInstanceUtil.ensureAllUsingInstancesActive()
            return UsingInstancesDBUtil.getAllUsingInstancesInfo()