def _scan_item(timeout, my_uuid, srv_files_mgr, item): """Connect to item host:port (item) to get suite identify.""" host, port = item host_anon = host if is_remote_host(host): try: host_anon = get_host_ip_by_name(host) # IP reduces DNS traffic except socket.error as exc: if cylc.flags.debug: raise sys.stderr.write("ERROR: %s: %s\n" % (exc, host)) return (host, port, None) client = SuiteRuntimeServiceClient( None, host=host_anon, port=port, my_uuid=my_uuid, timeout=timeout, auth=SuiteRuntimeServiceClient.ANON_AUTH) try: result = client.identify() except ClientTimeout: return (host, port, MSG_TIMEOUT) except ClientError: return (host, port, None) else: owner = result.get(KEY_OWNER) name = result.get(KEY_NAME) states = result.get(KEY_STATES, None) if cylc.flags.debug: sys.stderr.write(' suite: %s %s\n' % (name, owner)) if states is None: # This suite keeps its state info private. # Try again with the passphrase if I have it. try: pphrase = srv_files_mgr.get_auth_item( srv_files_mgr.FILE_BASE_PASSPHRASE, name, owner, host, content=True) except SuiteServiceFileError: pass else: if pphrase: client.suite = name client.owner = owner client.auth = None try: result = client.identify() except ClientError: # Nope (private suite, wrong passphrase). if cylc.flags.debug: sys.stderr.write(' (wrong passphrase)\n') else: if cylc.flags.debug: sys.stderr.write( ' (got states with passphrase)\n') return (host, port, result)
def _send_by_remote_port(self, messages): """Send message by talking to the daemon (remote?) port.""" from cylc.network.httpclient import (SuiteRuntimeServiceClient, ClientError, ClientInfoError) # Convert time/duration into appropriate units retry_intvl = float( self.env_map.get(SuiteSrvFilesManager.KEY_TASK_MSG_RETRY_INTVL, self.MSG_RETRY_INTVL)) max_tries = int( self.env_map.get(SuiteSrvFilesManager.KEY_TASK_MSG_MAX_TRIES, self.MSG_MAX_TRIES)) client = SuiteRuntimeServiceClient( self.suite, owner=self.env_map.get(SuiteSrvFilesManager.KEY_OWNER), host=self.env_map.get(SuiteSrvFilesManager.KEY_HOST), port=self.env_map.get(SuiteSrvFilesManager.KEY_PORT), timeout=float( self.env_map.get(SuiteSrvFilesManager.KEY_TASK_MSG_TIMEOUT, self.MSG_TIMEOUT)), comms_protocol=self.env_map.get( SuiteSrvFilesManager.KEY_COMMS_PROTOCOL)) for i in range(1, max_tries + 1): # 1..max_tries inclusive try: for message in messages: client.put_message(self.task_id, self.severity, message) except ClientError as exc: sys.stderr.write( "%s WARNING - Send message: try %s of %s failed: %s\n" % (get_current_time_string(), i, max_tries, exc)) # Break if: # * Exhausted number of tries. # * Contact info file not found, suite probably not running. # Don't bother with retry, suite restart will poll any way. if i >= max_tries or isinstance(exc, ClientInfoError): # Issue a warning and let the task carry on sys.stderr.write("%s WARNING - MESSAGE SEND FAILED\n" % (get_current_time_string())) else: sys.stderr.write( " retry in %s seconds, timeout is %s\n" % (retry_intvl, client.timeout)) sleep(retry_intvl) # Reset in case contact info or passphrase change client.host = None client.port = None client.auth = None else: if i > 1: # Continue to write to STDERR, so users can easily see that # it has recovered from previous failures. sys.stderr.write( "%s INFO - Send message: try %s of %s succeeded\n" % (get_current_time_string(), i, max_tries)) break
def _scan_item(timeout, my_uuid, srv_files_mgr, item): """Connect to item host:port (item) to get suite identify.""" host, port = item host_anon = host if is_remote_host(host): host_anon = get_host_ip_by_name(host) # IP reduces DNS traffic client = SuiteRuntimeServiceClient( None, host=host_anon, port=port, my_uuid=my_uuid, timeout=timeout, auth=SuiteRuntimeServiceClient.ANON_AUTH) try: result = client.identify() except ClientTimeout: return (host, port, MSG_TIMEOUT) except ClientError: return (host, port, None) else: owner = result.get(KEY_OWNER) name = result.get(KEY_NAME) states = result.get(KEY_STATES, None) if cylc.flags.debug: sys.stderr.write(' suite: %s %s\n' % (name, owner)) if states is None: # This suite keeps its state info private. # Try again with the passphrase if I have it. try: pphrase = srv_files_mgr.get_auth_item( srv_files_mgr.FILE_BASE_PASSPHRASE, name, owner, host, content=True) except SuiteServiceFileError: pass else: if pphrase: client.suite = name client.owner = owner client.auth = None try: result = client.identify() except ClientError: # Nope (private suite, wrong passphrase). if cylc.flags.debug: sys.stderr.write(' (wrong passphrase)\n') else: if cylc.flags.debug: sys.stderr.write( ' (got states with passphrase)\n') return (host, port, result)