HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
drce.CommandConvertor.CommandConvertor Class Reference

Convertor which used to convert Task*Reques to json and TaskResponse from json. More...

Inheritance diagram for drce.CommandConvertor.CommandConvertor:
Collaboration diagram for drce.CommandConvertor.CommandConvertor:

Public Member Functions

def to_json (self, taskRequestObj, log=None)
 convert from Task*Reques object to json string More...
 
def from_json (self, json_string)
 convert from json string to TaskResponse More...
 

Detailed Description

Convertor which used to convert Task*Reques to json and TaskResponse from json.

Convert Request to json and restore Response from json

Definition at line 161 of file CommandConvertor.py.

Member Function Documentation

◆ from_json()

def drce.CommandConvertor.CommandConvertor.from_json (   self,
  json_string 
)

convert from json string to TaskResponse

Parameters
json_stringjson string
Returns
TaskResponse or throw CommandConvertorError

Definition at line 198 of file CommandConvertor.py.

198  def from_json(self, json_string):
199  try:
200  drceResponseObj = json.loads(json_string, cls=TaskResponseDecoder)
201  for item in drceResponseObj.items:
202  #For each item in DRCE response base64decode encoded fields
203  item.stderror = base64.b64decode(item.stderror)
204  item.stdout = base64.b64decode(item.stdout)
205  return drceResponseObj
206  except (ValueError, KeyError, TypeError) as err:
207  raise CommandConvertorError("convert from json " + err.message)
208 
209 

◆ to_json()

def drce.CommandConvertor.CommandConvertor.to_json (   self,
  taskRequestObj,
  log = None 
)

convert from Task*Reques object to json string

Parameters
cmdObjan instance of Task*Request object
Returns
json string or throw CommandConvertorError

Definition at line 170 of file CommandConvertor.py.

170  def to_json(self, taskRequestObj, log=None):
171  cmd_json = None
172  try:
173  cmd_json = taskRequestObj.toJSON()
174  if log is not None:
175  log.debug("!!! cmd_json: %s", cmd_json)
176 
177  cmd_json = json.loads(cmd_json)
178 
179  if "data" in cmd_json:
180  data_json = json.dumps(cmd_json["data"])
181  else:
182  raise CommandConvertorError("convert to json error, \"data\" field not found!")
183 
184  cmd_json["data"] = base64.b64encode(data_json)
185  cmd_json = json.dumps(cmd_json)
186 
187  return cmd_json
188 
189  except (TypeError, ValueError) as err:
190  raise CommandConvertorError("convert to json error : " + str(err) + "\n" + Utils.varDump(taskRequestObj) + '\n' + Utils.getTracebackInfo() + \
191  "\ncmd_json: " + Utils.varDump(cmd_json) + "\ntaskRequestObj: " + Utils.varDump(taskRequestObj))
192 
193 

The documentation for this class was generated from the following file: