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.CommandExecutor.CommandExecutor Class Reference
Inheritance diagram for drce.CommandExecutor.CommandExecutor:
Collaboration diagram for drce.CommandExecutor.CommandExecutor:

Public Member Functions

def __init__ (self, connection, cmd_convertor)
 
def replace_connection (self, connection)
 
def execute (self, command, timeout=1000, ttl=30000, maxTries=100)
 

Public Attributes

 connection
 
 cmd_convertor
 
 id_generator
 

Detailed Description

Definition at line 32 of file CommandExecutor.py.

Constructor & Destructor Documentation

◆ __init__()

def drce.CommandExecutor.CommandExecutor.__init__ (   self,
  connection,
  cmd_convertor 
)

Definition at line 39 of file CommandExecutor.py.

39  def __init__(self, connection, cmd_convertor):
40  self.connection = connection
41  self.cmd_convertor = cmd_convertor
42  # @var id_generator
43  # a member variable, used to generate uid for messages
44  self.id_generator = UIDGenerator()
45 
46 
def __init__(self)
constructor
Definition: UIDGenerator.py:19

Member Function Documentation

◆ execute()

def drce.CommandExecutor.CommandExecutor.execute (   self,
  command,
  timeout = 1000,
  ttl = 30000,
  maxTries = 100 
)

Definition at line 67 of file CommandExecutor.py.

67  def execute(self, command, timeout=1000, ttl=30000, maxTries=100):
68  if maxTries < 0:
69  maxTries = 0
70 
71  try:
72  logger.debug("command: %s", Utils.varDump(command, strTypeMaxLen=10000))
73  cmd_json = self.cmd_convertor.to_json(command, logger)
74  drce_cover_envelop = DRCECover(ttl, cmd_json)
75  request = Request(self.id_generator.get_uid())
76  request.add_data(json.dumps(drce_cover_envelop, cls=TaskExecuteStructEncoder))
77  request.route = command.route
78  request.task_type = command.task_type
79 
80  uid = request.get_uid()
81  logger.debug("Send DRCE request msg Id:" + uid + ", route: " + str(request.route))
82 
83  self.connection.send(request, uid)
84 
85  for i in range(int(maxTries) + 1):
86  response = self.connection.recv(timeout, uid)
87  logger.debug("Received DRCE response msg Id:" + response.get_uid())
88  if response.get_uid() == request.get_uid() or maxTries == 0:
89  cover_envelop_response = json.loads(response.get_body())
90  return self.cmd_convertor.from_json(cover_envelop_response["data"])
91  else:
92  logger.error("DRCE response msg Id:" + response.get_uid() + \
93  " not matched with the request msg Id:" + request.get_uid() + \
94  ", try: " + str(i))
95  except (ResponseFormatErr, CommandConvertorError, KeyError, CommandExecutorErr) as err:
96  logger.error("DRCE object model error: %s", str(err))
97  raise CommandExecutorErr(str(err))
98  except Exception as err:
99  logger.error("General error: %s", str(err))
100  raise CommandExecutorErr(str(err))
101 
102 
def get_uid(self, idType=0)
get_uid
Definition: UIDGenerator.py:31
def execute(self, commands, nodes)
execute method execute incoming commands on nodes, keepts reult in responses and responsesDicts field...
Definition: NodeManager.py:63

◆ replace_connection()

def drce.CommandExecutor.CommandExecutor.replace_connection (   self,
  connection 
)

Definition at line 52 of file CommandExecutor.py.

52  def replace_connection(self, connection):
53  self.connection = connection
54 
55 
56 

Member Data Documentation

◆ cmd_convertor

drce.CommandExecutor.CommandExecutor.cmd_convertor

Definition at line 41 of file CommandExecutor.py.

◆ connection

drce.CommandExecutor.CommandExecutor.connection

Definition at line 40 of file CommandExecutor.py.

◆ id_generator

drce.CommandExecutor.CommandExecutor.id_generator

Definition at line 44 of file CommandExecutor.py.


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