Skip to content

Commit

Permalink
feat: add VO in Jobs table
Browse files Browse the repository at this point in the history
  • Loading branch information
DIRACGrid CI authored and simon-mazenoux committed Sep 27, 2023
1 parent d011057 commit dde7b2b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
26 changes: 14 additions & 12 deletions src/DIRAC/WorkloadManagementSystem/DB/JobDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,26 @@
* *CompressJDLs*: Enable compression of JDLs when they are stored in the database, default *False*.
"""
import base64
import zlib
import datetime

import operator

from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getVOForGroup
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSiteTier
from DIRAC.Core.Base.DB import DB
from DIRAC.Core.Utilities import DErrno
from DIRAC.Core.Utilities.ClassAd.ClassAdLight import ClassAd
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, convertToReturnValue
from DIRAC.Core.Utilities.DErrno import EWMSSUBM, EWMSJMAN, cmpError
from DIRAC.Core.Utilities.ObjectLoader import ObjectLoader
from DIRAC.Core.Utilities.DErrno import EWMSJMAN, EWMSSUBM, cmpError
from DIRAC.Core.Utilities.ReturnValues import S_ERROR, S_OK
from DIRAC.ResourceStatusSystem.Client.SiteStatus import SiteStatus
from DIRAC.WorkloadManagementSystem.Client.JobState.JobManifest import JobManifest
from DIRAC.WorkloadManagementSystem.Client import JobStatus
from DIRAC.WorkloadManagementSystem.Client import JobMinorStatus
from DIRAC.WorkloadManagementSystem.Client import JobMinorStatus, JobStatus
from DIRAC.WorkloadManagementSystem.Client.JobMonitoringClient import JobMonitoringClient
from DIRAC.WorkloadManagementSystem.DB.JobDBUtils import (
checkAndAddOwner,
fixJDL,
checkAndPrepareJob,
createJDLWithInitialStatus,
compressJDL,
createJDLWithInitialStatus,
extractJDL,
fixJDL,
)


Expand Down Expand Up @@ -891,6 +884,7 @@ def insertNewJobIntoDB(
ownerGroup,
initialStatus=JobStatus.RECEIVED,
initialMinorStatus="Job accepted",
vo=None,
):
"""Insert the initial JDL into the Job database,
Do initial JDL crosscheck,
Expand All @@ -903,11 +897,17 @@ def insertNewJobIntoDB(
:param str initialMinorStatus: optional initial minor job status
:return: new job ID
"""
# Workaround for the case when a custom version of dirac would be
# calling this method
if not vo:
vo = getVOForGroup(ownerGroup)

jobAttrs = {
"LastUpdateTime": str(datetime.datetime.utcnow()),
"SubmissionTime": str(datetime.datetime.utcnow()),
"Owner": owner,
"OwnerGroup": ownerGroup,
"VO": vo,
}

result = checkAndAddOwner(jdl, owner, ownerGroup)
Expand Down Expand Up @@ -1193,6 +1193,8 @@ def rescheduleJob(self, jobID):

jobAttrs["RescheduleTime"] = str(datetime.datetime.utcnow())

jobAttrs["VO"] = getVOForGroup(resultDict["OwnerGroup"])

reqJDL = classAdReq.asJDL()
classAdJob.insertAttributeInt("JobRequirements", reqJDL)

Expand Down
1 change: 1 addition & 0 deletions src/DIRAC/WorkloadManagementSystem/DB/JobDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CREATE TABLE `Jobs` (
`JobName` VARCHAR(128) NOT NULL DEFAULT 'Unknown',
`Owner` VARCHAR(64) NOT NULL DEFAULT 'Unknown',
`OwnerGroup` VARCHAR(128) NOT NULL DEFAULT 'Unknown',
`VO` VARCHAR(32) NOT NULL DEFAULT 'Unknown',
`SubmissionTime` DATETIME DEFAULT NULL,
`RescheduleTime` DATETIME DEFAULT NULL,
`LastUpdateTime` DATETIME DEFAULT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def export_submitJob(self, jobDesc):
self.ownerGroup,
initialStatus=initialStatus,
initialMinorStatus=initialMinorStatus,
vo=getVOForGroup(self.ownerGroup),
)
if not result["OK"]:
return result
Expand Down
32 changes: 16 additions & 16 deletions tests/Integration/WorkloadManagementSystem/Test_JobDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def test_isValid(jobDB: JobDB):
assert jobDB.isValid()


def test_insertNewJobIntoDB(jobDB):
def test_insertNewJobIntoDB(jobDB: JobDB):
"""Test the insertNewJobIntoDB method"""

# Act
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")

# Assert
assert res["OK"], res["Message"]
Expand All @@ -105,9 +105,9 @@ def test_insertNewJobIntoDB(jobDB):
assert res["Value"] == {}


def test_removeJobFromDB(jobDB):
def test_removeJobFromDB(jobDB: JobDB):
# Arrange
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID = int(res["JobID"])

Expand All @@ -122,7 +122,7 @@ def test_getJobJDL_original(jobDB: JobDB):
"""Test of the getJobJDL method with the original parameter set to True"""

# Arrange
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID = int(res["JobID"])

Expand All @@ -139,7 +139,7 @@ def test_getJobJDL_nonOriginal(jobDB: JobDB):
"""Test of the getJobJDL method with the original parameter set to True"""

# Arrange
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID = int(res["JobID"])

Expand Down Expand Up @@ -191,13 +191,13 @@ def test_getJobJDL_nonOriginal(jobDB: JobDB):
)


def test_getJobsAttributes(jobDB):
def test_getJobsAttributes(jobDB: JobDB):
# Arrange
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID_1 = int(res["JobID"])

res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID_2 = int(res["JobID"])

Expand All @@ -214,7 +214,7 @@ def test_getJobsAttributes(jobDB):

def test_rescheduleJob(jobDB):
# Arrange
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID = res["JobID"]

Expand Down Expand Up @@ -261,7 +261,7 @@ def test_getCounters(jobDB):


def test_heartBeatLogging(jobDB):
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID = res["JobID"]

Expand Down Expand Up @@ -303,7 +303,7 @@ def test_heartBeatLogging(jobDB):


def test_getJobParameters(jobDB):
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID = res["JobID"]

Expand All @@ -321,10 +321,10 @@ def test_getJobParameters(jobDB):


def test_setJobsMajorStatus(jobDB):
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID_1 = res["JobID"]
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID_2 = res["JobID"]

Expand Down Expand Up @@ -367,10 +367,10 @@ def test_setJobsMajorStatus(jobDB):


def test_attributes(jobDB):
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID_1 = res["JobID"]
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup")
res = jobDB.insertNewJobIntoDB(jdl, "owner", "ownerGroup", vo="vo")
assert res["OK"], res["Message"]
jobID_2 = res["JobID"]

Expand Down

0 comments on commit dde7b2b

Please sign in to comment.