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_old Class Reference

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

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

Public Member Functions

def to_json (self, command)
 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 112 of file CommandConvertor.py.

Member Function Documentation

◆ from_json()

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

convert from json string to TaskResponse

Parameters
json_stringjson string
Returns
TaskResponse or throw CommandConvertorError

Definition at line 145 of file CommandConvertor.py.

145  def from_json(self, json_string):
146  try:
147  drceResponseObj = json.loads(json_string, cls=TaskResponseDecoder)
148  for item in drceResponseObj.items:
149  #For each item in DRCE response base64decode encoded fields
150  item.stderror = base64.b64decode(item.stderror)
151  item.stdout = base64.b64decode(item.stdout)
152  return drceResponseObj
153  except (ValueError, KeyError, TypeError) as err:
154  raise CommandConvertorError("convert from json " + err.message)
155 
156 
157 

◆ to_json()

def drce.CommandConvertor.CommandConvertor_old.to_json (   self,
  command 
)

convert from Task*Reques object to json string

Parameters
commandan instance of Task*Reques object
Returns
json string or throw CommandConvertorError

Definition at line 121 of file CommandConvertor.py.

121  def to_json(self, command):
122  try:
123  cmd_json = None
124  if isinstance(command, TaskExecuteRequest):
125  cmd_json = json.loads(json.dumps(command, cls=TaskExecuteRequestEncoder)) #return
126  else:
127  cmd_json = json.loads(json.dumps(command.__dict__)) #return
128 
129  data = cmd_json["data"]
130  data_json = json.dumps(data)
131 
132  cmd_json["data"] = base64.b64encode(data_json)
133  cmd_json = json.dumps(cmd_json)
134 
135  return cmd_json
136 
137  except (TypeError, ValueError) as err:
138  raise CommandConvertorError("convert to json " + err.message)
139 
140 

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