コード例 #1
0
ファイル: FTS3Agent.py プロジェクト: DIRACGrid/DIRAC
  def __sendAccounting(ftsJob):
    """ prepare and send DataOperation to AccountingDB

        :param ftsJob: the FTS3Job from which we send the accounting info
    """

    dataOp = DataOperation()
    dataOp.setStartTime(fromString(ftsJob.submitTime))
    dataOp.setEndTime(fromString(ftsJob.lastUpdate))

    dataOp.setValuesFromDict(ftsJob.accountingDict)
    dataOp.delayedCommit()
コード例 #2
0
ファイル: FTS3Agent.py プロジェクト: hamzazafar/DIRAC
  def __sendAccounting(ftsJob):
    """ prepare and send DataOperation to AccountingDB

        :param ftsJob: the FTS3Job from which we send the accounting info
    """

    dataOp = DataOperation()
    dataOp.setStartTime(fromString(ftsJob.submitTime))
    dataOp.setEndTime(fromString(ftsJob.lastUpdate))

    dataOp.setValuesFromDict(ftsJob.accountingDict)
    dataOp.delayedCommit()
コード例 #3
0
ファイル: DataOperationSender.py プロジェクト: TaykYoku/DIRAC
class DataOperationSender:
    """
    class:: DataOperationSender
    It reads the MonitoringBackends option to decide whether send and commit data operation to either Accounting or Monitoring.
    """

    # Initialize the object so that the Reporters are created only once
    def __init__(self):
        monitoringType = "DataOperation"
        # Will use the `MonitoringBackends/Default` value as monitoring backend unless a flag for `MonitoringBackends/DataOperation` is set.
        self.monitoringOptions = Operations().getMonitoringBackends(
            monitoringType)
        if "Monitoring" in self.monitoringOptions:
            self.dataOperationReporter = MonitoringReporter(monitoringType)
        if "Accounting" in self.monitoringOptions:
            self.dataOp = DataOperation()

    def sendData(self,
                 baseDict,
                 commitFlag=False,
                 delayedCommit=False,
                 startTime=False,
                 endTime=False):
        """
        Sends the input to Monitoring or Acconting based on the monitoringOptions

        :param dict baseDict: contains a key/value pair
        :param bool commitFlag: decides whether to commit the record or not.
        :param bool delayedCommit: decides whether to commit the record with delay (only for sending to Accounting)
        :param int startTime: epoch time, start time of the plot
        :param int endTime: epoch time, end time of the plot
        """
        def sendMonitoring(self):
            baseDict["ExecutionSite"] = DIRAC.siteName()
            baseDict["Channel"] = baseDict["Source"] + "->" + baseDict[
                "Destination"]
            self.dataOperationReporter.addRecord(baseDict)
            if commitFlag:
                result = self.dataOperationReporter.commit()
                sLog.debug("Committing data operation to monitoring")
                if not result["OK"]:
                    sLog.error("Could not commit data operation to monitoring",
                               result["Message"])
                else:
                    sLog.debug("Done committing to monitoring")

        def sendAccounting(self):
            self.dataOp.setValuesFromDict(baseDict)
            if startTime:
                self.dataOp.setStartTime(startTime)
                self.dataOp.setEndTime(endTime)
            else:
                self.dataOp.setStartTime()
                self.dataOp.setEndTime()
            # Adding only to register
            if not commitFlag and not delayedCommit:
                return gDataStoreClient.addRegister(self.dataOp)

            # Adding to register and committing
            if commitFlag and not delayedCommit:
                gDataStoreClient.addRegister(self.dataOp)
                result = gDataStoreClient.commit()
                sLog.debug("Committing data operation to accounting")
                if not result["OK"]:
                    sLog.error("Could not commit data operation to accounting",
                               result["Message"])
                    return result
                sLog.debug("Done committing to accounting")
            # Only late committing
            else:
                result = self.dataOp.delayedCommit()
                if not result["OK"]:
                    sLog.error(
                        "Could not delay-commit data operation to accounting")
                    return result

            # Send data and commit prioritizing the first monitoring option in the list
            for backend in self.monitoringOptions:
                func = locals()[f"send{backend}"]
                res = func()
                if not res["OK"]:
                    return res

        return S_OK()

    # Call this method in order to commit all records added but not yet committed to Accounting and Monitoring
    def concludeSending(self):
        def commitAccounting():
            result = gDataStoreClient.commit()
            sLog.debug(
                "Concluding the sending and committing data operation to accounting"
            )
            if not result["OK"]:
                sLog.error("Could not commit data operation to accounting",
                           result["Message"])
            sLog.debug("Committing to accounting concluded")
            return result

        def commitMonitoring():
            result = self.dataOperationReporter.commit()
            sLog.debug("Committing data operation to monitoring")
            if not result["OK"]:
                sLog.error("Could not commit data operation to monitoring",
                           result["Message"])
            sLog.debug("Committing to monitoring concluded")
            return result

        # Commit data prioritizing first monitoring option in the list
        for backend in self.monitoringOptions:
            func = locals()[f"commit{backend}"]
            res = func()
            if not res["OK"]:
                return res
        return S_OK()