def _process_start_client(self, client, branch):
     '''
       Used to start a single client. This is done when a client dynamically joins after the solution has started.
     '''
     app_name = branch.node.tuple.split('.')[3]
     node_name = branch.node.id
     remappings = []
     implementation = self._implementation.to_msg()
     link_graph = implementation.link_graph
     for edge in link_graph.edges:
         if edge.start == node_name or edge.finish == node_name:
             remappings.append((edge.remap_from, edge.remap_to))
     rospy.loginfo("            node: %s/%s" % (node_name, client.name))
     rospy.loginfo("              app: %s" % app_name)
     rospy.loginfo("              remaps")
     for (remap_from, remap_to) in remappings:
         rospy.loginfo("                %s->%s" % (remap_from, remap_to))
     # Check to see if start app service exists for the node, abort if not
     start_app_name = '/' + client.gateway_name + '/start_app'
     rospy.wait_for_service(start_app_name)
     start_app = rospy.ServiceProxy(start_app_name,
                                    rapp_manager_srvs.StartApp)
     req = rapp_manager_srvs.StartAppRequest()
     req.name = app_name
     req.remappings = []
     for remapping in remappings:
         req.remappings.append(
             rapp_manager_msgs.Remapping(remapping[0], remapping[1]))
     rospy.loginfo("              Starting...")
     resp = start_app(req)
     if not resp.started:
         rospy.logwarn("              failed to start app %s" % (app_name))
 def start_app(self, app_name, remappings):
     '''
       @param app_name : string unique identifier for the app
       @type string
       @param remappings : list of (from,to) pairs
       @type list of tuples
     '''
     self._start_app_service.wait_for_service()
     req = rapp_manager_srvs.StartAppRequest()
     req.name = app_name
     req.remappings = []
     for remapping in remappings:
         req.remappings.append(
             rapp_manager_msgs.Remapping(remapping[0], remapping[1]))
     unused_resp = self._start_app_service(req)
Exemple #3
0
 def _start(self, gateway_name, resource):
     if self._resource == None:
         raise FailedToStartAppsException(
             "this client hasn't been allocated yet [%s]" % self.name)
     start_app = rospy.ServiceProxy('/' + gateway_name + '/start_app',
                                    rapp_manager_srvs.StartApp)
     request = rapp_manager_srvs.StartAppRequest()
     request.name = resource.rapp
     request.remappings = resource.remappings
     try:
         start_app(request)
     except (rospy.service.ServiceException,
             rospy.exceptions.ROSInterruptException
             ) as e:  # Service not found or ros is shutting down
         raise FailedToStartAppsException("%s" % str(e))
    def start(self, rapp, remappings):
        """
        Start the rapp with the specified remappings.

        :param rapp str: name of the rapp to start (e.g. rocon_apps/teleop)
        :param remappings ??: remappings to apply to the rapp when starting.

        :raises: :exc:`.FailedToStartRappError`
        """
        request = rapp_manager_srvs.StartAppRequest()
        request.name = rapp
        request.remappings = remappings
        try:
            self.start_rapp(request)
        except (rospy.service.ServiceException,
                rospy.exceptions.ROSInterruptException) as e:
            # Service not found or ros is shutting down
            raise FailedToStartRappError("%s" % str(e))
    def __init__(self):
        self._namespace = None  # Namespace that gets used as default namespace for rapp connections
        self._gateway_name = None  # Name of our local gateway (if available)
        self._gateway_ip = None  # IP/Hostname of our local gateway if available
        self._remote_name = None  # Name (gateway name) for the entity that is remote controlling this app manager
        self._current_rapp = None  # App that is running, otherwise None
        self._application_namespace = None  # Push all app connections underneath this namespace
        roslaunch.pmon._init_signal_handlers()
        self._services = {}
        self._publishers = {}
        self._rospack = rospkg.RosPack(
        )  # used to speed up searches for resources

        self._param = setup_ros_parameters()
        (self._rocon_uri, self._icon) = self._set_platform_info()
        self._init_gateway_services()
        self._init_default_service_names()

        self.apps = {}
        self.app_list_file = {}
        self.caps_list = {}
        self._initialising_services = False

        self._preinstalled_apps = self._load_installed_rapps(
        )  # parses exported rapps from the package path
        (platform_filtered_apps,
         capabilities_filtered_apps) = self._determine_runnable_rapps(
             self._preinstalled_apps)
        self._init_services()
        self._private_publishers = self._init_private_publishers()
        self._publish_app_list()
        self._publishers['incompatible_app_list'].publish(
            [], [], self._get_app_msg_list(platform_filtered_apps),
            self._get_app_msg_list(capabilities_filtered_apps))

        if self._param['auto_start_rapp']:  # None and '' are both false here
            request = rapp_manager_srvs.StartAppRequest(
                self._param['auto_start_rapp'], [])
            unused_response = self._process_start_app(request)

        self._debug_ignores = {
        }  # a remote_controller_name : timestamp of the last time we logged an ignore response
        rospy.loginfo("App Manager : initialised.")
    def _process_start_solution(self, req):
        # Put in checks to see if a solution is already running
        response = concert_srvs.StartSolutionResponse()
        if not self._pruned_compatibility_tree.is_valid():
            response.success = False
            response.message = "cowardly refused to start the solution [%s]..." % self._pruned_compatibility_tree.error_message
            rospy.loginfo("Orchestration : %s" % response.message)
            self._pruned_compatibility_tree.print_branches()
            return response
        if self._solution_running:
            rospy.logwarn("Orchestration : %s" % response.message)
            response.message = "chincha? the solution is already running..."
            response.success = False
            return response
        implementation = self._implementation.to_msg()
        response.success = True
        response.message = "bonza"
        link_graph = implementation.link_graph

        rospy.loginfo("Orchestra : starting solution [%s]" %
                      implementation.name)
        for branch in self._pruned_compatibility_tree.branches:
            app_name = branch.node.tuple.split('.')[3]
            node_name = branch.node.id
            remappings = []
            for edge in link_graph.edges:
                if edge.start == node_name or edge.finish == node_name:
                    remappings.append((edge.remap_from, edge.remap_to))
            for leaf in branch.leaves:
                concert_client_name = leaf.name
                rospy.loginfo("            node: %s/%s" %
                              (node_name, concert_client_name))
                rospy.loginfo("              app: %s" % app_name)
                rospy.loginfo("              remaps")
                for (remap_from, remap_to) in remappings:
                    rospy.loginfo("                %s->%s" %
                                  (remap_from, remap_to))
                # Check to see if start app service exists for the node, abort if not
                start_app_name = '/' + self._concert_clients[
                    concert_client_name].gateway_name + '/start_app'
                rospy.wait_for_service(start_app_name)
                start_app = rospy.ServiceProxy(start_app_name,
                                               rapp_manager_srvs.StartApp)
                req = rapp_manager_srvs.StartAppRequest()
                req.name = app_name
                req.remappings = []
                for remapping in remappings:
                    req.remappings.append(
                        rapp_manager_msgs.Remapping(remapping[0],
                                                    remapping[1]))
                rospy.loginfo("              Starting...")
                resp = start_app(req)
                if not resp.started:
                    response.success = False
                    response.message = "aigoo, failed to start app %s of %s" % (
                        app_name, concert_client_name)
                    rospy.logwarn("              failed to start app %s" %
                                  (app_name))
        if response.success:
            rospy.loginfo("Orchestra: All clients' app are started")
        else:
            rospy.logwarn("Orchestra: " + response.message)

        self._solution_running = True
        return response