def _psco_publish(self, psco): # Persist the psco if its not if __debug__: logger.debug("Persisting user PSCO...") if psco.getID() is None: import uuid alias = str(uuid.uuid4()) psco.makePersistent(alias) psco_id = psco.getID() # Register the psco on the server if __debug__: logger.debug("Registering PSCO publish...") req = PublishRequest(self.id, psco_id) DistroStreamClientHandler.request(req) # Retrieve answer req.wait_processed() error = req.get_error_code() if error != 0: raise BackendException(error, req.get_error_msg()) # Parse answer answer = req.get_response_msg() # noqa if __debug__: logger.debug("Publish stream answer: " + str(answer))
def poll(self, timeout=None): logger.info("Polling new stream items...") # Send request to server req = PollRequest(self.id) DistroStreamClientHandler.request(req) # Retrieve answer req.wait_processed() error = req.get_error_code() if error != 0: raise BackendException(error, req.get_error_msg()) # Parse answer info = req.get_response_msg() if __debug__: logger.debug("Retrieved stream items: " + str(info)) from pycompss.util.storages.persistent import get_by_id retrieved_pscos = [] if info is not None and info and info != "null": for psco_id in info.split(): psco = get_by_id(psco_id) retrieved_pscos.append(psco) return retrieved_pscos
def close(self): if __debug__: logger.debug("Closing stream " + str(self.id)) # Ask for stream closure req = CloseStreamRequest(self.id) DistroStreamClientHandler.request(req) req.wait_processed() error = req.get_error_code() if error != 0: logger.error("ERROR: Cannot close stream") logger.error(" - Internal Error Code: " + str(error)) logger.error(" - Internal Error Msg: " + str(req.get_error_msg()))
def is_closed(self): if __debug__: logger.debug("Checking if stream " + str(self.id) + " is closed") # Ask for stream status req = StreamStatusRequest(self.id) DistroStreamClientHandler.request(req) req.wait_processed() error = req.get_error_code() if error != 0: logger.error("ERROR: Cannot retrieve stream status") logger.error(" - Internal Error Code: " + str(error)) logger.error(" - Internal Error Msg: " + str(req.get_error_msg())) return str2bool(req.get_response_msg())
def _request_bootstrap_server_info(): logger.info("Requesting bootstrap server...") req = BootstrapServerRequest() DistroStreamClientHandler.request(req) # Retrieve answer req.wait_processed() error = req.get_error_code() if error != 0: raise BackendException(error, req.get_error_msg()) # Parse answer answer = req.get_response_msg() if __debug__: logger.debug("Retrieved bootstrap server information: " + answer) return answer
def poll(self, timeout=None): logger.info("Polling new stream items...") # Send request to server req = PollRequest(self.id) DistroStreamClientHandler.request(req) # Retrieve answer req.wait_processed() error = req.get_error_code() if error != 0: raise BackendException(error, req.get_error_msg()) # Parse answer info = req.get_response_msg() if __debug__: logger.debug("Retrieved stream items: " + str(info)) if info is not None and info and info != "null": return info.split() else: return []
def __init__(self, alias=None, stream_type=None, access_mode=AT_MOST_ONCE, internal_stream_info=None): """ Creates a new DistroStream instance. :param alias: Stream alias. + type: string :param stream_type: Internal stream type. + type: StreamType :param access_mode: Stream access mode. + type: ConsumerMode :param internal_stream_info: Implementation specific information. + type: List<T> :raise RegistrationException: When client cannot register the stream into the server. """ super(DistroStreamImpl, self).__init__() if __debug__: logger.debug("Registering new stream...") self.alias = alias self.stream_type = stream_type self.access_mode = access_mode # Retrieve registration id req = RegisterStreamRequest(self.alias, self.stream_type, self.access_mode, internal_stream_info) DistroStreamClientHandler.request(req) req.wait_processed() error = req.get_error_code() if error != 0: raise RegistrationException(error, req.get_error_msg()) self.id = req.get_response_msg()