def __init__(self, replicate_on_write=False):

        self.replicate_on_write = replicate_on_write

        use_daemon = rospy.get_param('mongodb_use_daemon', False)
	# If you want to use a remote datacenter, then it should be set as false
	use_localdatacenter = rospy.get_param('~mongodb_use_localdatacenter', True)
        
	if use_daemon:            
            db_host = rospy.get_param('mongodb_host')
            db_port = rospy.get_param('mongodb_port')
            is_daemon_alive = dc_util.check_connection_to_mongod(db_host, db_port)
            if not is_daemon_alive:
                raise Exception("No Daemon?")
        else:	  
	  if use_localdatacenter:
            have_dc = dc_util.wait_for_mongo()
            if not have_dc:
                raise Exception("No Datacentre?")
          # move these to after the wait_for_mongo check as they may not be set before the db is available
          db_host = rospy.get_param('mongodb_host')
          db_port = rospy.get_param('mongodb_port')


        self._mongo_client=MongoClient(db_host, db_port)


        extras = rospy.get_param('mongodb_store_extras', [])
        self.extra_clients = []
        for extra in extras:
            try:
                self.extra_clients.append(MongoClient(extra[0], extra[1]))
            except pymongo.errors.ConnectionFailure, e:
                rospy.logwarn('Could not connect to extra datacentre at %s:%s' % (extra[0], extra[1]))
Beispiel #2
0
    def test_replication(self):
        replication_db = "replication_test"
        replication_col = "replication_test"
        # connect to destination for replication
        try:
            self.assertTrue(wait_for_mongo(ns="/datacentre2"), "wait for mongodb server")
            dst_client = import_MongoClient()("localhost", 49163)
            count = dst_client[replication_db][replication_col].count()
            self.assertEqual(count, 0, "No entry in destination")
        except pymongo.errors.ConnectionFailure:
            self.fail("Failed to connect to destination for replication")

        # insert an entry to move
        self.assertTrue(wait_for_mongo(), "wait for mongodb server")
        msg_store = MessageStoreProxy(
            database=replication_db, collection=replication_col)
        msg = Wrench()
        msg_name = "replication test message"
        self.assertIsNotNone(msg_store.insert_named(msg_name, msg), "inserted message")

        # move entries
        rospy.sleep(3)
        retcode = subprocess.check_call([
            get_script_path(),
            '--move-before', '0',
            replication_db, replication_col])
        self.assertEqual(retcode, 0, "replicator_client returns code 0")

        # check if replication was succeeded
        rospy.sleep(3)
        count = dst_client[replication_db][replication_col].count()
        self.assertGreater(count, 0, "entry moved to the destination")

        # test deletion after move
        data, meta = msg_store.query_named(msg_name, Wrench._type)
        self.assertIsNotNone(data, "entry is still in source")
        retcode = subprocess.check_call([
            get_script_path(),
            '--move-before', '0',
            '--delete-after-move',
            replication_db, replication_col])
        self.assertEqual(retcode, 0, "replicator_client returns code 0")
        data, meta = msg_store.query_named("replication test", Wrench._type)
        self.assertIsNone(data, "moved entry is deleted from source")
    def __init__(self, replicate_on_write=False):

        use_daemon = rospy.get_param('mongodb_use_daemon', False)
        # If you want to use a remote datacenter, then it should be set as false
        use_localdatacenter = rospy.get_param('~mongodb_use_localdatacenter',
                                              True)
        local_timeout = rospy.get_param('~local_timeout', 10)
        if str(local_timeout).lower() == "none":
            local_timeout = None

        # wait for hostname and port for mongodb server
        for _ in range(10):
            if rospy.has_param('mongodb_host') and rospy.has_param(
                    'mongodb_port'):
                break
            rospy.sleep(1.0)
        db_host = rospy.get_param('mongodb_host')
        db_port = rospy.get_param('mongodb_port')

        if use_daemon:
            is_daemon_alive = dc_util.check_connection_to_mongod(
                db_host, db_port)
            if not is_daemon_alive:
                raise Exception("No Daemon?")
        elif use_localdatacenter:
            rospy.loginfo('Waiting for local datacentre (timeout: %s)' %
                          str(local_timeout))
            have_dc = dc_util.wait_for_mongo(local_timeout)
            if not have_dc:
                raise Exception("No Datacentre?")

        self.keep_trash = rospy.get_param('mongodb_keep_trash', True)

        self._mongo_client = MongoClient(db_host, db_port)

        self.replicate_on_write = rospy.get_param("mongodb_replicate_on_write",
                                                  replicate_on_write)
        if self.replicate_on_write:
            rospy.logwarn(
                "The option 'replicate_on_write' is now deprecated and will be removed. "
                "Use 'Replication' on MongoDB instead: "
                "https://docs.mongodb.com/manual/replication/")

            extras = rospy.get_param('mongodb_store_extras', [])
            self.extra_clients = []
            for extra in extras:
                try:
                    self.extra_clients.append(MongoClient(extra[0], extra[1]))
                except pymongo.errors.ConnectionFailure, e:
                    rospy.logwarn(
                        'Could not connect to extra datacentre at %s:%s' %
                        (extra[0], extra[1]))
            rospy.loginfo('Replicating content to a futher %s datacentres',
                          len(self.extra_clients))
Beispiel #4
0
    def test_replication_with_query(self):
        replication_db = "replication_test_with_query"
        replication_col = "replication_test_with_query"
        # connect to destination for replication
        try:
            self.assertTrue(wait_for_mongo(ns="/datacentre2"), "wait for mongodb server")
            dst_client = import_MongoClient()("localhost", 49163)
            count = dst_client[replication_db][replication_col].count()
            self.assertEqual(count, 0, "No entry in destination")
        except pymongo.errors.ConnectionFailure:
            self.fail("Failed to connect to destination for replication")

        # insert an entry to move
        self.assertTrue(wait_for_mongo(), "wait for mongodb server")
        msg_store = MessageStoreProxy(
            database=replication_db, collection=replication_col)
        for i in range(5):
            msg = Wrench()
            msg.force.x = i
            msg_store.insert(msg)
            msg = Pose()
            msg.position.x = i
            msg_store.insert(msg)

        # move entries with query
        rospy.sleep(3)
        query = {'_meta.stored_type': Pose._type}
        retcode = subprocess.check_call([
            get_script_path(),
            '--move-before', '0',
            '--query', json_util.dumps(query),
            replication_db, replication_col])
        self.assertEqual(retcode, 0, "replicator_client returns code 0")

        # check if replication was succeeded
        rospy.sleep(3)
        count = dst_client[replication_db][replication_col].count()
        self.assertEqual(count, 5, "replicated entry exists in destination")
Beispiel #5
0
    def __init__(self):
        rospy.init_node("mongo_bridge")

        have_dc = dc_util.wait_for_mongo()
        if not have_dc:
            raise Exception("No Datacentre?")

        self._mongo_client = pymongo.MongoClient(rospy.get_param("mongodb_host"), rospy.get_param("mongodb_port"))

        # advertise ros services
        for attr in dir(self):
            if attr.endswith("_ros_srv"):
                service = getattr(self, attr)
                rospy.Service("/mongo_bridge/" + attr[:-8], service.type, service)
Beispiel #6
0
    def __init__(self):
        rospy.init_node("mongo_bridge")

        have_dc = dc_util.wait_for_mongo()
        if not have_dc:
            raise Exception("No Datacentre?")

        self._mongo_client=pymongo.MongoClient(rospy.get_param("mongodb_host"),
                                               rospy.get_param("mongodb_port") )

        # advertise ros services
        for attr in dir(self):
            if attr.endswith("_ros_srv"):
                service=getattr(self, attr)
                rospy.Service("/mongo_bridge/"+attr[:-8], service.type, service)
    def __init__(self, replicate_on_write=False):

        self.replicate_on_write = replicate_on_write

        have_dc = dc_util.wait_for_mongo()
        if not have_dc:
            raise Exception("No Datacentre?")

        self._mongo_client=MongoClient(rospy.get_param("mongodb_host"),
                                              rospy.get_param("mongodb_port") )


        extras = rospy.get_param('mongodb_store_extras', [])
        self.extra_clients = []
        for extra in extras:
            try:
                self.extra_clients.append(MongoClient(extra[0], extra[1]))
            except pymongo.errors.ConnectionFailure, e:
                rospy.logwarn('Could not connect to extra datacentre at %s:%s' % (extra[0], extra[1]))
    def __init__(self, replicate_on_write=False):

        self.replicate_on_write = replicate_on_write

        have_dc = dc_util.wait_for_mongo()
        if not have_dc:
            raise Exception("No Datacentre?")

        self._mongo_client = MongoClient(rospy.get_param("mongodb_host"),
                                         rospy.get_param("mongodb_port"))

        extras = rospy.get_param('mongodb_store_extras', [])
        self.extra_clients = []
        for extra in extras:
            try:
                self.extra_clients.append(MongoClient(extra[0], extra[1]))
            except pymongo.errors.ConnectionFailure, e:
                rospy.logwarn(
                    'Could not connect to extra datacentre at %s:%s' %
                    (extra[0], extra[1]))
Beispiel #9
0
    def __init__(self):
        rospy.init_node("monitor_logs")

        have_dc = dc_util.wait_for_mongo()
        if not have_dc:
            raise Exception("No Datacentre?")

        self._mongo_client = pymongo.MongoClient(
            rospy.get_param("mongodb_host"), rospy.get_param("mongodb_port"))

        #self.topics_to_check = rospy.get_param("topics", "/tf \
        #                                                  /scan \
        #                                                  /odom \
        #                                                  /robot_pose \
        self.topics_to_check = rospy.get_param(
            "topics", "/amcl_pose \
                                                          /current_node \
                                                          /current_edge \
                                                          /map \
                                                          /topological_map \
                                                          /rosout_filtered \
                                                          /topological_navigation/Route \
                                                          /topological_navigation/Statistics \
                                                          /current_node \
                                                          /current_edge \
                                                          /closest_node \
                                                          /do_backtrack/goal \
                                                          /speak/goal \
                                                          /strands_emails/goal \
                                                          /strands_image_tweets/goal \
                                                          /chargingServer/goal \
                                                          /chargingServer/result \
                                                          /chargingServer/cancel \
                                                          /docking/goal \
                                                          /docking/result \
                                                          /docking/cancel \
                                                          /undocking/goal \
                                                          /undocking/result \
                                                          /undocking/cancel \
                                                          /map_updates \
                                                          /move_base/current_goal \
                                                          /charging_task/goal \
                                                          /charging_task/result \
                                                          /charging_task/cancel \
                                                          /maintenance_task/goal \
                                                          /maintenance_task/result \
                                                          /maintenance_task/cancel \
                                                          /task_executor/events \
                                                          /emergency_stop_status \
                                                          /info_terminal/active_screen \
                                                          /info_terminal/task_outcome \
                                                          /info_task_server/goal \
                                                          /info_task_server/result \
                                                          /info_task_server/cancel \
                                                          /bellbot/goal \
                                                          /bellbot/result \
                                                          /bellbot/cancel \
                                                          /walking_group_fast/goal \
                                                          /walking_group_fast/result \
                                                          /walking_group_fast/cancel \
                                                          /walking_group_slow/goal \
                                                          /walking_group_slow/result \
                                                          /walking_group_slow/cancel \
                                                          /store_logs/cancel \
                                                          /store_logs/goal \
                                                          /store_logs/result \
                                                          /strands_webserver/display_1/page \
                                                          /strands_webserver/display_2/page \
                                                          /strands_webserver/display_3/page \
                                                          /strands_webserver/display_4/page \
                                                          /strands_webserver/display_5/page \
                                                          /strands_webserver/display_6/page \
                                                          /strands_webserver/display_7/page \
                                                          /strands_webserver/display_8/page \
                                                          /strands_webserver/display_9/page"
        )
        self.topic_list = self.topics_to_check.split()

        self.topics_map = {}

        self.pub = rospy.Publisher('monitored_logs', String, queue_size=10)
        self.timer = rospy.Timer(rospy.Duration(30), self.timer_callback)