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
Commands.py
Go to the documentation of this file.
1 '''
2 Created on Feb 12, 2014
3 
4 @author: igor, bgv
5 '''
6 
7 import Consts as consts
8 from app.Utils import JsonSerializable
9 
10 
12 class BaseRequest(object):
13 
14 
18  def __init__(self, ctype, cid):
19  super(BaseRequest, self).__init__()
20 
21  self.type = ctype
22  #@var data
23  #a member variable, hold command data
24  self.data = dict()
25  self.id = cid
26  self.route = None
27  self.task_type = 0
28 
29 
30 
32 class Session(object):
33  TMODE_SYNC = 1
34  TMODE_ASYNC = 2
35 
36  TYPE_HOST_SHELL = 0
37  TYPE_SSH = 1
38 
39  '''
40  wrapper for Session fields array of execute task
41  '''
42  def __init__(self, tmode, ctype=TYPE_HOST_SHELL, maxExecutionTime=0):
43  super(Session, self).__init__()
44 
45  self.type = ctype
46  self.port = 0
47  self.user = ""
48  self.password = ""
49  self.shell = ""
50  self.environment = {}
51  self.timeout = 0
52  self.tmode = tmode
53  self.time_max = maxExecutionTime
54  self.home_directory = ""
55  if tmode == self.TMODE_SYNC:
56  self.cleanup = consts.TERMINATE_DATA_DELETE
57  else:
58  self.cleanup = consts.TERMINATE_DATA_SAVE
59 
60 
61  def add_evn_pair(self, param_name, param_value):
62  self.environment[param_name] = param_value
63 
64 
65 
66 
68 class Limits(object):
69 
70  def __init__(self):
71  super(Limits, self).__init__()
72 
73  self.proc_max = 0
74  self.threads_max = 0
75  self.cpu = 0
76  self.rram_free = 0
77  self.rram_free_min = 0
78  self.vram_free = 0
79  self.vram_free_min = 0
80  self.disk_free = 0
81  self.disk_free_min = 0
82 
83 
84 
85 
87 class TaskExecuteStruct(object):
88 
89  def __init__(self):
90  super(TaskExecuteStruct, self).__init__()
91 
92  self.session = Session(1, 0, 1200000)
93  self.limits = Limits()
94  self.command = ""
95  self.input = ""
96  self.files = list()
97 
98 
99 
101  def add_files(self, name, data, action):
102  self.files.append(dict({"name" : name,
103  "data" : data,
104  "action" : action}))
105 
106 
107 
108 
110 class ResponseItem(object):
111 
112  def __init__(self):
113  super(ResponseItem, self).__init__()
114 
115  self.error_code = 0
116  self.error_message = ""
117  self.id = 0
118  self.type = 0
119  self.host = ""
120  self.port = 0
121  self.state = 0
122  self.pid = 0
123  self.stdout = ""
124  self.stderror = ""
125  self.exit_status = 0
126  self.files = list()
127  self.node = ""
128  self.time = 0
129  self.fields = dict()
130 
131 
132 
133 
135 class TaskResponse(object):
136 
137  def __init__(self, items):
138  super(TaskResponse, self).__init__()
139 
140  self.items = items
141 
142 
143 
144 
145 class DRCECover(object):
146 
147  def __init__(self, ttl, data):
148  super(DRCECover, self).__init__()
149 
150  self.type = 2
151  self.ttl = ttl
152  self.data = data
153 
154 
155 
156 
159 
160  def __init__(self, tId):
161  super(TaskExecuteRequest, self).__init__(consts.EXECUTE_TASK, tId)
162 
164 
165 
166 
167 
170 
171  def __init__(self, tId, info_type):
172  super(TaskCheckRequest, self).__init__(consts.CHECK_TASK_STATE, tId)
173 
174  self.data = dict({"type" : info_type})
175 
176 
177 
178 
181 
182  def __init__(self, tId, info_type):
183  super(TaskGetDataRequest, self).__init__(consts.GET_TASK_DATA, tId)
184 
185  self.data = dict({"type" : info_type})
186 
187 
188 
189 
192 
193 
194  def __init__(self, tId):
195  super(TaskTerminateRequest, self).__init__(consts.TERMINATE_TASK, tId)
196 
197  self.data = dict({"alg":consts.TERMINATE_ALGORITHM_DEFAULT,
198  "delay":1,
199  "repeat":1,
200  "signal":9,
201  "cleanup":consts.TERMINATE_DATA_DELETE
202  })
203 
204 
205 
206 
209 
210 
211  def __init__(self, tId):
212  super(TaskDeleteRequest, self).__init__(consts.DELETE_TASK, tId)
213 
wrapper for task response item
Definition: Commands.py:110
def __init__(self)
Definition: Commands.py:70
def __init__(self, ctype, cid)
constructor
Definition: Commands.py:18
Base command for all dre request command.
Definition: Commands.py:12
Check task request.
Definition: Commands.py:169
Delete task request.
Definition: Commands.py:208
wrapper for TaskExecuteStruct
Definition: Commands.py:87
def __init__(self, items)
Definition: Commands.py:137
def add_evn_pair(self, param_name, param_value)
Definition: Commands.py:61
wrapper for task request
Definition: Commands.py:158
wrapper for Session fields array of execute task
Definition: Commands.py:32
def __init__(self, ttl, data)
Definition: Commands.py:147
def __init__(self, tId, info_type)
Definition: Commands.py:171
wrapper for Limits fields array of execute task
Definition: Commands.py:68
wrapper for cover object
Definition: Commands.py:145
wrapper for task response
Definition: Commands.py:135
def __init__(self, tmode, ctype=TYPE_HOST_SHELL, maxExecutionTime=0)
Definition: Commands.py:42
def __init__(self, tId, info_type)
Definition: Commands.py:182
def add_files(self, name, data, action)
simple wrapper for addion files fields
Definition: Commands.py:101
Get task's data request.
Definition: Commands.py:180
Terminate task request.
Definition: Commands.py:191