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)
    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