Skip to content

Commit 51b5d29

Browse files
authored
Merge pull request #5931 from fstagni/80_fixes22
[8.0] from BLOBs to TEXTs
2 parents 41f4b17 + dda883a commit 51b5d29

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

src/DIRAC/FrameworkSystem/DB/ComponentMonitoringDB.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
""" ComponentMonitoring class is a front-end to the Component monitoring Database
22
"""
3-
import six
43
from urllib import parse
54

65
from DIRAC import gConfig, S_OK, S_ERROR
@@ -84,7 +83,7 @@ def __initializeDB(self):
8483
"Version": "VARCHAR(255)",
8584
"DIRACVersion": "VARCHAR(255) NOT NULL",
8685
"Platform": "VARCHAR(255) NOT NULL",
87-
"Description": "BLOB",
86+
"Description": "TEXT",
8887
},
8988
"Indexes": {"Component": ["CompId"]},
9089
}
@@ -95,7 +94,7 @@ def __datetime2str(self, dt):
9594
"""
9695
This method converts the datetime type to a string type.
9796
"""
98-
if isinstance(dt, six.string_types):
97+
if isinstance(dt, str):
9998
return dt
10099
return "%s-%s-%s %s:%s:%s" % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
101100

@@ -249,9 +248,9 @@ def __getComponents(self, condDict):
249248
sqlWhere = []
250249
for field in condDict:
251250
val = condDict[field]
252-
if isinstance(val, six.string_types):
251+
if isinstance(val, str):
253252
sqlWhere.append("%s='%s'" % (field, val))
254-
elif isinstance(val, six.integer_types + (float,)):
253+
elif isinstance(val, (int, float)):
255254
sqlWhere.append("%s='%s'" % (field, val))
256255
else:
257256
sqlWhere.append("( %s )" % " OR ".join(["%s='%s'" % (field, v) for v in val]))

src/DIRAC/FrameworkSystem/DB/InstalledComponentsDB.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Classes and functions for easier management of the InstalledComponents database
33
"""
4-
import six
54
import re
65
import datetime
76
from sqlalchemy import MetaData, Column, Integer, String, DateTime, create_engine, text
@@ -416,7 +415,7 @@ def __filterFields(self, session, table, matchFields=None):
416415
toAppend = element
417416
if isinstance(toAppend, datetime.datetime):
418417
toAppend = toAppend.strftime("%Y-%m-%d %H:%M:%S")
419-
if isinstance(toAppend, six.string_types):
418+
if isinstance(toAppend, str):
420419
toAppend = "'%s'" % (toAppend)
421420
if i == 0:
422421
sql = "%s%s" % (sql, toAppend)
@@ -425,7 +424,7 @@ def __filterFields(self, session, table, matchFields=None):
425424
sql = "%s )" % (sql)
426425
else:
427426
continue
428-
elif isinstance(matchFields[key], six.string_types):
427+
elif isinstance(matchFields[key], str):
429428
sql = "`%s` %s '%s'" % (actualKey, comparison, matchFields[key])
430429
elif isinstance(matchFields[key], datetime.datetime):
431430
sql = "%s %s '%s'" % (actualKey, comparison, matchFields[key].strftime("%Y-%m-%d %H:%M:%S"))

src/DIRAC/FrameworkSystem/DB/NotificationDB.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __initializeDB(self):
6565
"Subject": "VARCHAR(255) NOT NULL",
6666
"Status": "VARCHAR(64) NOT NULL",
6767
"Priority": "VARCHAR(32) NOT NULL",
68-
"Body": "BLOB",
68+
"Body": "TEXT",
6969
"Assignee": "VARCHAR(64) NOT NULL",
7070
"Notifications": "VARCHAR(128) NOT NULL",
7171
},
@@ -87,7 +87,7 @@ def __initializeDB(self):
8787
"AlarmId": "INTEGER UNSIGNED NOT NULL",
8888
"Timestamp": "DATETIME NOT NULL",
8989
"Author": "VARCHAR(64) NOT NULL",
90-
"Comment": "BLOB",
90+
"Comment": "TEXT",
9191
"Modifications": "VARCHAR(255)",
9292
},
9393
"Indexes": {"AlarmID": ["AlarmId"]},
@@ -110,7 +110,7 @@ def __initializeDB(self):
110110
"Fields": {
111111
"Id": "INTEGER UNSIGNED AUTO_INCREMENT NOT NULL",
112112
"User": "VARCHAR(64) NOT NULL",
113-
"Message": "BLOB NOT NULL",
113+
"Message": "TEXT NOT NULL",
114114
"Seen": "TINYINT(1) NOT NULL DEFAULT 0",
115115
"Expiration": "DATETIME",
116116
"Timestamp": "DATETIME",

src/DIRAC/FrameworkSystem/DB/UserProfileDB.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
""" UserProfileDB class is a front-end to the User Profile Database
22
"""
33

4-
import six
5-
64
import cachetools
75

86
from DIRAC import S_OK, S_ERROR
@@ -51,7 +49,7 @@ class UserProfileDB(DB):
5149
"VOId": "INTEGER",
5250
"Profile": "VARCHAR(255) NOT NULL",
5351
"VarName": "VARCHAR(255) NOT NULL",
54-
"Data": "BLOB",
52+
"Data": "TEXT",
5553
"ReadAccess": 'VARCHAR(10) DEFAULT "USER"',
5654
"PublishAccess": 'VARCHAR(10) DEFAULT "USER"',
5755
},
@@ -260,7 +258,8 @@ def retrieveVarById(self, userIds, ownerIds, profileName, varName):
260258
return result
261259
data = result["Value"]
262260
if len(data) > 0:
263-
return S_OK(data[0][0].decode())
261+
# TODO: The decode is only needed in DIRAC v8.0.x while moving from BLOB -> TEXT
262+
return S_OK(data[0][0].decode() if isinstance(data[0][0], bytes) else data[0][0])
264263
return S_ERROR("No data for userIds %s profileName %s varName %s" % (userIds, profileName, varName))
265264

266265
def retrieveAllUserVarsById(self, userIds, profileName):
@@ -278,7 +277,12 @@ def retrieveAllUserVarsById(self, userIds, profileName):
278277
if not result["OK"]:
279278
return result
280279
data = result["Value"]
281-
return S_OK({k: v.decode() for k, v in data})
280+
try:
281+
# TODO: This is only needed in DIRAC v8.0.x while moving from BLOB -> TEXT
282+
allUserDataDict = {k: v.decode() for k, v in data}
283+
except AttributeError:
284+
allUserDataDict = {k: v for k, v in data}
285+
return S_OK(allUserDataDict)
282286

283287
def retrieveUserProfilesById(self, userIds):
284288
"""
@@ -289,12 +293,15 @@ def retrieveUserProfilesById(self, userIds):
289293
result = self._query(selectSQL)
290294
if not result["OK"]:
291295
return result
292-
data = result["Value"]
293296
dataDict = {}
294-
for profile, varName, data in data:
297+
for profile, varName, data in result["Value"]:
295298
if profile not in dataDict:
296299
dataDict[profile] = {}
297-
dataDict[profile][varName] = data.decode()
300+
try:
301+
# TODO: This is only needed in DIRAC v8.0.x while moving from BLOB -> TEXT
302+
dataDict[profile][varName] = data.decode()
303+
except AttributeError:
304+
dataDict[profile][varName] = data
298305
return S_OK(dataDict)
299306

300307
def retrieveVarPermsById(self, userIds, ownerIds, profileName, varName):
@@ -489,7 +496,7 @@ def deleteVar(self, userName, userGroup, profileName, varName):
489496
return self.deleteVarByUserId(userIds, profileName, varName)
490497

491498
def __profilesCondGenerator(self, value, varType, initialValue=False):
492-
if isinstance(value, six.string_types):
499+
if isinstance(value, str):
493500
value = [value]
494501
ids = []
495502
if initialValue:

src/DIRAC/ProductionSystem/DB/ProductionDB.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
in order to automate the task of transformation preparation for high level productions.
55
"""
66
# # imports
7-
import six
87
import json
98
import threading
109

@@ -146,10 +145,10 @@ def getProductions(
146145
webList = []
147146
resultList = []
148147
for row in res["Value"]:
149-
# HACK: Description should be converted to a text type
148+
# TODO: remove, as Description should have been converted to a text type
150149
row = [item.decode() if isinstance(item, bytes) else item for item in row]
151150
# Prepare the structure for the web
152-
rList = [str(item) if not isinstance(item, six.integer_types) else item for item in row]
151+
rList = [str(item) if not isinstance(item, int) else item for item in row]
153152
prodDict = dict(zip(self.PRODPARAMS, row))
154153
webList.append(rList)
155154
resultList.append(prodDict)
@@ -181,7 +180,7 @@ def getProductionParameters(self, prodName, parameters, connection=False):
181180
:param str prodName: the Production name or ID
182181
:param str parameters: any valid production parameter in self.PRODPARAMS
183182
"""
184-
if isinstance(parameters, six.string_types):
183+
if isinstance(parameters, str):
185184
parameters = [parameters]
186185
res = self.getProduction(prodName, connection=connection)
187186
if not res["OK"]:
@@ -215,7 +214,7 @@ def getProductionStep(self, stepID, connection=False):
215214
if not res["Value"]:
216215
return S_ERROR("ProductionStep %s did not exist" % str(stepID))
217216
row = res["Value"][0]
218-
# HACK: LongDescription and Body should be converted to a text type
217+
# TODO: remove, as Description and body should have been converted to a text type
219218
row = [item.decode() if isinstance(item, bytes) else item for item in row]
220219
return S_OK(row)
221220

@@ -319,7 +318,7 @@ def getProductionTransformations(
319318
resultList = []
320319
for row in res["Value"]:
321320
# Prepare the structure for the web
322-
rList = [str(item) if not isinstance(item, six.integer_types) else item for item in row]
321+
rList = [str(item) if not isinstance(item, int) else item for item in row]
323322
transDict = dict(zip(self.TRANSPARAMS, row))
324323
webList.append(rList)
325324
resultList.append(transDict)
@@ -619,7 +618,7 @@ def _getProductionID(self, prodName, connection=False):
619618
prodName = int(prodName)
620619
cmd = "SELECT ProductionID from Productions WHERE ProductionID=%d;" % prodName
621620
except Exception:
622-
if not isinstance(prodName, six.string_types):
621+
if not isinstance(prodName, str):
623622
return S_ERROR("Production should be ID or name")
624623
cmd = "SELECT ProductionID from Productions WHERE ProductionName='%s';" % prodName
625624
res = self._query(cmd, connection)

src/DIRAC/ProductionSystem/DB/ProductionDB.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DROP TABLE IF EXISTS Productions;
2222
CREATE TABLE Productions(
2323
ProductionID INTEGER NOT NULL AUTO_INCREMENT,
2424
ProductionName VARCHAR(255) NOT NULL,
25-
Description LONGBLOB,
25+
Description LONGTEXT,
2626
CreationDate DATETIME,
2727
LastUpdate DATETIME,
2828
AuthorDN VARCHAR(255) NOT NULL,
@@ -38,8 +38,8 @@ CREATE TABLE ProductionSteps(
3838
StepID INTEGER NOT NULL AUTO_INCREMENT,
3939
Name VARCHAR(255),
4040
Description VARCHAR(255),
41-
LongDescription BLOB,
42-
Body LONGBLOB,
41+
LongDescription TEXT,
42+
Body LONGTEXT,
4343
Type CHAR(32) DEFAULT 'Simulation',
4444
Plugin CHAR(32) DEFAULT 'None',
4545
AgentType CHAR(32) DEFAULT 'Manual',

0 commit comments

Comments
 (0)