def is_compatible(concert_client, resource): ''' Checks to see if a client is compatible for the implementation's node rule. :param scheduler_msgs.Resource resource: :param concert_msgs.ConcertClient: concert_client :returns: true if compatible, false otherwise :rtype: bool ''' if not rocon_uri.is_compatible(resource.uri, concert_client.platform_info.uri): return False for client_rapp in concert_client.rapps: if resource.rapp == client_rapp.name: return True return False
def is_compatible(concert_client, resource): ''' Checks to see if a client is compatible for the implementation's node rule. @param resource @type scheduler_msgs.Resource @param concert_client @type concert_msgs.ConcertClient ''' if not rocon_uri.is_compatible(resource.uri, concert_client.platform_info.uri): return False for client_app in concert_client.apps: if resource.rapp == client_app.name: return True return False
def is_compatible(self, uri): ''' it compares its compatibility with given uri. and returns true if it is compatible. If it is virtual rapp which does not have compatibility field, return True always :param uri: rocon_uri :type uri: rocon_uri.RoconURI :returns: true if compatible :rtype: bool ''' my_uri = self.raw_data['compatibility'] if 'compatibility' in self.raw_data else None if my_uri: return rocon_uri.is_compatible(my_uri, uri) else: return True
def match_pattern(self, pattern, rapp): """ Match this resource to a ROCON name and application. :param pattern: Canonical ROCON name to match, maybe a regular expression. :type pattern: str :param rapp: ROCON application name. :type rapp: str :returns: ``True`` if this specific resource matches. :raises: :class:`.RoconURIValueError` if *pattern* invalid. The *rapp* must be one of those advertised by this ROCON resource. The *pattern* may be a ROCON pattern matching multiple resource names. """ if rapp not in self.rapps: # rapp not advertised here? return False return rocon_uri.is_compatible(self.uri, pattern)
def filter(self, roles=None, compatibility_uri='rocon:/'): ''' Filter the interactions in the table according to role and/or compatibility uri. :param roles: a list of roles to filter against, use all roles if None :type roles: str [] :param str compatibility_uri: compatibility rocon_uri_, eliminates interactions that don't match this uri. :returns interactions: subset of all interactions that survived the filter :rtype: :class:`.Interaction` [] :raises: rocon_uri.RoconURIValueError if provided compatibility_uri is invalid. ''' if roles: # works for classifying non-empty list vs either of None or empty list role_filtered_interactions = [i for i in self.interactions if i.role in roles] else: role_filtered_interactions = list(self.interactions) filtered_interactions = [i for i in role_filtered_interactions if rocon_uri.is_compatible(i.compatibility, compatibility_uri)] return filtered_interactions
def filter(self, roles=None, compatibility_uri='rocon:/'): ''' Filter the interactions in the table according to role and/or compatibility uri. :param roles: a list of roles to filter against, use all roles if None :type roles: str [] :param str compatibility_uri: compatibility rocon_uri_, eliminates interactions that don't match this uri. :returns interactions: subset of all interactions that survived the filter :rtype: :class:`.Interaction` [] :raises: rocon_uri.RoconURIValueError if provided compatibility_uri is invalid. ''' if roles: # works for classifying non-empty list vs either of None or empty list role_filtered_interactions = [ i for i in self.interactions if i.role in roles ] else: role_filtered_interactions = list(self.interactions) filtered_interactions = [ i for i in role_filtered_interactions if rocon_uri.is_compatible(i.compatibility, compatibility_uri) ] return filtered_interactions
def filter(self, roles=None, compatibility_uri='rocon:/'): ''' Filter the interactions in the table according to role and/or compatibility uri. @param roles : a list of roles to filter against, use all roles if None @type str[] @param compatibility_uri : compatibility rocon uri, eliminates interactions that don't match this uri. @type str (rocon_uri) @return interactions : subset of all interactions that survived the filter @rtype interactions.Interactions[] ''' if roles: # works for classifying non-empty list vs either of None or empty list role_filtered_interactions = [ i for i in self.interactions if i.role in roles ] else: role_filtered_interactions = list(self.interactions) filtered_interactions = [ i for i in role_filtered_interactions if rocon_uri.is_compatible(i.compatibility, compatibility_uri) ] return filtered_interactions
def _determine_runnable_rapps(self, rapps): ''' Prune unsupported apps due to incompatibilities in platform information or lack of support for required capabilities. @param rapps: an index of rapps to check @type dic name : Rapp @return incompatible app list dictionaries for platform and capability incompatibilities respectively @type 2-tuple of app list dictionaries ''' # First try initialise the list of available capabilities no_caps_available = False try: self.caps_list = CapsList() except IOError as e: if 'timeout' in str(e): rospy.loginfo( "App Manager : disabling apps requiring capabilities [timed out looking for the capability server]" ) else: rospy.logwarn( "App Manager : disabling apps requiring capabilities [%s]" % str(e)) no_caps_available = True # Then add runable apps to list self.apps['runnable'] = {} platform_compatible_apps = {} platform_filtered_apps = {} capabilities_filtered_apps = {} for app_name in rapps: app = rapps[app_name] # Platform check if rocon_uri.is_compatible(self._rocon_uri, app.data['compatibility']): platform_compatible_apps[app.data['name']] = app else: platform_filtered_apps[app.data['name']] = app rospy.logwarn("App : '" + str(app.data['name']) + "' is incompatible [" + app.data['compatibility'] + '][' + self._rocon_uri + ']') for app_name in platform_compatible_apps: app = platform_compatible_apps[app_name] if no_caps_available: if 'required_capabilities' in app.data: capabilities_filtered_apps[app.data['name']] = app rospy.logwarn( "App : '" + str(app.data['name']) + "' cannot be run, since capabilities are not available." + " App will be excluded from the list of runnable apps." ) else: self.apps['runnable'][app.data['name']] = app rospy.loginfo("App : '" + str(app.data['name']) + "' added to the list of runnable apps.") else: try: self.caps_list.compatibility_check(app) self.apps['runnable'][app.data['name']] = app rospy.loginfo("App : '" + str(app.data['name']) + "' added to the list of runnable apps.") except exceptions.MissingCapabilitiesException as e: capabilities_filtered_apps[app.data['name']] = app rospy.logwarn( "App : '" + str(app.data['name']) + "' cannot be run, since some required capabilities (" + str(e.missing_caps) + ") are not installed. App will be excluded from the list of runnable apps." ) return (platform_filtered_apps, capabilities_filtered_apps)
def test_compatibility(): print( console.bold + "\n****************************************************************************************" + console.reset) print(console.bold + "* Compatibility" + console.reset) print( console.bold + "****************************************************************************************" + console.reset) rocon_uri_string = 'rocon:/turtlebot2/dude/hydro/precise' print(console.cyan + " - %s ~ %s" % (rocon_uri_string, rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, rocon_uri_string) == True) # Missing operating system modified_rocon_uri_string = 'rocon:/turtlebot2/dude/hydro' print(console.cyan + " - %s ~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == True) # Missing application_framework/operating system modified_rocon_uri_string = 'rocon:/turtlebot2/dude' print(console.cyan + " - %s ~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == True) # Missing everything modified_rocon_uri_string = 'rocon:/' print(console.cyan + " - %s ~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == True) # Wildcards modified_rocon_uri_string = 'rocon:/*/*/*/*' print(console.cyan + " - %s ~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == True) # Regex names modified_rocon_uri_string = 'rocon:/turtlebot2/dud*/hydro/precise' print(console.cyan + " - %s ~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == True) modified_rocon_uri_string = 'rocon:/turtlebot2/dud*/hydro/precise' print(console.cyan + " - %s ~ %s" % (modified_rocon_uri_string, rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(modified_rocon_uri_string, rocon_uri_string) == True) doubly_modified_rocon_uri_string = 'rocon:/turtlebot2/dudette*/hydro/precise' print(console.cyan + " - %s ~ %s" % (modified_rocon_uri_string, doubly_modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(modified_rocon_uri_string, doubly_modified_rocon_uri_string) == True) # No matching hardware platform modified_rocon_uri_string = 'rocon:/pr2|waiterbot/dude' print(console.cyan + " - %s !~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == False) # Modified field modified_rocon_uri_string = 'rocon:/turtlebot2/dudette/hydro/precise' print(console.cyan + " - %s !~ %s" % (rocon_uri_string, modified_rocon_uri_string) + console.reset) assert (rocon_uri.is_compatible(rocon_uri_string, modified_rocon_uri_string) == False) invalid_rocon_uri = 'rocon:/lala|turtlebot2' try: rocon_uri.is_compatible(rocon_uri_string, invalid_rocon_uri) except rocon_uri.RoconURIValueError as e: print(console.cyan + " - %s FAILS %s [%s]" % (rocon_uri_string, invalid_rocon_uri, str(e)) + console.reset) assert_raises(rocon_uri.RoconURIValueError, rocon_uri.is_compatible, rocon_uri_string, invalid_rocon_uri)