def __init__(self, debug_jail = False): super(StaticSurrogate, self).__init__() # Set member variables. self.pending_tasks = {} self.pending_tasks_lock = allocate_lock() self.activity_count = 0 self.__shutdown = False # Get a logger. self.__logger = logging.getLogger('scavenger') # Get a config handle. self._config = Config.get_instance() # Check that the "static" section contains a node name. if not self._config.has_section('static') or not self._config.has_option('static', 'name'): self.__logger.error("Static surrogate name is missing in the config file.") raise Exception("Static surrogate name is missing in the config file.") # Start the execution environment. self._ipc, remote_pipe = EIPC.eipc_pair() self._ipc.start() self.__exec_env = Jailor(remote_pipe, self._config.getint('cpu', 'cores'), debug=debug_jail) self.__exec_env.start() # Register the callback function. self._ipc.register_function(self.task_callback) # Create an RPC server that the clients can connect to. try: self.rpc_server = SCRPC() scavenger_port = self.rpc_server.get_address()[1] self.rpc_server.register_function(self.perform_task) self.rpc_server.register_function(self.perform_task_intent) self.rpc_server.register_function(self.install_task) self.rpc_server.register_function(self.has_task) self.rpc_server.register_function(self.ping) self.__logger.info('StaticSurrogate daemon is listening on port %i'%scavenger_port) except Exception, e: self.__logger.exception('Error creating RPC server.') try: self.__exec_env.shutdown() if self.rpc_server: self.rpc_server.stop(True) except: pass raise e
def __init__(self, jailor, cores, basedir): """ Constructor. @type jailor: Jailor @param jailor: The Jailor instance controlling this scheduler. @type cores: int @param cores: The number of cores/CPUs to use. @type basedir: str @param basedir: The base directory where task code is stored. """ super(Scheduler, self).__init__() # Check the input. if cores <= 0: raise ValueError('Invalid number of cores (%i)'%cores) # Store local members. self.__cores = cores self.__jailor = jailor self.__shutdown = False # Spawn a thread for each core/cpu. self.__schedulers = [] for i in range(0, cores): local_ipc, remote_ipc = EIPC.eipc_pair() self.__schedulers.append((CoreScheduler(remote_ipc, basedir), local_ipc)) local_ipc.register_function(self.corescheduler_callback, "callback") local_ipc.start() self.__schedulers[i][0].start() # Set state variables. self.__execution_id = 0 self.__next_scheduler = 0 # Get a logger. self.__logger = logging.getLogger('scheduler') self.__logger.info('%i core scheduler(s) spawned'%cores)