Skip to content

Commit

Permalink
Improve storage node startup behavior, added tip for populating start…
Browse files Browse the repository at this point in the history
…ing db tables
  • Loading branch information
smartin015 committed Jun 18, 2020
1 parent d48ae02 commit 8b0d36d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion infra/ros/storage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ ARG L2NODES=node.py
FROM l2base-pre
FROM l2base-post

RUN pip3 install psycopg2-binary watchdog
RUN apt-get update && apt-get install --no-install-recommends -y python3-pip && pip3 install psycopg2-binary watchdog && apt-get clean
COPY --from=0 /node/install /node/install
11 changes: 11 additions & 0 deletions infra/ros/storage/files/.demo.wbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Webots Project File version R2020a
perspectives: 000000ff00000000fd00000003000000000000000000000000fc0100000001fb0000001a0044006f00630075006d0065006e0074006100740069006f006e0000000000ffffffff0000006900ffffff000000010000011c000006dbfc0200000001fb0000001400540065007800740045006400690074006f00720100000024000006db0000003f00ffffff0000000300000bb700000061fc0100000001fb0000000e0043006f006e0073006f006c0065010000000000000bb70000006900ffffff00000a99000006db00000001000000020000000100000008fc00000000
simulationViewPerspectives: 000000ff000000010000000200000100000009990100000002010000000100
sceneTreePerspectives: 000000ff000000010000000200000610000000fa0100000002010000000200
maximizedDockId: -1
centralWidgetVisible: 1
selectionDisabled: 0
viewpointLocked: 0
orthographicViewHeight: 1
textFiles: -1
renderingDevicePerspectives: range:rangefinder;1;3.21875;0;0
10 changes: 10 additions & 0 deletions infra/ros/storage/files/.pendant.wbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Webots Project File version R2020a
perspectives: 000000ff00000000fd00000003000000000000000000000000fc0100000001fb0000001a0044006f00630075006d0065006e0074006100740069006f006e0000000000ffffffff0000006900ffffff00000001000000750000021ffc0200000001fb0000001400540065007800740045006400690074006f007201000000150000021f0000003f00ffffff00000003000004d20000007efc0100000001fb0000000e0043006f006e0073006f006c00650100000000000004d20000006900ffffff0000045b0000021f00000001000000020000000100000008fc00000000
simulationViewPerspectives: 000000ff0000000100000002000000fa0000035f0100000002010000000100
sceneTreePerspectives: 000000ff0000000100000002000000c0000000fa0100000002010000000200
maximizedDockId: -1
centralWidgetVisible: 1
selectionDisabled: 0
viewpointLocked: 0
orthographicViewHeight: 1
textFiles: -1
12 changes: 12 additions & 0 deletions infra/ros/storage/files/.rangefinder.wbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Webots Project File version R2020a
perspectives: 000000ff00000000fd00000003000000000000000000000000fc0100000001fb0000001a0044006f00630075006d0065006e0074006100740069006f006e0000000000ffffffff0000006900ffffff00000001000001cd0000027afc0200000001fb0000001400540065007800740045006400690074006f007201000000160000027a0000003f00ffffff000000030000053e0000007efc0100000001fb0000000e0043006f006e0073006f006c006501000000000000053e0000006900ffffff0000036f0000027a00000001000000020000000100000008fc00000000
simulationViewPerspectives: 000000ff000000010000000200000100000003be0100000002010000000100
sceneTreePerspectives: 000000ff00000001000000020000024d000000fa0100000002010000000200
maximizedDockId: -1
centralWidgetVisible: 1
selectionDisabled: 0
viewpointLocked: 0
orthographicViewHeight: 1
textFiles: -1
renderingDevicePerspectives: range:rangefinder;1;1;0;0
renderingDevicePerspectives: testrobot:rangefinder;1;1.375;0;0
5 changes: 5 additions & 0 deletions infra/ros/storage/files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Table initialization:

```
docker exec -it storage_db_1 psql app_db app_user -f /volume/test_db.sql
```
18 changes: 13 additions & 5 deletions infra/ros/storage/node.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from l2_msgs.srv import GetProject, GetFile, GetObject3D
from l2_msgs.msg import Object3D
import time

import rclpy
from rclpy.node import Node
Expand Down Expand Up @@ -108,12 +109,19 @@ def connect_to_db(self):
database = result.path[1:]
hostname = result.hostname

self.con = psycopg2.connect(
database=database,
user=username,
password=password,
host=hostname)
while True:
try:
self.con = psycopg2.connect(
database=database,
user=username,
password=password,
host=hostname)
break
except:
self.get_logger().warn("Failed to connect to db; waiting a bit then retrying...")
time.sleep(5)
self.get_logger().info("Connected (host: %s, db: %s)" % (hostname, database))
self.get_logger().info("TODO: ensure initial tables are set up")

def get_project_callback(self, request, response):
self.get_logger().info(str(request))
Expand Down

0 comments on commit 8b0d36d

Please sign in to comment.