コード例 #1
0
 def move_entries(self,
                  move_before=None,
                  delete_after_move=False,
                  query=None):
     move_before = move_before or rospy.Duration(self.interval)
     if query is None:
         query = {}
     query = StringPairList(pairs=[
         StringPair(first=MongoQueryMsgRequest.JSON_QUERY,
                    second=json_util.dumps(query))
     ])
     goal = MoveEntriesGoal(database=self.database,
                            collections=StringList(self.collections),
                            move_before=move_before,
                            delete_after_move=delete_after_move,
                            query=query)
     self.replicate_ac.send_goal(goal,
                                 done_cb=self.done_cb,
                                 active_cb=self.active_cb,
                                 feedback_cb=self.feedback_cb)
     while not self.replicate_ac.wait_for_result(
             timeout=rospy.Duration(5.0)):
         if rospy.is_shutdown():
             break
         elif self.monitor_network and not self.network_connected:
             rospy.loginfo(
                 "disconnected wired network connection. canceling replication..."
             )
             self.replicate_ac.cancel_all_goals()
コード例 #2
0
 def move_entries(self, move_before):
     client = actionlib.SimpleActionClient('move_mongodb_entries',
                                           MoveEntriesAction)
     client.wait_for_server()
     goal = MoveEntriesGoal(database=self.database,
                            collections=StringList(self.collections),
                            move_before=move_before,
                            delete_after_move=self.delete_after_move)
     client.send_goal(goal, feedback_cb=self.feedback_cb)
     client.wait_for_result()
コード例 #3
0
    def execute(self, goal):
        target = goal.wait_until
        target.secs -= 10  # Making sure the wait finishes before the window ends.

        rospy.loginfo(
            "Starting data transfer. This task is not interruptible.")
        self.running = False
        g = MoveEntriesGoal()
        g.database = rospy.get_param('~database', 'message_store')

        p = str(rospy.get_param('~collections', '[]'))
        self.collections = load(p)
        g.collections = StringList(self.collections)

        hours = rospy.get_param('~past_hours', 24)
        time_ago = rospy.Duration(60 * 60 * hours)
        g.move_before = time_ago

        retries = int(rospy.get_param('retries', 3))

        t = 0
        state = 0

        while t < retries and state != GoalStatus.SUCCEEDED:
            t = t + 1
            rospy.loginfo(
                "Starting data upload of collections %s (try %d of %d)" %
                (g.collections, t, retries))
            self.client.send_goal(g, feedback_cb=self.feeback_cb)
            self.client.wait_for_result()
            state = self.client.get_state()
            if state != GoalStatus.SUCCEEDED:
                rospy.logwarn('Data replication failed.')

        if state != GoalStatus.SUCCEEDED:
            rospy.logerr(
                'Data replication failed for some reason after %d tries. '
                'Check mongodb logs. Will still continue to wait in this action. '
                'Data upload exited with state %s. Waiting ...' %
                (retries, state))
        rospy.loginfo("From now on I'm interruptible and will just wait")
        self.interruptible = True

        while not rospy.is_shutdown() and not self.server.is_preempt_requested(
        ) and rospy.get_rostime() < target:
            rospy.sleep(1.0)

        rospy.loginfo("WAKE UP!")

        if self.server.is_preempt_requested():
            self.server.set_preempted()
        elif state == GoalStatus.SUCCEEDED:
            self.server.set_succeeded()
        else:
            self.server.set_aborted()
コード例 #4
0
 def move_entries(self, move_before):
     goal = MoveEntriesGoal(database=self.database,
                            collections=StringList(self.collections),
                            move_before=move_before,
                            delete_after_move=self.delete_after_move)
     self.replicate_ac.send_goal(goal,
                                 active_cb=self.active_cb,
                                 feedback_cb=self.feedback_cb)
     while not self.replicate_ac.wait_for_result(timeout=rospy.Duration(5.0)):
         if self.disable_on_wireless_network and not self.network_connected:
             rospy.loginfo("disconnected wired network connection. canceling replication...")
             self.cancel()
コード例 #5
0
 def insert_replicate_date(self):
     try:
         self.date_msg_store.insert(StringList(self.collections))
     except Exception as e:
         rospy.logwarn(
             "failed to insert last replicate date to database: %s", e)
コード例 #6
0
    args = parse_args(rospy.myargv()[1:])

    # validate parameters
    try:
        data = json_util.loads(args.query)
        query = StringPairList(pairs=[
            StringPair(first=MongoQueryMsgRequest.JSON_QUERY,
                       second=json_util.dumps(data))
        ])
    except:
        raise ValueError('The query is invalid')
    if args.move_before < 0:
        raise ValueError('move_before time must be >= 0')
    move_before = rospy.Duration(args.move_before)
    goal = MoveEntriesGoal(database=args.database,
                           collections=StringList(args.collection),
                           move_before=move_before,
                           delete_after_move=args.delete_after_move,
                           query=query)

    rospy.loginfo('Moves entries from (db: %s, cols: %s)' %
                  (args.database, args.collection))
    rospy.loginfo('before time: %s' % (rospy.Time.now() - move_before))
    rospy.loginfo('delete after move: %s' % args.delete_after_move)
    rospy.loginfo('with query: %s' % args.query)

    client = actionlib.SimpleActionClient('move_mongodb_entries',
                                          MoveEntriesAction)
    client.wait_for_server()

    client.send_goal(goal, feedback_cb=feedback)
コード例 #7
0
import actionlib
from mongodb_store_msgs.msg import MoveEntriesAction, MoveEntriesGoal, StringList
import sys


def feedback(feedback):
    print feedback


if __name__ == '__main__':
    rospy.init_node("mongodb_replicator_client")

    client = actionlib.SimpleActionClient('move_mongodb_entries',
                                          MoveEntriesAction)
    client.wait_for_server()

    database = sys.argv[1]
    collections = sys.argv[2:]

    print database
    print collections

    # but this is the default anyway
    twenty_four_hrs_ago = rospy.Duration(60 * 60 * 24)
    goal = MoveEntriesGoal(database=database,
                           collections=StringList(collections),
                           move_before=twenty_four_hrs_ago,
                           delete_after_move=True)

    client.send_goal(goal, feedback_cb=feedback)
    client.wait_for_result()