forked from ancorisrm/ancoris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.py
More file actions
executable file
·42 lines (31 loc) · 1.11 KB
/
master.py
File metadata and controls
executable file
·42 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from catenae import Link, Electron, rpc, utils as catenae_utils
from random import randint
import json
from enum import Enum
from common import startup_text
class AncorisMaster(Link):
class JSONRPC_ERRORS(Enum):
NO_WORKERS_AVAILABLE = -32000
def _get_worker(self, request):
try:
workers = self.instances['by_group']['catenae_ancorisworker']
except KeyError:
return
random_index = randint(0, len(workers) - 1)
return workers[random_index]
@rpc
def run(self, request):
request_id = catenae_utils.get_uid()
worker_uid = self._get_worker(request)
if worker_uid is None:
error = AncorisMaster.JSONRPC_ERRORS.NO_WORKERS_AVAILABLE
return error.value, error.name
response = self.rpc_call(worker_uid, 'run', request, request_id=request_id)
return response
@rpc
def remove(self, request):
self.rpc_notify('broadcast', 'remove', request['container'])
if __name__ == "__main__":
AncorisMaster().start(startup_text=startup_text)