Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions Server/Python/src/dbs/web/DBSWriterModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,43 @@

import traceback

# import for gzip decompression utility
import gzip
try:
import cStringIO as StringIO
except ImportError: # python3
import io
except:
import StringIO
# CMSMonitoring modules
from CMSMonitoring.NATS import NATSManager


def decompress(body):
"Decompress the request body"
if sys.version.startswith('3.'):
zbuf = io.BytesIO()
else:
zbuf = StringIO.StringIO()
zbuf.write(body)
zbuf.seek(0)
zfile = gzip.GzipFile(mode='rb', fileobj=zbuf)
data = zfile.read()
zfile.close()
return data

def read_body():
"""
Provides uniform way to read either plain payload body
or gzipped one
"""
raw = request.body.read(int(cherrypy.request.headers['Content-Length']))
if request.headers['Content-Encoding'] == 'gzip':
raw = decompress(raw)
return raw
body = request.body.read()
return body

class DBSWriterModel(DBSReaderModel):
"""
DBS3 Server API Documentation
Expand Down Expand Up @@ -98,7 +131,7 @@ def insertPrimaryDataset(self):

"""
try :
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy("primds", indata)
indata.update({"creation_date": dbsUtils().getTime(), "create_by": dbsUtils().getCreateBy() })
Expand Down Expand Up @@ -130,7 +163,7 @@ def insertOutputConfig(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy("dataset_conf_list", indata)
indata.update({"creation_date": dbsUtils().getTime(),
Expand Down Expand Up @@ -181,7 +214,7 @@ def insertAcquisitionEra(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy("acquisition_era", indata)
indata.update({"start_date": indata.get("start_date", dbsUtils().getTime()),\
Expand Down Expand Up @@ -210,7 +243,7 @@ def insertProcessingEra(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy('processing_era', indata)
indata.update({"creation_date": indata.get("creation_date", dbsUtils().getTime()), \
Expand Down Expand Up @@ -247,7 +280,7 @@ def insertDataset(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy('dataset', indata)
indata.update({"creation_date": dbsUtils().getTime(),
Expand Down Expand Up @@ -287,7 +320,7 @@ def insertBulkBlock(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
if (indata.get("file_parent_list", []) and indata.get("dataset_parent_list", [])):
dbsExceptionHandler("dbsException-invalid-input2", "insertBulkBlock: dataset and file parentages cannot be in the input at the same time",
Expand Down Expand Up @@ -332,7 +365,7 @@ def insertFileParents(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy("file_parent", indata)
self.dbsFile.insertFileParents(indata)
Expand Down Expand Up @@ -365,7 +398,7 @@ def insertBlock(self):

"""
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)
indata = validateJSONInputNoCopy("block", indata)
self.dbsBlock.insertBlock(indata)
Expand Down Expand Up @@ -405,7 +438,7 @@ def insertFile(self, qInserts=False):
"""
if qInserts in (False, 'False'): qInserts=False
try:
body = request.body.read()
body = read_body()
indata = cjson.decode(body)["files"]
if not isinstance(indata, (list, dict)):
dbsExceptionHandler("dbsException-invalid-input", "Invalid Input DataType", self.logger.exception, \
Expand Down Expand Up @@ -563,7 +596,7 @@ def insertDataTier(self):
conn = self.dbi.connection()
tran = conn.begin()

body = request.body.read()
body = read_body()
indata = cjson.decode(body)

indata = validateJSONInputNoCopy("dataTier", indata)
Expand Down