def printSummary(self, request, detail=False):

        wqResult = self.getWQElementResultsByRequest(request)

        if wqResult is None:
            print("No WQ element exist for the status given")
            return
        print("### summary for %s ###" % request )
        print("  Priority: %s, available elements: %s " % (wqResult["Priority"], len(wqResult['Elements'])))

        sites = self.getPossibleSitesByRequest(request)
        print("  Possible sites to run: %s" % list(sites))

        higher = self.elementsWithHigherPriorityInSameSites(request)
        total = 0
        totalJobs = 0
        for request in higher:
            wqResult = higher[request]
            availableEle = wqResult.availableItems()
            if not availableEle:
                continue
            total += len(availableEle)
            wqAvailResult = WorkQueueElementResult(Elements=availableEle)
            totalJobs += wqAvailResult['Jobs']
            maxJobEle = wqAvailResult.getMaxJobElement()
            minJobEle = wqAvailResult.getMinJobElement()
            if detail:
                print("  Higher priority elements by request:")
                print("""%s: Priority: %s, available elements: %s, total jobs: %s,
                        max jobs: %s (element_id: %s), min jobs: %s (element_id: %s)""" % (
                        request, wqAvailResult["Priority"], availableEle, wqAvailResult['Jobs'],
                        maxJobEle["Jobs"], maxJobEle.id,
                        minJobEle["Jobs"], minJobEle.id))
        print("  Higher priority elements: %s, total available jobs: %s"  % (total, totalJobs))
Exemplo n.º 2
0
    def printSummary(self, request, detail=False):

        wqResult = self.getWQElementResultsByRequest(request)

        if wqResult is None:
            print("No WQ element exist for the status given")
            return
        print("### summary for %s ###" % request )
        print("  Priority: %s, available elements: %s " % (wqResult["Priority"], len(wqResult['Elements'])))

        sites = self.getPossibleSitesByRequest(request)
        print("  Possible sites to run: %s" % list(sites))

        higher = self.elementsWithHigherPriorityInSameSites(request)
        total = 0
        totalJobs = 0
        for request in higher:
            wqResult = higher[request]
            availableEle = wqResult.availableItems()
            if not availableEle:
                continue
            total += len(availableEle)
            wqAvailResult = WorkQueueElementResult(Elements=availableEle)
            totalJobs += wqAvailResult['Jobs']
            maxJobEle = wqAvailResult.getMaxJobElement()
            minJobEle = wqAvailResult.getMinJobElement()
            if detail:
                print("  Higher priority elements by request:")
                print("""%s: Priority: %s, available elements: %s, total jobs: %s,
                        max jobs: %s (element_id: %s), min jobs: %s (element_id: %s)""" % (
                        request, wqAvailResult["Priority"], availableEle, wqAvailResult['Jobs'],
                        maxJobEle["Jobs"], maxJobEle.id,
                        minJobEle["Jobs"], minJobEle.id))
        print("  Higher priority elements: %s, total available jobs: %s"  % (total, totalJobs))
Exemplo n.º 3
0
    def __init__(self, elements):
        self.elements = elements

        elementsByRequest = {}
        for ele in elements:
            elementsByRequest.setdefault(ele["RequestName"], [])
            elementsByRequest[ele["RequestName"]].append(ele)

        self.wqResultsByRequest = {}
        for reqName, wqElements in elementsByRequest.iteritems():
            self.wqResultsByRequest[reqName] = WorkQueueElementResult(Elements=wqElements)
Exemplo n.º 4
0
    def elementsWithHigherPriorityInSameSites(self,
                                              requestName,
                                              returnFormat="dict"):

        if requestName not in self.wqResultsByRequest:
            return None

        priority = self.wqResultsByRequest[requestName]['Priority']
        creationTime = self.wqResultsByRequest[requestName]['Elements'][0][
            'CreationTime']

        # this will include all the possible sites on the requests
        # TODO: when different blocks are located in different site it need to handled
        sites = self.getPossibleSitesByRequest(requestName)

        sortedElements = []
        for reqName in self.wqResultsByRequest:
            # skip the workflow
            if reqName == requestName:
                continue
            if self.wqResultsByRequest[reqName]['Priority'] >= priority:
                for element in self.wqResultsByRequest[reqName]['Elements']:
                    if element['CreationTime'] > creationTime:
                        continue
                    if len(sites) > 0:
                        possibleSites = element.possibleSites()
                        if len(set(possibleSites) & sites) > 0:
                            sortedElements.append(element)
                    else:
                        sortedElements.append(element)
        # sort elements to get them in priority first and timestamp order
        sortedElements.sort(key=lambda element: element['CreationTime'])
        sortedElements.sort(key=lambda x: x['Priority'], reverse=True)
        if returnFormat == "list":
            return sortedElements
        elif returnFormat == "dict":
            sortedByRequest = defaultdict(list)
            for ele in sortedElements:
                sortedByRequest[ele['RequestName']].append(ele)

            for request in sortedByRequest:
                sortedByRequest[request] = WorkQueueElementResult(
                    Elements=sortedByRequest[request])
            return sortedByRequest
    def elementsWithHigherPriorityInSameSites(self,
                                              requestName,
                                              returnFormat="dict"):

        if requestName not in self.wqResultsByRequest:
            return None

        priority = self.wqResultsByRequest[requestName]['Priority']
        creationTime = self.wqResultsByRequest[requestName]['Elements'][0][
            'CreationTime']

        sites = self.getPossibleSitesByRequest(requestName)

        sortedElements = []
        for reqName in self.wqResultsByRequest:
            # skip the workflow
            if reqName == requestName:
                continue
            if self.wqResultsByRequest[reqName]['Priority'] >= priority:
                for element in self.wqResultsByRequest[reqName]['Elements']:
                    if element['CreationTime'] > creationTime:
                        continue
                    if len(sites) > 0:
                        commonSites = possibleSites(element)
                        if len(set(commonSites) & sites) > 0:
                            sortedElements.append(element)
                    else:
                        sortedElements.append(element)
        # sort elements to get them in priority first and timestamp order
        sortedElements.sort(key=lambda element: element['CreationTime'])
        sortedElements.sort(key=lambda x: x['Priority'], reverse=True)
        if returnFormat == "list":
            return sortedElements
        elif returnFormat == "dict":
            sortedByRequest = defaultdict(list)
            for ele in sortedElements:
                sortedByRequest[ele['RequestName']].append(ele)

            for request in sortedByRequest:
                sortedByRequest[request] = WorkQueueElementResult(
                    Elements=sortedByRequest[request])
            return sortedByRequest