Skip to content

Commit

Permalink
added daemon version to crossbar
Browse files Browse the repository at this point in the history
  • Loading branch information
atiderko committed Nov 29, 2023
1 parent 8c9fdd2 commit cdb031a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,16 @@ def __init__(self,
self.size = size
self.size_min = size_min
self.size_max = size_max

class DaemonVersion:
'''
Version of the daemon node.
:param str version: version string.
:param str date: Date string.
'''

def __init__(self,
version: str,
date: str) -> None:
self.version = version
self.date = date
6 changes: 6 additions & 0 deletions fkie_node_manager_daemon/fkie_node_manager_daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from fkie_node_manager_daemon.parameter_servicer import ParameterServicer
from fkie_node_manager_daemon.rosstate_servicer import RosStateServicer
from fkie_node_manager_daemon.screen_servicer import ScreenServicer
from fkie_node_manager_daemon.version_servicer import VersionServicer


class Server:
Expand Down Expand Up @@ -74,6 +75,8 @@ def __init__(self, rosnode, *, default_domain_id=-1):
self.crossbar_loop, self.crossbar_realm, self.crossbar_port)
self.launch_servicer = LaunchServicer(
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, ros_domain_id=self.ros_domain_id)
self.version_servicer = VersionServicer(
self.crossbar_loop, self.crossbar_realm, self.crossbar_port)

rosnode.create_service(LoadLaunch, '~/start_launch',
self._rosservice_start_launch)
Expand All @@ -93,6 +96,7 @@ def __init__(self, rosnode, *, default_domain_id=-1):

def __del__(self):
self.crossbar_loop.stop()
self.version_servicer = None
self.launch_servicer = None
self.monitor_servicer = None
self.screen_servicer = None
Expand Down Expand Up @@ -131,6 +135,7 @@ def _crossbar_notify_if_regsitered(self):
registration_finished &= self.screen_servicer.crossbar_registered
registration_finished &= self.rosstate_servicer.crossbar_registered
registration_finished &= self.parameter_servicer.crossbar_registered
registration_finished &= self.version_servicer.crossbar_registered
time.sleep(0.5)
self.publish_daemon_state(True)
self._crossbar_send_status(True)
Expand All @@ -154,6 +159,7 @@ def shutdown(self):
WAIT_TIMEOUT = 3
self.publish_daemon_state(False)
self._crossbar_send_status(False)
self.version_servicer.stop()
self.screen_servicer.stop()
self.launch_servicer.stop()
self.file_servicer.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import fkie_node_manager_daemon.grpc_proto.version_pb2_grpc as vgrpc
import fkie_node_manager_daemon.grpc_proto.version_pb2 as vmsg
import asyncio
from autobahn import wamp
import json
from fkie_multimaster_pylib.crossbar.base_session import CrossbarBaseSession
from fkie_multimaster_pylib.crossbar.base_session import SelfEncoder
from fkie_multimaster_pylib.crossbar.runtime_interface import DaemonVersion
from fkie_multimaster_pylib.logging.logging import Log
import fkie_node_manager_daemon as nmd
from . import version


class VersionServicer(vgrpc.VersionServiceServicer):
class VersionServicer(CrossbarBaseSession):

def __init__(self):
nmd.ros_node.get_logger().info("Create version servicer")
vgrpc.VersionServiceServicer.__init__(self)
def __init__(self, loop: asyncio.AbstractEventLoop, realm: str = 'ros', port: int = 11911):
Log.info("Create ROS2 version servicer")
CrossbarBaseSession.__init__(self, loop, realm, port)
self._version, self._date = version.detect_version(
nmd.ros_node, 'fkie_node_manager_daemon')

def GetVersion(self, request, context):
reply = vmsg.Version()
reply.version = self._version
reply.date = self._date
return reply
@wamp.register('ros.daemon.get_version')
def get_version(self) -> DaemonVersion:
Log.info(f"{self.__class__.__name__}: get daemon version ")
reply = DaemonVersion(f"{self._version}", f"{self._date}")
return json.dumps(reply, cls=SelfEncoder)
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def __init__(self, test_env=False):
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, test_env=self._test_env)
self.screen_servicer = ScreenServicer(
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, test_env=self._test_env)
self.version_servicer = VersionServicer(
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, test_env=self._test_env)

rospy.Service('~start_launch', LoadLaunch,
self._rosservice_start_launch)
Expand All @@ -102,6 +104,7 @@ def __init__(self, test_env=False):
rospy.Service('~list_nodes', ListNodes, self._rosservice_list_nodes)

def __del__(self):
self.version_servicer = None
self.launch_servicer = None
self.monitor_servicer = None
self.settings_servicer = None
Expand Down Expand Up @@ -151,6 +154,8 @@ def restart(self):
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, test_env=self._test_env)
self.screen_servicer = ScreenServicer(
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, test_env=self._test_env)
self.version_servicer = VersionServicer(
self.crossbar_loop, self.crossbar_realm, self.crossbar_port, test_env=self._test_env)
self.start(self._launch_url)

def start(self, url='[::]:12311'):
Expand Down Expand Up @@ -184,7 +189,7 @@ def start(self, url='[::]:12311'):
stgrpc.add_SettingsServiceServicer_to_server(
self.settings_servicer, self.server)
vgrpc.add_VersionServiceServicer_to_server(
VersionServicer(), self.server)
self.version_servicer, self.server)
self.server.start()
Log.info("Server at '%s' started!" % url)
#Log.info(f"Connect to crossbar server @ ws://localhost:{self.crossbar_port}/ws, realm: {self.crossbar_realm}")
Expand All @@ -207,6 +212,7 @@ def _crossbar_notify_if_regsitered(self):
registration_finished &= self.screen_servicer.crossbar_registered
registration_finished &= self.file_servicer.crossbar_registered
registration_finished &= self.parameter_servicer.crossbar_registered
registration_finished &= self.version_servicer.crossbar_registered
time.sleep(0.5)
self._crossbar_send_status(True)

Expand All @@ -219,6 +225,7 @@ def shutdown(self):
self._crossbar_send_status(False)
shutdown_task = self.crossbar_loop.create_task(
self.crossbar_loop.shutdown_asyncgens())
self.version_servicer.stop()
self.launch_servicer.stop()
self.monitor_servicer.stop()
self.parameter_servicer.shutdown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


import asyncio
from autobahn import wamp
import json
from fkie_multimaster_pylib.crossbar.base_session import CrossbarBaseSession
from fkie_multimaster_pylib.crossbar.base_session import SelfEncoder
from fkie_multimaster_pylib.crossbar.runtime_interface import DaemonVersion
import fkie_multimaster_msgs.grpc.version_pb2_grpc as vgrpc
import fkie_multimaster_msgs.grpc.version_pb2 as vmsg
from . import version
from fkie_multimaster_pylib.logging.logging import Log


class VersionServicer(vgrpc.VersionServiceServicer):
class VersionServicer(vgrpc.VersionServiceServicer, CrossbarBaseSession):

def __init__(self):
def __init__(self, loop: asyncio.AbstractEventLoop, realm: str = 'ros', port: int = 11911, test_env=False):
Log.info("Create version servicer")
vgrpc.VersionServiceServicer.__init__(self)
CrossbarBaseSession.__init__(self, loop, realm, port, test_env=test_env)
self._version, self._date = version.detect_version(
'fkie_node_manager_daemon')

Expand All @@ -50,3 +56,9 @@ def GetVersion(self, request, context):
reply.version = self._version
reply.date = self._date
return reply

@wamp.register('ros.daemon.get_version')
def get_version(self) -> DaemonVersion:
Log.info(f"{self.__class__.__name__}: get daemon version ")
reply = DaemonVersion(f"{self._version}", f"{self._date}")
return json.dumps(reply, cls=SelfEncoder)

0 comments on commit cdb031a

Please sign in to comment.