From 49afdbef9627e0a6335ae67ba269018216c05372 Mon Sep 17 00:00:00 2001 From: rupozzi Date: Thu, 19 May 2022 20:45:22 +0200 Subject: [PATCH] refactor: Changed name of Time module --- docs/source/conf.py | 4 +- .../Client/Types/BaseAccountingType.py | 6 +-- src/DIRAC/AccountingSystem/DB/AccountingDB.py | 44 ++++++++++--------- .../Service/DataStoreHandler.py | 18 ++++---- .../Service/ReportGeneratorHandler.py | 4 +- src/DIRAC/AccountingSystem/private/DBUtils.py | 4 +- src/DIRAC/ConfigurationSystem/Client/CSAPI.py | 2 +- .../private/ConfigurationData.py | 6 +-- .../private/Modificator.py | 2 +- .../scripts/dirac_admin_sort_cs_sites.py | 6 +-- src/DIRAC/Core/Base/AgentModule.py | 6 +-- src/DIRAC/Core/DISET/MessageClient.py | 4 +- src/DIRAC/Core/DISET/RequestHandler.py | 2 +- src/DIRAC/Core/DISET/ServiceReactor.py | 2 +- src/DIRAC/Core/DISET/private/Service.py | 8 ++-- src/DIRAC/Core/Security/VOMS.py | 9 ++-- .../Core/Tornado/Server/TornadoServer.py | 4 +- src/DIRAC/Core/Utilities/ElasticSearchDB.py | 10 ++--- src/DIRAC/Core/Utilities/MySQL.py | 2 +- src/DIRAC/Core/Utilities/NTP.py | 6 +-- .../Utilities/{Time.py => TimeUtilities.py} | 0 src/DIRAC/Core/Utilities/test/Test_Time.py | 2 +- .../DataManagementSystem/Agent/FTS3Agent.py | 2 +- .../Client/DataManager.py | 14 +++--- .../DataManagementSystem/Client/MetaQuery.py | 4 +- .../DirectoryMetadata/DirectoryMetadata.py | 2 +- .../FileMetadata/FileMetadata.py | 2 +- .../Client/SecurityLogClient.py | 2 +- .../DB/ComponentMonitoringDB.py | 4 +- .../Service/SystemAdministratorHandler.py | 4 +- .../scripts/dirac_admin_users_with_proxy.py | 4 +- src/DIRAC/Interfaces/API/Dirac.py | 4 +- .../scripts/dirac_wms_job_delete.py | 2 +- .../scripts/dirac_wms_job_get_output.py | 2 +- .../scripts/dirac_wms_job_status.py | 2 +- .../Service/MonitoringHandler.py | 8 ++-- .../Agent/RequestExecutingAgent.py | 4 +- .../private/OperationHandlerBase.py | 4 +- .../private/RequestTask.py | 20 ++++----- .../scripts/dirac_rss_query_db.py | 4 +- .../scripts/dirac_rss_query_dtcache.py | 26 +++++------ src/DIRAC/Resources/Cloud/KeystoneClient.py | 2 +- .../Computing/CloudComputingElement.py | 6 +-- .../Resources/Computing/ComputingElement.py | 2 +- .../Agent/StageMonitorAgent.py | 2 +- .../Agent/JobCleaningAgent.py | 6 +-- .../Agent/PilotStatusAgent.py | 10 +++-- .../Agent/SiteDirector.py | 2 +- .../Agent/StalledJobAgent.py | 2 +- .../Agent/StatesAccountingAgent.py | 6 +-- .../Client/JobReport.py | 6 +-- .../WorkloadManagementSystem/DB/JobDB.py | 12 ++--- .../DB/JobLoggingDB.py | 6 +-- .../DB/PilotAgentsDB.py | 10 ++--- .../DB/VirtualMachineDB.py | 8 ++-- .../Executor/JobScheduling.py | 2 +- .../JobWrapper/JobWrapper.py | 4 +- .../Service/JobMonitoringHandler.py | 6 +-- .../Service/JobStateUpdateHandler.py | 8 ++-- .../Service/PilotManagerHandler.py | 4 +- tests/Integration/Core/Test_MySQLDB.py | 6 +-- 61 files changed, 190 insertions(+), 185 deletions(-) rename src/DIRAC/Core/Utilities/{Time.py => TimeUtilities.py} (100%) diff --git a/docs/source/conf.py b/docs/source/conf.py index 960f9d30191..dbf21f6d7ab 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,7 +13,7 @@ # pylint: disable=invalid-name import logging -import datetime +from datetime import datetime import os import sys @@ -139,7 +139,7 @@ def setup(app): # General information about the project. project = "DIRAC" -copyright = "%s, DIRAC Project" % datetime.datetime.utcnow().year +copyright = "%s, DIRAC Project" % datetime.utcnow().year # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/src/DIRAC/AccountingSystem/Client/Types/BaseAccountingType.py b/src/DIRAC/AccountingSystem/Client/Types/BaseAccountingType.py index a2981213a5b..9d7582db4f7 100644 --- a/src/DIRAC/AccountingSystem/Client/Types/BaseAccountingType.py +++ b/src/DIRAC/AccountingSystem/Client/Types/BaseAccountingType.py @@ -4,7 +4,7 @@ import datetime from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Base.Client import Client from DIRAC.AccountingSystem.Client.DataStoreClient import gDataStoreClient @@ -124,11 +124,11 @@ def checkValues(self): return S_ERROR("Invalid values: %s" % ", ".join(errorList)) if not self.startTime: return S_ERROR("Start time has not been defined") - if not isinstance(self.startTime, Time._dateTimeType): + if not isinstance(self.startTime, TimeUtilities._dateTimeType): return S_ERROR("Start time is not a datetime object") if not self.endTime: return S_ERROR("End time has not been defined") - if not isinstance(self.endTime, Time._dateTimeType): + if not isinstance(self.endTime, TimeUtilities._dateTimeType): return S_ERROR("End time is not a datetime object") return self.checkRecord() diff --git a/src/DIRAC/AccountingSystem/DB/AccountingDB.py b/src/DIRAC/AccountingSystem/DB/AccountingDB.py index bc66cfe49c4..266399d7bdd 100644 --- a/src/DIRAC/AccountingSystem/DB/AccountingDB.py +++ b/src/DIRAC/AccountingSystem/DB/AccountingDB.py @@ -1,13 +1,13 @@ """ Frontend to MySQL DB AccountingDB """ -import datetime +from datetime import datetime import time import threading import random from DIRAC.Core.Base.DB import DB from DIRAC import S_OK, S_ERROR, gConfig -from DIRAC.Core.Utilities import List, ThreadSafe, Time, DEncode +from DIRAC.Core.Utilities import List, ThreadSafe, DEncode, TimeUtilities from DIRAC.Core.Utilities.Plotting.TypeLoader import TypeLoader from DIRAC.Core.Utilities.ThreadPool import ThreadPool @@ -49,9 +49,9 @@ def __init__(self, name="Accounting/AccountingDB", readOnly=False, parentLogger= self.__loadCatalogFromDB() self.__compactTime = datetime.time(hour=2, minute=random.randint(0, 59), second=random.randint(0, 59)) - lcd = datetime.datetime.utcnow() + lcd = datetime.utcnow() lcd.replace(hour=self.__compactTime.hour + 1, minute=0, second=0) - self.__lastCompactionEpoch = Time.toEpoch(lcd) + self.__lastCompactionEpoch = TimeUtilities.toEpoch(lcd) self.__registerTypes() @@ -69,14 +69,14 @@ def autoCompactDB(self): def __periodicAutoCompactDB(self): while self.autoCompact: - nct = datetime.datetime.utcnow() + nct = datetime.utcnow() if nct.hour >= self.__compactTime.hour: nct = nct + datetime.timedelta(days=1) nct = nct.replace( hour=self.__compactTime.hour, minute=self.__compactTime.minute, second=self.__compactTime.second ) self.log.info("Next db compaction", "will be at %s" % nct) - sleepTime = Time.toEpoch(nct) - Time.toEpoch() + sleepTime = TimeUtilities.toEpoch(nct) - TimeUtilities.toEpoch() time.sleep(sleepTime) self.compactBuckets() @@ -173,7 +173,7 @@ def loadPendingRecords(self): gSynchro.unlock() self.log.info("[PENDING] Loading pending records for insertion") pending = 0 - now = Time.toEpoch() + now = TimeUtilities.toEpoch() recordsPerSlot = self.getCSOption("RecordsPerSlot", 100) for typeName in self.dbCatalog: self.log.info("[PENDING] Checking %s" % typeName) @@ -534,7 +534,7 @@ def calculateBuckets(self, typeName, startTime, endTime, nowEpoch=False): the proportional part for each bucket """ if not nowEpoch: - nowEpoch = int(Time.toEpoch(datetime.datetime.utcnow())) + nowEpoch = int(TimeUtilities.toEpoch(datetime.utcnow())) bucketTimeLength = self.calculateBucketLengthForTime(typeName, nowEpoch, startTime) currentBucketStart = startTime - startTime % bucketTimeLength if startTime == endTime: @@ -566,7 +566,7 @@ def insertRecordBundleThroughQueue(self, recordsToQueue): if self.__readOnly: return S_ERROR("ReadOnly mode enabled. No modification allowed") recordsToProcess = [] - now = Time.toEpoch() + now = TimeUtilities.toEpoch() for record in recordsToQueue: typeName, startTime, endTime, valuesList = record result = self.__insertInQueueTable(typeName, startTime, endTime, valuesList) @@ -585,7 +585,8 @@ def insertRecordThroughQueue(self, typeName, startTime, endTime, valuesList): return S_ERROR("ReadOnly mode enabled. No modification allowed") self.log.info( "Adding record to queue", - "for type %s\n [%s -> %s]" % (typeName, Time.fromEpoch(startTime), Time.fromEpoch(endTime)), + "for type %s\n [%s -> %s]" + % (typeName, TimeUtilities.fromEpoch(startTime), TimeUtilities.fromEpoch(endTime)), ) if typeName not in self.dbCatalog: return S_ERROR("Type %s has not been defined in the db" % typeName) @@ -618,7 +619,9 @@ def insertRecordDirectly(self, typeName, startTime, endTime, valuesList): if self.__readOnly: return S_ERROR("ReadOnly mode enabled. No modification allowed") self.log.info( - "Adding record", "for type %s\n [%s -> %s]" % (typeName, Time.fromEpoch(startTime), Time.fromEpoch(endTime)) + "Adding record", + "for type %s\n [%s -> %s]" + % (typeName, TimeUtilities.fromEpoch(startTime), TimeUtilities.fromEpoch(endTime)), ) if typeName not in self.dbCatalog: return S_ERROR("Type %s has not been defined in the db" % typeName) @@ -667,7 +670,8 @@ def deleteRecord(self, typeName, startTime, endTime, valuesList): self.log.info( "Deleting record", - "for type %s\n [%s -> %s]" % (typeName, Time.fromEpoch(startTime), Time.fromEpoch(endTime)), + "for type %s\n [%s -> %s]" + % (typeName, TimeUtilities.fromEpoch(startTime), TimeUtilities.fromEpoch(endTime)), ) sqlValues = [] sqlValues.extend(valuesList) @@ -950,7 +954,7 @@ def retrieveBucketedData( ) if not retVal["OK"]: return retVal - nowEpoch = Time.toEpoch(datetime.datetime.utcnow()) + nowEpoch = TimeUtilities.toEpoch(datetime.utcnow()) bucketTimeLength = self.calculateBucketLengthForTime(typeName, nowEpoch, startTime) startTime = startTime - startTime % bucketTimeLength result = self.__queryType( @@ -1121,7 +1125,7 @@ def compactBuckets(self, typeFilter=False): else: self.__compactBucketsForType(typeName) self.log.info("[COMPACT] Compaction finished") - self.__lastCompactionEpoch = int(Time.toEpoch()) + self.__lastCompactionEpoch = int(TimeUtilities.toEpoch()) gSynchro.lock() try: if self.__doingCompaction: @@ -1169,7 +1173,7 @@ def __compactBucketsForType(self, typeName): """ Compact all buckets for a given type """ - nowEpoch = Time.toEpoch() + nowEpoch = TimeUtilities.toEpoch() # retVal = self.__startTransaction(connObj) # if not retVal[ 'OK' ]: # return retVal @@ -1181,7 +1185,7 @@ def __compactBucketsForType(self, typeName): nextBucketLength = self.dbBucketsLength[typeName][bPos + 1][1] self.log.info( "[COMPACT] Compacting data newer that %s with bucket size %s" - % (Time.fromEpoch(timeLimit), bucketLength) + % (TimeUtilities.fromEpoch(timeLimit), bucketLength) ) # Retrieve the data retVal = self.__selectForCompactBuckets(typeName, timeLimit, bucketLength, nextBucketLength) @@ -1218,7 +1222,7 @@ def __slowCompactBucketsForType(self, typeName): """ Compact all buckets for a given type """ - nowEpoch = Time.toEpoch() + nowEpoch = TimeUtilities.toEpoch() for bPos in range(len(self.dbBucketsLength[typeName]) - 1): self.log.info("[COMPACT] Query %d of %d" % (bPos, len(self.dbBucketsLength[typeName]) - 1)) secondsLimit = self.dbBucketsLength[typeName][bPos][0] @@ -1226,7 +1230,7 @@ def __slowCompactBucketsForType(self, typeName): timeLimit = (nowEpoch - nowEpoch % bucketLength) - secondsLimit self.log.info( "[COMPACT] Compacting data newer that %s with bucket size %s for %s" - % (Time.fromEpoch(timeLimit), bucketLength, typeName) + % (TimeUtilities.fromEpoch(timeLimit), bucketLength, typeName) ) querySize = 10000 previousRecordsSelected = querySize @@ -1235,7 +1239,7 @@ def __slowCompactBucketsForType(self, typeName): # Retrieve the data self.log.info( "[COMPACT] Retrieving buckets to compact newer that %s with size %s" - % (Time.fromEpoch(timeLimit), bucketLength) + % (TimeUtilities.fromEpoch(timeLimit), bucketLength) ) roundStartTime = time.time() result = self.__selectIndividualForCompactBuckets(typeName, timeLimit, bucketLength, querySize) @@ -1402,7 +1406,7 @@ def regenerateBuckets(self, typeName): sqlQueries = [] dateInclusiveConditions = [] countedField = "`%s`.`%s`" % (rawTableName, self.dbCatalog[typeName]["keys"][0]) - lastTime = Time.toEpoch() + lastTime = TimeUtilities.toEpoch() # Iterate for all ranges for iRange, iValue in enumerate(self.dbBucketsLength[typeName]): bucketTimeSpan = iValue[0] diff --git a/src/DIRAC/AccountingSystem/Service/DataStoreHandler.py b/src/DIRAC/AccountingSystem/Service/DataStoreHandler.py index 688ff8a1883..885a4a00f28 100644 --- a/src/DIRAC/AccountingSystem/Service/DataStoreHandler.py +++ b/src/DIRAC/AccountingSystem/Service/DataStoreHandler.py @@ -15,7 +15,7 @@ from DIRAC.AccountingSystem.DB.MultiAccountingDB import MultiAccountingDB from DIRAC.ConfigurationSystem.Client import PathFinder from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler from DIRAC.Core.Base.Client import Client @@ -133,8 +133,8 @@ def export_commit(self, typeName, startTime, endTime, valuesList): Add a record for a type """ setup = self.serviceInfoDict["clientSetup"] - startTime = int(Time.toEpoch(startTime)) - endTime = int(Time.toEpoch(endTime)) + startTime = int(TimeUtilities.toEpoch(startTime)) + endTime = int(TimeUtilities.toEpoch(endTime)) return self.__acDB.insertRecordThroughQueue( # pylint: disable=no-member setup, typeName, startTime, endTime, valuesList ) @@ -159,8 +159,8 @@ def export_commitRegisters(self, entriesList): return S_ERROR("Unexpected type in report") records = [] for entry in entriesList: - startTime = int(Time.toEpoch(entry[1])) - endTime = int(Time.toEpoch(entry[2])) + startTime = int(TimeUtilities.toEpoch(entry[1])) + endTime = int(TimeUtilities.toEpoch(entry[2])) self.log.debug("inserting", entry) records.append((setup, entry[0], startTime, endTime, entry[3])) return self.__acDB.insertRecordBundleThroughQueue(records) @@ -186,8 +186,8 @@ def export_remove(self, typeName, startTime, endTime, valuesList): Remove a record for a type """ setup = self.serviceInfoDict["clientSetup"] - startTime = int(Time.toEpoch(startTime)) - endTime = int(Time.toEpoch(endTime)) + startTime = int(TimeUtilities.toEpoch(startTime)) + endTime = int(TimeUtilities.toEpoch(endTime)) return self.__acDB.deleteRecord(setup, typeName, startTime, endTime, valuesList) # pylint: disable=no-member types_removeRegisters = [list] @@ -206,8 +206,8 @@ def export_removeRegisters(self, entriesList): return S_ERROR("%s field in the records should be %s" % (i, expectedTypes[i])) ok = 0 for entry in entriesList: - startTime = int(Time.toEpoch(entry[1])) - endTime = int(Time.toEpoch(entry[2])) + startTime = int(TimeUtilities.toEpoch(entry[1])) + endTime = int(TimeUtilities.toEpoch(entry[2])) record = entry[3] result = self.__acDB.deleteRecord(setup, entry[0], startTime, endTime, record) # pylint: disable=no-member if not result["OK"]: diff --git a/src/DIRAC/AccountingSystem/Service/ReportGeneratorHandler.py b/src/DIRAC/AccountingSystem/Service/ReportGeneratorHandler.py index b86777564b9..465bc13e025 100644 --- a/src/DIRAC/AccountingSystem/Service/ReportGeneratorHandler.py +++ b/src/DIRAC/AccountingSystem/Service/ReportGeneratorHandler.py @@ -11,7 +11,7 @@ from DIRAC import S_OK, S_ERROR, rootPath, gConfig, gLogger from DIRAC.Core.Utilities.File import mkDir -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.AccountingSystem.DB.MultiAccountingDB import MultiAccountingDB from DIRAC.Core.Utilities.Plotting import gDataCache from DIRAC.AccountingSystem.private.MainReporter import MainReporter @@ -94,7 +94,7 @@ def __checkPlotRequest(self, reportRequest): % (key, str(type(reportRequest[key])), str(self.__reportRequestDict[key])) ) if key in ("startTime", "endTime"): - reportRequest[key] = int(Time.toEpoch(reportRequest[key])) + reportRequest[key] = int(TimeUtilities.toEpoch(reportRequest[key])) return S_OK(reportRequest) diff --git a/src/DIRAC/AccountingSystem/private/DBUtils.py b/src/DIRAC/AccountingSystem/private/DBUtils.py index b0bf6e022bd..37dd1e9ee3d 100644 --- a/src/DIRAC/AccountingSystem/private/DBUtils.py +++ b/src/DIRAC/AccountingSystem/private/DBUtils.py @@ -1,6 +1,6 @@ """ Class that collects utilities used in Accounting and Monitoring systems """ -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities class DBUtils(object): @@ -63,7 +63,7 @@ def _getBins(self, typeName, startTime, endTime): return self._acDB.calculateBuckets(self._setup, typeName, startTime, endTime) def _getBucketLengthForTime(self, typeName, momentEpoch): - nowEpoch = Time.toEpoch() + nowEpoch = TimeUtilities.toEpoch() return self._acDB.calculateBucketLengthForTime(self._setup, typeName, nowEpoch, momentEpoch) def _spanToGranularity(self, granularity, bucketsData): diff --git a/src/DIRAC/ConfigurationSystem/Client/CSAPI.py b/src/DIRAC/ConfigurationSystem/Client/CSAPI.py index 3db46d20672..982c50da963 100644 --- a/src/DIRAC/ConfigurationSystem/Client/CSAPI.py +++ b/src/DIRAC/ConfigurationSystem/Client/CSAPI.py @@ -7,7 +7,7 @@ from DIRAC import gLogger, gConfig, S_OK, S_ERROR from DIRAC.ConfigurationSystem.Client.ConfigurationClient import ConfigurationClient -from DIRAC.Core.Utilities import List, Time +from DIRAC.Core.Utilities import List, TimeUtilities from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error from DIRAC.Core.Security import Locations from DIRAC.ConfigurationSystem.private.Modificator import Modificator diff --git a/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py b/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py index 919e8c638c5..c586e9c698e 100755 --- a/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py +++ b/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py @@ -10,7 +10,7 @@ from diraccfg import CFG from DIRAC.Core.Utilities.File import mkDir -from DIRAC.Core.Utilities import List, Time +from DIRAC.Core.Utilities import List, TimeUtilities from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR from DIRAC.Core.Utilities.LockRing import LockRing from DIRAC.FrameworkSystem.Client.Logger import gLogger @@ -198,7 +198,7 @@ def deleteOptionInCFG(self, path, cfg=False): self.sync() def generateNewVersion(self): - self.setVersion(Time.toString()) + self.setVersion(TimeUtilities.toString()) self.sync() gLogger.info("Generated new version %s" % self.getVersion()) @@ -336,7 +336,7 @@ def dumpRemoteCFGToFile(self, fileName): def __backupCurrentConfiguration(self, backupName): configurationFilename = "%s.cfg" % self.getName() configurationFile = os.path.join(DIRAC.rootPath, "etc", configurationFilename) - today = Time.date() + today = TimeUtilities.date() backupPath = os.path.join(self.getBackupDir(), str(today.year), "%02d" % today.month) mkDir(backupPath) backupFile = os.path.join(backupPath, configurationFilename.replace(".cfg", ".%s.zip" % backupName)) diff --git a/src/DIRAC/ConfigurationSystem/private/Modificator.py b/src/DIRAC/ConfigurationSystem/private/Modificator.py index 43fb3fdc28d..4cfb8e75b38 100755 --- a/src/DIRAC/ConfigurationSystem/private/Modificator.py +++ b/src/DIRAC/ConfigurationSystem/private/Modificator.py @@ -5,7 +5,7 @@ import datetime from diraccfg import CFG -from DIRAC.Core.Utilities import List, Time +from DIRAC.Core.Utilities import List, TimeUtilities from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.Core.Security.ProxyInfo import getProxyInfo diff --git a/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py b/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py index 5aeece89d0f..b2babeda99a 100755 --- a/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py +++ b/src/DIRAC/ConfigurationSystem/scripts/dirac_admin_sort_cs_sites.py @@ -11,14 +11,14 @@ $ dirac-admin-sort-cs-sites -C CLOUDS DIRAC sort site names by country postfix in '/Resources/Sites/CLOUDS' and '/Resources/Sites/DIRAC' subsection """ -import datetime +from datetime import datetime from DIRAC import gLogger, exit as DIRACExit from DIRAC.Core.Base.Script import Script from DIRAC.Core.Security.ProxyInfo import getProxyInfo from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getPropertiesForGroup from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI -from DIRAC.Core.Utilities.Time import toString +from DIRAC.Core.Utilities.TimeUtilities import toString global SORTBYNAME, REVERSE SORTBYNAME = True @@ -113,7 +113,7 @@ def main(): gLogger.notice("Nothing to do, site names are already sorted") DIRACExit(0) - timestamp = toString(datetime.datetime.utcnow()) + timestamp = toString(datetime.utcnow()) stamp = "Site names are sorted by %s script at %s" % (Script.scriptName, timestamp) cs.setOptionComment("/Resources/Sites", stamp) diff --git a/src/DIRAC/Core/Base/AgentModule.py b/src/DIRAC/Core/Base/AgentModule.py index 83dfe64a755..e1ce7ce99ea 100644 --- a/src/DIRAC/Core/Base/AgentModule.py +++ b/src/DIRAC/Core/Base/AgentModule.py @@ -15,7 +15,7 @@ import DIRAC from DIRAC import S_OK, S_ERROR, gConfig, gLogger, rootPath from DIRAC.Core.Utilities.File import mkDir -from DIRAC.Core.Utilities import Time, MemStat, Network +from DIRAC.Core.Utilities import MemStat, Network, TimeUtilities from DIRAC.Core.Utilities.Shifter import setupShifterProxyInEnv from DIRAC.Core.Utilities.ReturnValues import isReturnStructure from DIRAC.ConfigurationSystem.Client import PathFinder @@ -227,7 +227,7 @@ def am_checkStopAgentFile(self): def am_createStopAgentFile(self): try: with open(self.am_getStopAgentFile(), "w") as fd: - fd.write("Dirac site agent Stopped at %s" % Time.toString()) + fd.write("Dirac site agent Stopped at %s" % TimeUtilities.toString()) except Exception: pass @@ -371,7 +371,7 @@ def am_go(self): self.activityMonitoringReporter.addRecord( { "AgentName": self.agentName, - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "Host": Network.getFQDN(), "MemoryUsage": mem, "CpuPercentage": cpuPercentage, diff --git a/src/DIRAC/Core/DISET/MessageClient.py b/src/DIRAC/Core/DISET/MessageClient.py index 01a08b339c0..23810cd17be 100755 --- a/src/DIRAC/Core/DISET/MessageClient.py +++ b/src/DIRAC/Core/DISET/MessageClient.py @@ -5,7 +5,7 @@ from DIRAC.Core.DISET.private.BaseClient import BaseClient from DIRAC.Core.DISET.private.MessageBroker import getGlobalMessageBroker from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, isReturnStructure -from DIRAC.Core.Utilities import Network, Time +from DIRAC.Core.Utilities import Network, TimeUtilities from DIRAC.FrameworkSystem.Client.Logger import gLogger gMsgSync = Synchronizer() @@ -25,7 +25,7 @@ def _initialize(self): self.__specialCallbacks = {"drop": [], "msg": []} def __generateUniqueClientName(self): - hashStr = ":".join((Time.toString(), str(random.random()), Network.getFQDN(), gLogger.getName())) + hashStr = ":".join((TimeUtilities.toString(), str(random.random()), Network.getFQDN(), gLogger.getName())) hexHash = md5(hashStr.encode()).hexdigest() return hexHash diff --git a/src/DIRAC/Core/DISET/RequestHandler.py b/src/DIRAC/Core/DISET/RequestHandler.py index 3a173b4a2df..98f9250851d 100755 --- a/src/DIRAC/Core/DISET/RequestHandler.py +++ b/src/DIRAC/Core/DISET/RequestHandler.py @@ -8,7 +8,7 @@ from DIRAC.Core.DISET.private.FileHelper import FileHelper from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, isReturnStructure -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.ConfigurationSystem.Client.Config import gConfig from DIRAC.FrameworkSystem.Client.Logger import gLogger from DIRAC.Core.Security.Properties import CS_ADMINISTRATOR diff --git a/src/DIRAC/Core/DISET/ServiceReactor.py b/src/DIRAC/Core/DISET/ServiceReactor.py index 091170fd64c..f2d93d637fb 100644 --- a/src/DIRAC/Core/DISET/ServiceReactor.py +++ b/src/DIRAC/Core/DISET/ServiceReactor.py @@ -30,7 +30,7 @@ from DIRAC.Core.DISET.private.Service import Service from DIRAC.Core.DISET.private.GatewayService import GatewayService from DIRAC.Core.DISET.RequestHandler import RequestHandler -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Base.private.ModuleLoader import ModuleLoader from DIRAC.Core.DISET.private.Protocols import gProtocolDict from DIRAC.ConfigurationSystem.Client.Helpers import Registry diff --git a/src/DIRAC/Core/DISET/private/Service.py b/src/DIRAC/Core/DISET/private/Service.py index e69250faf60..a0efd4245dc 100644 --- a/src/DIRAC/Core/DISET/private/Service.py +++ b/src/DIRAC/Core/DISET/private/Service.py @@ -23,7 +23,7 @@ from DIRAC.Core.DISET.private.MessageBroker import MessageBroker, MessageSender from DIRAC.Core.DISET.AuthManager import AuthManager from DIRAC.Core.DISET.RequestHandler import getServiceOption -from DIRAC.Core.Utilities import Time, MemStat, Network +from DIRAC.Core.Utilities import MemStat, Network, TimeUtilities from DIRAC.Core.Utilities.DErrno import ENOAUTH from DIRAC.Core.Utilities.ReturnValues import isReturnStructure from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler @@ -259,7 +259,7 @@ def __reportActivity(self): percentage = self.__endReportToMonitoring(initialWallTime, initialCPUTime) self.activityMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "Host": Network.getFQDN(), "ServiceName": "_".join(self._name.split("/")), "Location": self._cfg.getURL(), @@ -566,7 +566,7 @@ def _executeAction(self, trid, proposalTuple, handlerObj): if self.activityMonitoring: self.activityMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "Host": Network.getFQDN(), "ServiceName": "_".join(self._name.split("/")), "Location": self._cfg.getURL(), @@ -592,7 +592,7 @@ def _mbReceivedMsg(self, trid, msgObj): if self.activityMonitoring and response["OK"]: self.activityMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "Host": Network.getFQDN(), "ServiceName": "_".join(self._name.split("/")), "Location": self._cfg.getURL(), diff --git a/src/DIRAC/Core/Security/VOMS.py b/src/DIRAC/Core/Security/VOMS.py index 2374981db63..ae452f2aa18 100644 --- a/src/DIRAC/Core/Security/VOMS.py +++ b/src/DIRAC/Core/Security/VOMS.py @@ -6,7 +6,6 @@ import tempfile import shlex import shutil -import datetime from DIRAC import S_OK, S_ERROR, gConfig, rootPath, gLogger from DIRAC.Core.Utilities import DErrno @@ -14,7 +13,7 @@ from DIRAC.Core.Security.BaseSecurity import BaseSecurity from DIRAC.Core.Security.X509Chain import X509Chain # pylint: disable=import-error from DIRAC.Core.Utilities.Subprocess import shellCall -from DIRAC.Core.Utilities import List, Time, Os +from DIRAC.Core.Utilities import List, Os class VOMS(BaseSecurity): @@ -132,11 +131,11 @@ def getVOMSProxyInfo(self, proxy, option=False): data = res["Value"] if option == "actimeleft": - now = datetime.datetime.utcnow() + now = datetime.utcnow() left = data["notAfter"] - now return S_OK("%d\n" % left.total_seconds()) if option == "timeleft": - now = datetime.datetime.utcnow() + now = datetime.utcnow() left = proxyDict["chain"].getNotAfterDate()["Value"] - now return S_OK("%d\n" % left.total_seconds()) if option == "identity": @@ -171,7 +170,7 @@ def getVOMSProxyInfo(self, proxy, option=False): lines.append("attribute : %s" % fqan) if "attribute" in data: lines.append("attribute : %s" % data["attribute"]) - now = datetime.datetime.utcnow() + now = datetime.utcnow() left = (data["notAfter"] - now).total_seconds() h = int(left / 3600) m = int(left / 60) - h * 60 diff --git a/src/DIRAC/Core/Tornado/Server/TornadoServer.py b/src/DIRAC/Core/Tornado/Server/TornadoServer.py index 0b496c03120..20ed1d66c2d 100644 --- a/src/DIRAC/Core/Tornado/Server/TornadoServer.py +++ b/src/DIRAC/Core/Tornado/Server/TornadoServer.py @@ -23,7 +23,7 @@ import DIRAC from DIRAC import gConfig, gLogger, S_OK from DIRAC.Core.Security import Locations -from DIRAC.Core.Utilities import MemStat, Time, Network +from DIRAC.Core.Utilities import MemStat, Network, TimeUtilities from DIRAC.Core.Tornado.Server.HandlerManager import HandlerManager from DIRAC.ConfigurationSystem.Client import PathFinder from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations @@ -244,7 +244,7 @@ def __reportToMonitoring(self, responseTime): # Send record to Monitoring self.activityMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "Host": Network.getFQDN(), "ServiceName": "Tornado", "MemoryUsage": self.__report[2], diff --git a/src/DIRAC/Core/Utilities/ElasticSearchDB.py b/src/DIRAC/Core/Utilities/ElasticSearchDB.py index 7e79fec1f0a..85de6647af7 100644 --- a/src/DIRAC/Core/Utilities/ElasticSearchDB.py +++ b/src/DIRAC/Core/Utilities/ElasticSearchDB.py @@ -23,7 +23,7 @@ from elasticsearch.helpers import BulkIndexError, bulk from DIRAC import gLogger, S_OK, S_ERROR -from DIRAC.Core.Utilities import Time, DErrno +from DIRAC.Core.Utilities import DErrno, TimeUtilities from DIRAC.FrameworkSystem.Client.BundleDeliveryClient import BundleDeliveryClient @@ -59,7 +59,7 @@ def generateDocs(data, withTimeStamp=True): sLog.warn("timestamp is not given") # if the timestamp is not provided, we use the current utc time. - timestamp = doc.get("timestamp", int(Time.toEpoch())) + timestamp = doc.get("timestamp", int(TimeUtilities.toEpoch())) try: if isinstance(timestamp, datetime): doc["timestamp"] = int(timestamp.strftime("%s")) * 1000 @@ -71,7 +71,7 @@ def generateDocs(data, withTimeStamp=True): except (TypeError, ValueError) as e: # in case we are not able to convert the timestamp to epoch time.... sLog.error("Wrong timestamp", e) - doc["timestamp"] = int(Time.toEpoch()) * 1000 + doc["timestamp"] = int(TimeUtilities.toEpoch()) * 1000 sLog.debug("yielding %s" % doc) yield doc @@ -453,8 +453,8 @@ def getUniqueValue(self, indexName, key, orderBy=False): timeFilter = self._Q( "range", timestamp={ - "lte": int(Time.toEpoch(endDate)) * 1000, - "gte": int(Time.toEpoch(startDate)) * 1000, + "lte": int(TimeUtilities.toEpoch(endDate)) * 1000, + "gte": int(TimeUtilities.toEpoch(startDate)) * 1000, }, ) query = query.filter("bool", must=timeFilter) diff --git a/src/DIRAC/Core/Utilities/MySQL.py b/src/DIRAC/Core/Utilities/MySQL.py index 844e3a82bc5..4654f855f7c 100755 --- a/src/DIRAC/Core/Utilities/MySQL.py +++ b/src/DIRAC/Core/Utilities/MySQL.py @@ -153,7 +153,7 @@ from DIRAC import gLogger from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Utilities.Time import fromString +from DIRAC.Core.Utilities.TimeUtilities import fromString from DIRAC.Core.Utilities import DErrno gInstancesCount = 0 diff --git a/src/DIRAC/Core/Utilities/NTP.py b/src/DIRAC/Core/Utilities/NTP.py index ae4a6142a7a..792c0d03743 100644 --- a/src/DIRAC/Core/Utilities/NTP.py +++ b/src/DIRAC/Core/Utilities/NTP.py @@ -1,7 +1,7 @@ from socket import socket, AF_INET, SOCK_DGRAM import struct import time as time -import datetime +from datetime import datetime from DIRAC import S_OK, S_ERROR TIME1970 = 2208988800 @@ -28,7 +28,7 @@ def getNTPUTCTime(serverList=None, retries=2): if data: myTime = struct.unpack("!12I", data)[10] myTime -= TIME1970 - return S_OK(datetime.datetime(*time.gmtime(myTime)[:6])) + return S_OK(datetime(*time.gmtime(myTime)[:6])) return S_ERROR("Could not get NTP time") @@ -36,5 +36,5 @@ def getClockDeviation(serverList=None): result = getNTPUTCTime(serverList) if not result["OK"]: return result - td = datetime.datetime.utcnow() - result["Value"] + td = datetime.utcnow() - result["Value"] return S_OK(abs(td.days * 86400 + td.seconds)) diff --git a/src/DIRAC/Core/Utilities/Time.py b/src/DIRAC/Core/Utilities/TimeUtilities.py similarity index 100% rename from src/DIRAC/Core/Utilities/Time.py rename to src/DIRAC/Core/Utilities/TimeUtilities.py diff --git a/src/DIRAC/Core/Utilities/test/Test_Time.py b/src/DIRAC/Core/Utilities/test/Test_Time.py index 36789748e6b..fd696ebcf40 100755 --- a/src/DIRAC/Core/Utilities/test/Test_Time.py +++ b/src/DIRAC/Core/Utilities/test/Test_Time.py @@ -4,7 +4,7 @@ import unittest # sut -from DIRAC.Core.Utilities.Time import timeThis +from DIRAC.Core.Utilities.TimeUtilities import timeThis class logClass(object): diff --git a/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py b/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py index 04c293550de..4c8239e06e8 100644 --- a/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py +++ b/src/DIRAC/DataManagementSystem/Agent/FTS3Agent.py @@ -29,7 +29,7 @@ from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.DErrno import cmpError from DIRAC.Core.Utilities.DictCache import DictCache -from DIRAC.Core.Utilities.Time import fromString +from DIRAC.Core.Utilities.TimeUtilities import fromString from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getFTS3ServerDict from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations as opHelper from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername diff --git a/src/DIRAC/DataManagementSystem/Client/DataManager.py b/src/DIRAC/DataManagementSystem/Client/DataManager.py index 06b14097a1f..efc06e79c0a 100644 --- a/src/DIRAC/DataManagementSystem/Client/DataManager.py +++ b/src/DIRAC/DataManagementSystem/Client/DataManager.py @@ -20,7 +20,7 @@ import DIRAC from DIRAC import S_OK, S_ERROR, gLogger, gConfig from DIRAC.Core.Utilities import DErrno -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.Adler import fileAdler, compareAdler from DIRAC.Core.Utilities.File import makeGuid, getSize from DIRAC.Core.Utilities.List import randomize, breakListIntoChunks @@ -539,7 +539,7 @@ def putAndRegister(self, lfn, fileName, diracSE, guid=None, path=None, checksum= failed = {} ########################################################## # Perform the put here. - startTime = datetime.datetime.utcnow() + startTime = datetime.utcnow() transferStartTime = time.time() res = returnSingleResult(storageElement.putFile(fileDict)) putTime = time.time() - transferStartTime @@ -555,7 +555,7 @@ def putAndRegister(self, lfn, fileName, diracSE, guid=None, path=None, checksum= accountingDict["TransferOK"] = 0 accountingDict["FinalStatus"] = "Failed" sendingResult = self.dataOpSender.sendData( - accountingDict, commitFlag=True, startTime=startTime, endTime=datetime.datetime.utcnow() + accountingDict, commitFlag=True, startTime=startTime, endTime=datetime.utcnow() ) log.verbose("Committing data operation") @@ -1416,14 +1416,14 @@ def __removeCatalogReplica(self, replicaTuples): """ log = self.log.getSubLogger("__removeCatalogReplica") - startTime = datetime.datetime.utcnow() + startTime = datetime.utcnow() registrationStartTime = time.time() # HACK! replicaDict = {} for lfn, pfn, se in replicaTuples: replicaDict[lfn] = {"SE": se, "PFN": pfn} res = self.fileCatalog.removeReplica(replicaDict) - endTime = datetime.datetime.utcnow() + endTime = datetime.utcnow() accountingDict = _initialiseAccountingDict("removeCatalogReplica", "", len(replicaTuples)) accountingDict["RegistrationTime"] = time.time() - registrationStartTime @@ -1477,13 +1477,13 @@ def __removePhysicalReplica(self, storageElementName, lfnsToRemove, replicaDict= log.verbose(errStr, "%s %s" % (storageElementName, res["Message"])) return S_ERROR("%s %s" % (errStr, res["Message"])) - startTime = datetime.datetime.utcnow() + startTime = datetime.utcnow() transferStartTime = time.time() lfnsToRemove = list(lfnsToRemove) ret = storageElement.getFileSize(lfnsToRemove, replicaDict=replicaDict) deletedSizes = ret.get("Value", {}).get("Successful", {}) res = storageElement.removeFile(lfnsToRemove, replicaDict=replicaDict) - endTime = datetime.datetime.utcnow() + endTime = datetime.utcnow() accountingDict = _initialiseAccountingDict("removePhysicalReplica", storageElementName, len(lfnsToRemove)) accountingDict["TransferTime"] = time.time() - transferStartTime diff --git a/src/DIRAC/DataManagementSystem/Client/MetaQuery.py b/src/DIRAC/DataManagementSystem/Client/MetaQuery.py index eb6b5cd3e1c..85fcb03fb1c 100644 --- a/src/DIRAC/DataManagementSystem/Client/MetaQuery.py +++ b/src/DIRAC/DataManagementSystem/Client/MetaQuery.py @@ -8,7 +8,7 @@ """ Utilities for managing metadata based queries """ from DIRAC import S_OK, S_ERROR -import DIRAC.Core.Utilities.Time as Time +import DIRAC.Core.Utilities.TimeUtilities as TimeUtilities import json @@ -187,7 +187,7 @@ def getTypedValue(value, mtype): elif mtype[0:5].lower() == "float": return float(value) elif mtype[0:4].lower() == "date": - return Time.fromString(value) + return TimeUtilities.fromString(value) else: return value diff --git a/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/DirectoryMetadata/DirectoryMetadata.py b/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/DirectoryMetadata/DirectoryMetadata.py index bce3fc1ee79..481e0e3364c 100644 --- a/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/DirectoryMetadata/DirectoryMetadata.py +++ b/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/DirectoryMetadata/DirectoryMetadata.py @@ -4,7 +4,7 @@ import six import os from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Utilities.Time import queryTime +from DIRAC.Core.Utilities.TimeUtilities import queryTime class DirectoryMetadata(object): diff --git a/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/FileMetadata/FileMetadata.py b/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/FileMetadata/FileMetadata.py index 540588a3414..9205eef2be4 100644 --- a/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/FileMetadata/FileMetadata.py +++ b/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/FileMetadata/FileMetadata.py @@ -2,7 +2,7 @@ """ import six from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Utilities.Time import queryTime +from DIRAC.Core.Utilities.TimeUtilities import queryTime from DIRAC.Core.Utilities.List import intListToString from DIRAC.DataManagementSystem.Client.MetaQuery import ( FILE_STANDARD_METAKEYS, diff --git a/src/DIRAC/FrameworkSystem/Client/SecurityLogClient.py b/src/DIRAC/FrameworkSystem/Client/SecurityLogClient.py index e2add200e9d..62986d3cf9e 100644 --- a/src/DIRAC/FrameworkSystem/Client/SecurityLogClient.py +++ b/src/DIRAC/FrameworkSystem/Client/SecurityLogClient.py @@ -5,7 +5,7 @@ from DIRAC import gLogger, gConfig from DIRAC.Core.Base.Client import Client -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler diff --git a/src/DIRAC/FrameworkSystem/DB/ComponentMonitoringDB.py b/src/DIRAC/FrameworkSystem/DB/ComponentMonitoringDB.py index 1f6e0d2f50c..067a6e90f90 100755 --- a/src/DIRAC/FrameworkSystem/DB/ComponentMonitoringDB.py +++ b/src/DIRAC/FrameworkSystem/DB/ComponentMonitoringDB.py @@ -5,7 +5,7 @@ from DIRAC import gConfig, S_OK, S_ERROR from DIRAC.Core.Base.DB import DB -from DIRAC.Core.Utilities import Time, Network +from DIRAC.Core.Utilities import Network, TimeUtilities from DIRAC.ConfigurationSystem.Client.PathFinder import getSystemURLs @@ -133,7 +133,7 @@ def __registerIfNotThere(self, compDict): if "startTime" in compDict: sqlInsertFields.append("StartTime") val = compDict["startTime"] - if isinstance(val, Time._allDateTypes): + if isinstance(val, TimeUtilities._allDateTypes): val = self.__datetime2str(val) sqlInsertValues.append("'%s'" % val) for field in ("cycles", "queries"): diff --git a/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py b/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py index 3499dc7a449..b8f190706bc 100644 --- a/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py +++ b/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py @@ -26,7 +26,7 @@ from DIRAC.Core.Utilities import Os from DIRAC.Core.Utilities.Extensions import extensionsByPriority, getExtensionMetadata from DIRAC.Core.Utilities.File import mkLink -from DIRAC.Core.Utilities.Time import fromString, hour, day +from DIRAC.Core.Utilities.TimeUtilities import fromString, hour, day from DIRAC.Core.Utilities.Subprocess import shellCall from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler from DIRAC.Core.Security.Locations import getHostCertificateAndKeyLocation @@ -432,7 +432,7 @@ def export_checkComponentLog(self, component): errors_1 = 0 errors_24 = 0 - now = datetime.datetime.utcnow() + now = datetime.utcnow() lastError = "" for line in logLines: if "ERROR:" in line: diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py index caefbd8dae8..791434c0364 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_users_with_proxy.py @@ -23,7 +23,7 @@ import datetime import DIRAC -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Base.Script import Script from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager @@ -77,7 +77,7 @@ def main(): data = dataDict[userName][iP] print(" DN : %s" % data[0]) print(" group : %s" % data[1]) - print(" not after : %s" % Time.toString(data[2])) + print(" not after : %s" % TimeUtilities.toString(data[2])) print(" persistent : %s" % data[3]) if iP < len(dataDict[userName]) - 1: print(" -") diff --git a/src/DIRAC/Interfaces/API/Dirac.py b/src/DIRAC/Interfaces/API/Dirac.py index 93b7bd55150..2abfa2e26fc 100755 --- a/src/DIRAC/Interfaces/API/Dirac.py +++ b/src/DIRAC/Interfaces/API/Dirac.py @@ -30,7 +30,7 @@ from DIRAC import gConfig, gLogger, S_OK, S_ERROR from DIRAC.Core.Base.API import API from DIRAC.Core.Base.Client import Client -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.File import mkDir from DIRAC.Core.Utilities.List import breakListIntoChunks from DIRAC.Core.Utilities.SiteSEMapping import getSEsForSite @@ -1974,7 +1974,7 @@ def selectJobs( except Exception as x: return self._errorReport(str(x), "Expected yyyy-mm-dd string for date") else: - date = "%s" % Time.date() + date = "%s" % TimeUtilities.date() self.log.verbose("Setting date to %s" % (date)) self.log.verbose("Will select jobs with last update %s and following conditions" % date) diff --git a/src/DIRAC/Interfaces/scripts/dirac_wms_job_delete.py b/src/DIRAC/Interfaces/scripts/dirac_wms_job_delete.py index fbc00f90753..33bc3291c80 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_wms_job_delete.py +++ b/src/DIRAC/Interfaces/scripts/dirac_wms_job_delete.py @@ -25,7 +25,7 @@ def main(): import DIRAC from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments - from DIRAC.Core.Utilities.Time import toString, date, day + from DIRAC.Core.Utilities.TimeUtilities import toString, date, day dirac = Dirac() diff --git a/src/DIRAC/Interfaces/scripts/dirac_wms_job_get_output.py b/src/DIRAC/Interfaces/scripts/dirac_wms_job_get_output.py index d561bee380b..e1e6eb28f0d 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_wms_job_get_output.py +++ b/src/DIRAC/Interfaces/scripts/dirac_wms_job_get_output.py @@ -27,7 +27,7 @@ def main(): sws, args = Script.parseCommandLine(ignoreErrors=True) from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments - from DIRAC.Core.Utilities.Time import toString, date, day + from DIRAC.Core.Utilities.TimeUtilities import toString, date, day from DIRAC.Core.Utilities.File import mkDir dirac = Dirac() diff --git a/src/DIRAC/Interfaces/scripts/dirac_wms_job_status.py b/src/DIRAC/Interfaces/scripts/dirac_wms_job_status.py index 5cc3a63eab8..74a44b817a0 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_wms_job_status.py +++ b/src/DIRAC/Interfaces/scripts/dirac_wms_job_status.py @@ -23,7 +23,7 @@ def main(): sws, args = Script.parseCommandLine(ignoreErrors=True) from DIRAC import exit as DIRACExit - from DIRAC.Core.Utilities.Time import toString, date, day + from DIRAC.Core.Utilities.TimeUtilities import toString, date, day from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments dirac = Dirac() diff --git a/src/DIRAC/MonitoringSystem/Service/MonitoringHandler.py b/src/DIRAC/MonitoringSystem/Service/MonitoringHandler.py index 260a2a84df5..6117caca1a1 100644 --- a/src/DIRAC/MonitoringSystem/Service/MonitoringHandler.py +++ b/src/DIRAC/MonitoringSystem/Service/MonitoringHandler.py @@ -15,7 +15,7 @@ from DIRAC import gLogger, S_OK, S_ERROR, gConfig from DIRAC.Core.DISET.RequestHandler import RequestHandler -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader from DIRAC.Core.Utilities.Plotting import gDataCache from DIRAC.Core.Utilities.Plotting.FileCoding import extractRequestFromFileId @@ -38,8 +38,8 @@ class MonitoringHandlerMixin: __reportRequestDict = { "typeName": str, "reportName": str, - "startTime": Time._allDateTypes, - "endTime": Time._allDateTypes, + "startTime": TimeUtilities._allDateTypes, + "endTime": TimeUtilities._allDateTypes, "condDict": dict, "grouping": str, "extraArgs": dict, @@ -203,7 +203,7 @@ def __checkPlotRequest(self, reportRequest): % (key, str(type(reportRequest[key])), str(self.__reportRequestDict[key])) ) if key in ("startTime", "endTime"): - reportRequest[key] = int(Time.toEpoch(reportRequest[key])) + reportRequest[key] = int(TimeUtilities.toEpoch(reportRequest[key])) return S_OK(reportRequest) diff --git a/src/DIRAC/RequestManagementSystem/Agent/RequestExecutingAgent.py b/src/DIRAC/RequestManagementSystem/Agent/RequestExecutingAgent.py index 4327d69a1ec..986d421f728 100644 --- a/src/DIRAC/RequestManagementSystem/Agent/RequestExecutingAgent.py +++ b/src/DIRAC/RequestManagementSystem/Agent/RequestExecutingAgent.py @@ -37,7 +37,7 @@ from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler -from DIRAC.Core.Utilities import Time, Network +from DIRAC.Core.Utilities import Network, TimeUtilities from DIRAC.Core.Utilities.DErrno import cmpError from DIRAC.Core.Utilities.ProcessPool import ProcessPool from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter @@ -381,7 +381,7 @@ def execute(self): if self.__rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Request", "status": "Attempted", diff --git a/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py b/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py index b0926f6b96d..d61ff708f56 100644 --- a/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py +++ b/src/DIRAC/RequestManagementSystem/private/OperationHandlerBase.py @@ -36,7 +36,7 @@ from DIRAC import gLogger, gConfig, S_ERROR, S_OK from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getGroupsWithVOMSAttribute -from DIRAC.Core.Utilities import Time, Network +from DIRAC.Core.Utilities import Network, TimeUtilities from DIRAC.Core.Utilities.ReturnValues import returnSingleResult from DIRAC.DataManagementSystem.Client.DataManager import DataManager from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager @@ -276,7 +276,7 @@ def createRMSRecord(self, status, nbObject): :returns: a dictionary. """ record = { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "File", "operationType": self.operation.Type, diff --git a/src/DIRAC/RequestManagementSystem/private/RequestTask.py b/src/DIRAC/RequestManagementSystem/private/RequestTask.py index 6cbc30585b5..b22197257e1 100644 --- a/src/DIRAC/RequestManagementSystem/private/RequestTask.py +++ b/src/DIRAC/RequestManagementSystem/private/RequestTask.py @@ -28,11 +28,11 @@ # # from DIRAC from DIRAC import gLogger, S_OK, S_ERROR, gConfig -from DIRAC.Core.Utilities import DErrno +from DIRAC.Core.Utilities import DErrno, TimeUtilities from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.ConfigurationSystem.Client.Helpers import Registry -from DIRAC.Core.Utilities import Time, Network +from DIRAC.Core.Utilities import Network from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient @@ -307,7 +307,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Operation", "operationType": pluginName, @@ -329,7 +329,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Operation", "operationType": pluginName, @@ -342,7 +342,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Request", "objectID": operation.RequestID, @@ -373,7 +373,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Operation", "operationType": pluginName, @@ -386,7 +386,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Request", "objectID": operation.RequestID, @@ -404,7 +404,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Operation", "operationType": pluginName, @@ -418,7 +418,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Operation", "operationType": pluginName, @@ -447,7 +447,7 @@ def __call__(self): if self.rmsMonitoring: self.rmsMonitoringReporter.addRecord( { - "timestamp": int(Time.toEpoch()), + "timestamp": int(TimeUtilities.toEpoch()), "host": Network.getFQDN(), "objectType": "Request", "objectID": getattr(self.request, "RequestID", 0), diff --git a/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_db.py b/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_db.py index 036b494ce30..99e4dad74f6 100755 --- a/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_db.py +++ b/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_db.py @@ -9,7 +9,7 @@ from DIRAC.ResourceStatusSystem.Client import ResourceStatusClient from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.PrettyPrint import printTable subLogger = None @@ -250,7 +250,7 @@ def tabularPrint(table): record = [] for _k, v in row.items(): if isinstance(v, datetime.datetime): - record.append(Time.toString(v)) + record.append(TimeUtilities.toString(v)) elif v is None: record.append("") else: diff --git a/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_dtcache.py b/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_dtcache.py index 8df47d8a9b8..b5d62d93652 100755 --- a/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_dtcache.py +++ b/src/DIRAC/ResourceStatusSystem/scripts/dirac_rss_query_dtcache.py @@ -6,7 +6,7 @@ from DIRAC import gLogger, exit as DIRACExit, version from DIRAC.Core.Base.Script import Script -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.PrettyPrint import printTable from DIRAC.ResourceStatusSystem.Utilities import Utils @@ -98,34 +98,34 @@ def filterDate(selectOutput, start, end): if start is not None: try: - start = Time.fromString(start) + start = TimeUtilities.fromString(start) except Exception: error("datetime formt is incorrect, pls try [%Y-%m-%d[ %H:%M:%S]]") - start = Time.toEpoch(start) + start = TimeUtilities.toEpoch(start) if end is not None: try: - end = Time.fromString(end) + end = TimeUtilities.fromString(end) except Exception: error("datetime formt is incorrect, pls try [%Y-%m-%d[ %H:%M:%S]]") - end = Time.toEpoch(end) + end = TimeUtilities.toEpoch(end) if start is not None and end is not None: for dt in downtimes: - dtStart = Time.toEpoch(dt["startDate"]) - dtEnd = Time.toEpoch(dt["endDate"]) + dtStart = TimeUtilities.toEpoch(dt["startDate"]) + dtEnd = TimeUtilities.toEpoch(dt["endDate"]) if (dtStart >= start) and (dtEnd <= end): downtimesFiltered.append(dt) elif start is not None and end is None: for dt in downtimes: - dtStart = Time.toEpoch(dt["startDate"]) + dtStart = TimeUtilities.toEpoch(dt["startDate"]) if dtStart >= start: downtimesFiltered.append(dt) elif start is None and end is not None: for dt in downtimes: - dtEnd = Time.toEpoch(dt["endDate"]) + dtEnd = TimeUtilities.toEpoch(dt["endDate"]) if dtEnd <= end: downtimesFiltered.append(dt) @@ -142,11 +142,11 @@ def filterOngoing(selectOutput): downtimes = selectOutput downtimesFiltered = [] - currentDate = Time.toEpoch(datetime.datetime.utcnow()) + currentDate = TimeUtilities.toEpoch(datetime.datetime.utcnow()) for dt in downtimes: - dtStart = Time.toEpoch(dt["startDate"]) - dtEnd = Time.toEpoch(dt["endDate"]) + dtStart = TimeUtilities.toEpoch(dt["startDate"]) + dtEnd = TimeUtilities.toEpoch(dt["endDate"]) if (dtStart <= currentDate) and (dtEnd >= currentDate): downtimesFiltered.append(dt) @@ -200,7 +200,7 @@ def tabularPrint(table): record = [] for k, v in row.items(): if isinstance(v, datetime.datetime): - record.append(Time.toString(v)) + record.append(TimeUtilities.toString(v)) elif v is None: record.append("") else: diff --git a/src/DIRAC/Resources/Cloud/KeystoneClient.py b/src/DIRAC/Resources/Cloud/KeystoneClient.py index 2e6ef0acc86..1531455b9cc 100644 --- a/src/DIRAC/Resources/Cloud/KeystoneClient.py +++ b/src/DIRAC/Resources/Cloud/KeystoneClient.py @@ -4,7 +4,7 @@ import datetime from DIRAC import S_OK, S_ERROR, gLogger -from DIRAC.Core.Utilities.Time import fromString, dateTime +from DIRAC.Core.Utilities.TimeUtilities import fromString class KeystoneClient(object): diff --git a/src/DIRAC/Resources/Computing/CloudComputingElement.py b/src/DIRAC/Resources/Computing/CloudComputingElement.py index 4eb708a2269..80d55268683 100644 --- a/src/DIRAC/Resources/Computing/CloudComputingElement.py +++ b/src/DIRAC/Resources/Computing/CloudComputingElement.py @@ -156,7 +156,7 @@ from DIRAC import S_OK, S_ERROR, gConfig, rootPath from DIRAC.Resources.Computing.ComputingElement import ComputingElement from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.Core.Utilities.Time import second, dt +from DIRAC.Core.Utilities.TimeUtilities import second, dt from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getVOForGroup from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.FrameworkSystem.Client.ProxyManagerClient import ProxyManagerClient @@ -342,7 +342,7 @@ def _renewCloudProxy(self): proxyLifetime = int(self.ceParameters.get("Context_ProxyLifetime", DEF_PROXYLIFETIME)) # only renew proxy if lifetime is less than configured lifetime # self.valid is a datetime - if self.valid - datetime.datetime.utcnow() > proxyLifetime * second: + if self.valid - datetime.utcnow() > proxyLifetime * second: return True proxyLifetime += DEF_PROXYGRACE proxyManager = ProxyManagerClient() @@ -356,7 +356,7 @@ def _renewCloudProxy(self): self.log.error("Failed to dump proxy to string", resdump["Message"]) return False self.proxy = resdump["Value"] - self.valid = datetime.datetime.utcnow() + proxyLifetime * second + self.valid = datetime.utcnow() + proxyLifetime * second return True def __init__(self, *args, **kwargs): diff --git a/src/DIRAC/Resources/Computing/ComputingElement.py b/src/DIRAC/Resources/Computing/ComputingElement.py index 5a9d2e5c574..fb71b47febf 100755 --- a/src/DIRAC/Resources/Computing/ComputingElement.py +++ b/src/DIRAC/Resources/Computing/ComputingElement.py @@ -38,7 +38,7 @@ from DIRAC.Core.Security.ProxyInfo import getProxyInfoAsString from DIRAC.Core.Security.ProxyInfo import formatProxyInfoAsString from DIRAC.Core.Security.ProxyInfo import getProxyInfo -from DIRAC.Core.Utilities.Time import second +from DIRAC.Core.Utilities.TimeUtilities import second from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader from DIRAC.ConfigurationSystem.Client.Config import gConfig from DIRAC.ConfigurationSystem.Client.Helpers import Registry diff --git a/src/DIRAC/StorageManagementSystem/Agent/StageMonitorAgent.py b/src/DIRAC/StorageManagementSystem/Agent/StageMonitorAgent.py index e358f506105..c44aaac0ab9 100755 --- a/src/DIRAC/StorageManagementSystem/Agent/StageMonitorAgent.py +++ b/src/DIRAC/StorageManagementSystem/Agent/StageMonitorAgent.py @@ -14,7 +14,7 @@ from DIRAC import gLogger, S_OK, S_ERROR, siteName from DIRAC.Core.Base.AgentModule import AgentModule -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient from DIRAC.Resources.Storage.StorageElement import StorageElement from DIRAC.MonitoringSystem.Client.DataOperationSender import DataOperationSender diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py index fda71a8a852..dff6fbee6ed 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/JobCleaningAgent.py @@ -38,7 +38,7 @@ from DIRAC.WorkloadManagementSystem.Client.JobMonitoringClient import JobMonitoringClient from DIRAC.WorkloadManagementSystem.Client.WMSClient import WMSClient -import DIRAC.Core.Utilities.Time as Time +import DIRAC.Core.Utilities.TimeUtilities as TimeUtilities class JobCleaningAgent(AgentModule): @@ -125,7 +125,7 @@ def execute(self): condDict = dict(baseCond) if status != "Any": condDict["Status"] = status - delTime = str(datetime.datetime.utcnow() - delay * Time.day) + delTime = str(datetime.datetime.utcnow() - delay * TimeUtilities.day) result = self.deleteJobsByStatus(condDict, delTime) if not result["OK"]: self.log.error("Failed to delete jobs", "with condDict %s" % condDict) @@ -361,7 +361,7 @@ def removeHeartBeatLoggingInfo(self, status, delayDays): :returns: None """ self.log.info("Removing HeartBeatLoggingInfo for Jobs with %s and older than %s day(s)" % (status, delayDays)) - delTime = str(datetime.datetime.utcnow() - delayDays * Time.day) + delTime = str(datetime.datetime.utcnow() - delayDays * TimeUtilities.day) result = self.jobDB.removeInfoFromHeartBeatLogging(status, delTime, self.maxHBJobsAtOnce) if not result["OK"]: self.log.error("Failed to delete from HeartBeatLoggingInfo", result["Message"]) diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/PilotStatusAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/PilotStatusAgent.py index 72ec6e02def..d7470acf512 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/PilotStatusAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/PilotStatusAgent.py @@ -15,7 +15,7 @@ from DIRAC.ConfigurationSystem.Client.Helpers import Registry from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getCESiteMapping from DIRAC.Core.Base.AgentModule import AgentModule -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin from DIRAC.WorkloadManagementSystem.Client import PilotStatus from DIRAC.WorkloadManagementSystem.Client.PilotManagerClient import PilotManagerClient @@ -92,7 +92,9 @@ def handleOldPilots(self, connection): Deleted, accounting for them. """ pilotsToAccount = {} - timeLimitToConsider = Time.toString(datetime.datetime.utcnow() - Time.day * self.pilotStalledDays) + timeLimitToConsider = TimeUtilities.toString( + datetime.datetime.utcnow() - TimeUtilities.day * self.pilotStalledDays + ) result = self.pilotDB.selectPilots( {"Status": PilotStatus.PILOT_TRANSIENT_STATES}, older=timeLimitToConsider, timeStamp="LastUpdateTime" ) @@ -231,14 +233,14 @@ def _killPilots(self, acc): self.log.error("Failed to get pilot info", "%s : %s" % (i, str(result))) def _checkJobLastUpdateTime(self, joblist, StalledDays): - timeLimitToConsider = datetime.datetime.utcnow() - Time.day * StalledDays + timeLimitToConsider = datetime.datetime.utcnow() - TimeUtilities.day * StalledDays ret = False for jobID in joblist: result = self.jobDB.getJobAttributes(int(jobID)) if result["OK"]: if "LastUpdateTime" in result["Value"]: lastUpdateTime = result["Value"]["LastUpdateTime"] - if Time.fromString(lastUpdateTime) > timeLimitToConsider: + if TimeUtilities.fromString(lastUpdateTime) > timeLimitToConsider: ret = True self.log.debug( "Since %s updates LastUpdateTime on %s this does not to need to be deleted." diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/SiteDirector.py b/src/DIRAC/WorkloadManagementSystem/Agent/SiteDirector.py index 5a5094d5813..ea05a49db04 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/SiteDirector.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/SiteDirector.py @@ -21,7 +21,7 @@ from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getCESiteMapping from DIRAC.Core.Base.AgentModule import AgentModule -from DIRAC.Core.Utilities.Time import second, toEpoch +from DIRAC.Core.Utilities.TimeUtilities import second, toEpoch from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager from DIRAC.AccountingSystem.Client.Types.Pilot import Pilot as PilotAccounting diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py index 61e00b151da..dd2ab92ee89 100755 --- a/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py @@ -17,7 +17,7 @@ from DIRAC.AccountingSystem.Client.Types.Job import Job from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities import DErrno -from DIRAC.Core.Utilities.Time import fromString, toEpoch, second +from DIRAC.Core.Utilities.TimeUtilities import fromString, toEpoch, second from DIRAC.Core.Utilities.ClassAd.ClassAdLight import ClassAd from DIRAC.ConfigurationSystem.Client.Helpers import cfgPath from DIRAC.ConfigurationSystem.Client.PathFinder import getSystemInstance diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/StatesAccountingAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/StatesAccountingAgent.py index bf929ac74c4..efdaaf8c1a0 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/StatesAccountingAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/StatesAccountingAgent.py @@ -12,7 +12,7 @@ from DIRAC import S_OK, S_ERROR from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.Core.Base.AgentModule import AgentModule -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.AccountingSystem.Client.Types.WMSHistory import WMSHistory from DIRAC.AccountingSystem.Client.DataStoreClient import DataStoreClient from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter @@ -92,7 +92,7 @@ def execute(self): rD = {} for iP, _ in enumerate(self.__pilotsMapping): rD[self.__pilotsMapping[iP]] = record[iP] - rD["timestamp"] = int(Time.toEpoch(now)) + rD["timestamp"] = int(TimeUtilities.toEpoch(now)) self.pilotReporter.addRecord(rD) self.log.info("Committing to Monitoring...") @@ -128,7 +128,7 @@ def execute(self): for backend in self.datastores: if backend.lower() == "monitoring": - rD["timestamp"] = int(Time.toEpoch(now)) + rD["timestamp"] = int(TimeUtilities.toEpoch(now)) self.datastores["Monitoring"].addRecord(rD) elif backend.lower() == "accounting": diff --git a/src/DIRAC/WorkloadManagementSystem/Client/JobReport.py b/src/DIRAC/WorkloadManagementSystem/Client/JobReport.py index 4c2ab868955..5888a8f9ffe 100644 --- a/src/DIRAC/WorkloadManagementSystem/Client/JobReport.py +++ b/src/DIRAC/WorkloadManagementSystem/Client/JobReport.py @@ -4,7 +4,7 @@ from collections import defaultdict from DIRAC import S_OK, S_ERROR, gLogger -from DIRAC.Core.Utilities import Time, DEncode +from DIRAC.Core.Utilities import DEncode, TimeUtilities from DIRAC.RequestManagementSystem.Client.Operation import Operation from DIRAC.WorkloadManagementSystem.Client.JobStateUpdateClient import JobStateUpdateClient @@ -31,7 +31,7 @@ def setJob(self, jobID): def setJobStatus(self, status="", minorStatus="", applicationStatus="", sendFlag=True): """Accumulate and possibly send job status information to the JobState service""" - timeStamp = Time.toString() + timeStamp = TimeUtilities.toString() # add job status record self.jobStatusInfo.append((status.replace("'", ""), minorStatus.replace("'", ""), timeStamp)) if applicationStatus: @@ -44,7 +44,7 @@ def setJobStatus(self, status="", minorStatus="", applicationStatus="", sendFlag def setApplicationStatus(self, appStatus, sendFlag=True): """Send application status information to the JobState service for jobID""" - timeStamp = Time.toString() + timeStamp = TimeUtilities.toString() # add Application status record if not isinstance(appStatus, str): appStatus = repr(appStatus) diff --git a/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py b/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py index 09e0f32f3c0..99f61957387 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/JobDB.py @@ -25,7 +25,7 @@ from DIRAC.Core.Utilities import DErrno from DIRAC.Core.Utilities.ClassAd.ClassAdLight import ClassAd from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.DErrno import EWMSSUBM, EWMSJMAN from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader from DIRAC.ResourceStatusSystem.Client.SiteStatus import SiteStatus @@ -986,10 +986,10 @@ def insertNewJobIntoDB( jobAttrValues.append(jobID) jobAttrNames.append("LastUpdateTime") - jobAttrValues.append(Time.toString()) + jobAttrValues.append(TimeUtilities.toString()) jobAttrNames.append("SubmissionTime") - jobAttrValues.append(Time.toString()) + jobAttrValues.append(TimeUtilities.toString()) jobAttrNames.append("Owner") jobAttrValues.append(owner) @@ -1414,10 +1414,10 @@ def rescheduleJob(self, jobID): jobAttrValues.append(0) jobAttrNames.append("LastUpdateTime") - jobAttrValues.append(Time.toString()) + jobAttrValues.append(TimeUtilities.toString()) jobAttrNames.append("RescheduleTime") - jobAttrValues.append(Time.toString()) + jobAttrValues.append(TimeUtilities.toString()) reqJDL = classAdReq.asJDL() classAdJob.insertAttributeInt("JobRequirements", reqJDL) @@ -1783,7 +1783,7 @@ def getSiteSummaryWeb(self, selectDict, sortList, startItem, maxItems): del selectDict["LastUpdateTime"] result = self.getCounters("Jobs", ["Site", "Status"], {}, newer=last_update, timeStamp="LastUpdateTime") - last_day = datetime.datetime.utcnow() - Time.day + last_day = datetime.datetime.utcnow() - TimeUtilities.day resultDay = self.getCounters("Jobs", ["Site", "Status"], {}, newer=last_day, timeStamp="EndExecTime") # Get the site mask status diff --git a/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py b/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py index 13ff7c51b16..465eee7a8aa 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py @@ -9,7 +9,7 @@ import time, datetime from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Base.DB import DB MAGIC_EPOC_NUMBER = 1270000000 @@ -61,8 +61,8 @@ def addLoggingRecord( _date = datetime.datetime.utcnow() elif isinstance(date, str): # The date is provided as a string in UTC - _date = Time.fromString(date) - elif isinstance(date, Time._dateTimeType): + _date = TimeUtilities.fromString(date) + elif isinstance(date, TimeUtilities._dateTimeType): _date = date else: self.log.error("Incorrect date for the logging record") diff --git a/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py b/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py index 9786a166a73..f9f80c96dd7 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/PilotAgentsDB.py @@ -23,7 +23,7 @@ from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.DB import DB -import DIRAC.Core.Utilities.Time as Time +import DIRAC.Core.Utilities.TimeUtilities as TimeUtilities from DIRAC.Core.Utilities import DErrno from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getCESiteMapping from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getUsernameForDN, getDNForUsername, getVOForGroup @@ -773,7 +773,7 @@ def getPilotSummaryWeb(self, selectDict, sortList, startItem, maxItems): if not result["OK"]: return result - last_update = datetime.datetime.utcnow() - Time.hour + last_update = datetime.datetime.utcnow() - TimeUtilities.hour selectDict["Status"] = PilotStatus.ABORTED resultHour = self.getCounters( "PilotAgents", @@ -785,7 +785,7 @@ def getPilotSummaryWeb(self, selectDict, sortList, startItem, maxItems): if not resultHour["OK"]: return resultHour - last_update = datetime.datetime.utcnow() - Time.day + last_update = datetime.datetime.utcnow() - TimeUtilities.day selectDict["Status"] = [PilotStatus.ABORTED, PilotStatus.DONE] resultDay = self.getCounters( "PilotAgents", @@ -1220,8 +1220,8 @@ def buildSQL(self, selectDict=None): :return: SQL query """ - lastUpdate = datetime.datetime.utcnow() - Time.day - lastHour = datetime.datetime.utcnow() - Time.hour + lastUpdate = datetime.datetime.utcnow() - TimeUtilities.day + lastHour = datetime.datetime.utcnow() - TimeUtilities.hour pvtable = "pivoted" innerGroupBy = ( diff --git a/src/DIRAC/WorkloadManagementSystem/DB/VirtualMachineDB.py b/src/DIRAC/WorkloadManagementSystem/DB/VirtualMachineDB.py index cbe54c4b7ea..4c1075887d5 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/VirtualMachineDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/VirtualMachineDB.py @@ -28,7 +28,7 @@ """ from DIRAC import S_ERROR, S_OK from DIRAC.Core.Base.DB import DB -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities class VirtualMachineDB(DB): @@ -846,7 +846,7 @@ def __insertInstance(self, uniqueID, imageName, instanceName, endpoint, runningP status = validStates[0] fields = ["UniqueID", "RunningPod", "Name", "Endpoint", "VMImageID", "Status", "LastUpdate"] - values = [uniqueID, runningPodName, instanceName, endpoint, imageID, status, Time.toString()] + values = [uniqueID, runningPodName, instanceName, endpoint, imageID, status, TimeUtilities.toString()] instance = self.insertFields(tableName, fields, values) if not instance["OK"]: @@ -1049,7 +1049,7 @@ def __getImageID(self, imageName): return S_OK(imageID) ret = self.insertFields( - tableName, ["Name", "Status", "LastUpdate"], [imageName, validStates[0], Time.toString()] + tableName, ["Name", "Status", "LastUpdate"], [imageName, validStates[0], TimeUtilities.toString()] ) if ret["OK"] and "lastRowId" in ret: @@ -1091,7 +1091,7 @@ def __addInstanceHistory(self, instanceID, status, load=0.0, jobs=0, transferred self.insertFields( "vm_History", ["InstanceID", "Status", "Load", "Update", "Jobs", "TransferredFiles", "TransferredBytes"], - [instanceID, status, load, Time.toString(), jobs, transferredFiles, transferredBytes], + [instanceID, status, load, TimeUtilities.toString(), jobs, transferredFiles, transferredBytes], ) return diff --git a/src/DIRAC/WorkloadManagementSystem/Executor/JobScheduling.py b/src/DIRAC/WorkloadManagementSystem/Executor/JobScheduling.py index de6e2f9e392..d1859f3f453 100755 --- a/src/DIRAC/WorkloadManagementSystem/Executor/JobScheduling.py +++ b/src/DIRAC/WorkloadManagementSystem/Executor/JobScheduling.py @@ -14,7 +14,7 @@ from DIRAC import S_OK, S_ERROR, gConfig from DIRAC.Core.Utilities.SiteSEMapping import getSEsForSite -from DIRAC.Core.Utilities.Time import fromString, toEpoch +from DIRAC.Core.Utilities.TimeUtilities import fromString, toEpoch from DIRAC.Core.Security import Properties from DIRAC.ConfigurationSystem.Client.Helpers import Registry from DIRAC.ConfigurationSystem.Client.Helpers.Path import cfgPath diff --git a/src/DIRAC/WorkloadManagementSystem/JobWrapper/JobWrapper.py b/src/DIRAC/WorkloadManagementSystem/JobWrapper/JobWrapper.py index 800fde7e153..850c0e0190e 100755 --- a/src/DIRAC/WorkloadManagementSystem/JobWrapper/JobWrapper.py +++ b/src/DIRAC/WorkloadManagementSystem/JobWrapper/JobWrapper.py @@ -31,7 +31,7 @@ from DIRAC.Core.Utilities import DErrno from DIRAC.Core.Utilities import List from DIRAC.Core.Utilities import DEncode -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.SiteSEMapping import getSEsForSite from DIRAC.Core.Utilities.ModuleFactory import ModuleFactory from DIRAC.Core.Utilities.Subprocess import systemCall @@ -514,7 +514,7 @@ def __sendFinalStdOut(self, exeThread): lines = len(result["Value"]) appStdOut = "\n".join(result["Value"]) - header = "Last %s lines of application output from JobWrapper on %s :" % (lines, Time.toString()) + header = "Last %s lines of application output from JobWrapper on %s :" % (lines, TimeUtilities.toString()) border = "=" * len(header) cpuTotal = "CPU Total: %s (h:m:s)" % cpuConsumed[1] diff --git a/src/DIRAC/WorkloadManagementSystem/Service/JobMonitoringHandler.py b/src/DIRAC/WorkloadManagementSystem/Service/JobMonitoringHandler.py index 1b4134449a2..c4971ba2228 100755 --- a/src/DIRAC/WorkloadManagementSystem/Service/JobMonitoringHandler.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/JobMonitoringHandler.py @@ -6,7 +6,7 @@ from DIRAC import S_OK, S_ERROR from DIRAC.Core.DISET.RequestHandler import RequestHandler -import DIRAC.Core.Utilities.Time as Time +import DIRAC.Core.Utilities.TimeUtilities as TimeUtilities from DIRAC.Core.Utilities.DEncode import ignoreEncodeWarning from DIRAC.Core.Utilities.JEncode import strToIntDict from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader @@ -397,8 +397,8 @@ def export_getJobPageSummaryWeb(self, selectDict, sortList, startItem, maxItems, # Code kept in case this is not working, but if we update the HeartBeatTime # at each status change from the jobs it should not be needed # Items are always strings - lastTime = Time.fromString(jobDict["LastUpdateTime"]) - hbTime = Time.fromString(jobDict["HeartBeatTime"]) + lastTime = TimeUtilities.fromString(jobDict["LastUpdateTime"]) + hbTime = TimeUtilities.fromString(jobDict["HeartBeatTime"]) # Try and identify statuses not set by the job itself as too expensive to get logging info # Not only Stalled jobs but also Failed jobs because Stalled if ( diff --git a/src/DIRAC/WorkloadManagementSystem/Service/JobStateUpdateHandler.py b/src/DIRAC/WorkloadManagementSystem/Service/JobStateUpdateHandler.py index 987bdfd657a..b403249764f 100755 --- a/src/DIRAC/WorkloadManagementSystem/Service/JobStateUpdateHandler.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/JobStateUpdateHandler.py @@ -10,7 +10,7 @@ from DIRAC import S_OK, S_ERROR from DIRAC.Core.DISET.RequestHandler import RequestHandler -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.DEncode import ignoreEncodeWarning from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations @@ -123,7 +123,7 @@ def __setJobStatus( if source: sDict["Source"] = source if not datetime: - datetime = Time.toString() + datetime = TimeUtilities.toString() return cls._setJobStatusBulk(jobID, {datetime: sDict}, force=force) return S_OK() @@ -178,14 +178,14 @@ def _setJobStatusBulk(cls, jobID, statusDict, force=False): return S_ERROR("No registered WMS timeStamps") # This is more precise than "LastTime". timeStamps is a sorted list of tuples... timeStamps = sorted((float(t), s) for s, t in result["Value"].items() if s != "LastTime") - lastTime = Time.toString(Time.fromEpoch(timeStamps[-1][0])) + lastTime = TimeUtilities.toString(TimeUtilities.fromEpoch(timeStamps[-1][0])) # Get chronological order of new updates updateTimes = sorted(statusDict) log.debug("*** New call ***", "Last update time %s - Sorted new times %s" % (lastTime, updateTimes)) # Get the status (if any) at the time of the first update newStat = "" - firstUpdate = Time.toEpoch(Time.fromString(updateTimes[0])) + firstUpdate = TimeUtilities.toEpoch(TimeUtilities.fromString(updateTimes[0])) for ts, st in timeStamps: if firstUpdate >= ts: newStat = st diff --git a/src/DIRAC/WorkloadManagementSystem/Service/PilotManagerHandler.py b/src/DIRAC/WorkloadManagementSystem/Service/PilotManagerHandler.py index 948f0c354ee..dac312dce12 100644 --- a/src/DIRAC/WorkloadManagementSystem/Service/PilotManagerHandler.py +++ b/src/DIRAC/WorkloadManagementSystem/Service/PilotManagerHandler.py @@ -5,7 +5,7 @@ import datetime from DIRAC import S_OK, S_ERROR -import DIRAC.Core.Utilities.Time as Time +import DIRAC.Core.Utilities.TimeUtilities as TimeUtilities from DIRAC.Core.DISET.RequestHandler import RequestHandler from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader @@ -59,7 +59,7 @@ def export_getCurrentPilotCounters(cls, attrDict={}): result = cls.pilotAgentsDB.getCounters("PilotAgents", ["Status"], attrDict, timeStamp="LastUpdateTime") if not result["OK"]: return result - last_update = datetime.datetime.utcnow() - Time.day + last_update = datetime.datetime.utcnow() - TimeUtilities.day resultDay = cls.pilotAgentsDB.getCounters( "PilotAgents", ["Status"], attrDict, newer=last_update, timeStamp="LastUpdateTime" ) diff --git a/tests/Integration/Core/Test_MySQLDB.py b/tests/Integration/Core/Test_MySQLDB.py index c3c144fedeb..4b334356f44 100644 --- a/tests/Integration/Core/Test_MySQLDB.py +++ b/tests/Integration/Core/Test_MySQLDB.py @@ -6,7 +6,7 @@ import DIRAC from DIRAC import gLogger, gConfig -from DIRAC.Core.Utilities import Time +from DIRAC.Core.Utilities import TimeUtilities from DIRAC.Core.Utilities.MySQL import MySQL @@ -230,8 +230,8 @@ def test_getDistinctAttributeValues(name, fields, requiredFields, values, table, ), (table, allFields, genVal2(), name, {"older": "UTC_TIMESTAMP()", "timeStamp": "Time"}, 2, True), (table, allFields, genVal2(), name, {"newer": "UTC_TIMESTAMP()", "timeStamp": "Time"}, 0, True), - (table, allFields, genVal2(), name, {"older": Time.toString, "timeStamp": "Time"}, 2, True), - (table, allFields, genVal2(), name, {"newer": Time.toString, "timeStamp": "Time"}, 0, True), + (table, allFields, genVal2(), name, {"older": TimeUtilities.toString, "timeStamp": "Time"}, 2, True), + (table, allFields, genVal2(), name, {"newer": TimeUtilities.toString, "timeStamp": "Time"}, 0, True), ], ) def test_getFields(table, reqFields, values, name, args, expected, isExpectedCount):