Warning
The Push scripts (and webinterface) require the latest version of the database. Even if the server is not running the web inteface. You will need to follow the database upgrade instructions found here Updating the Database
Note
These scripts require a mysql database, even for testing. Unfortunately sqlites table locking mechinism does not play nicely when reading / writing data from several scripts.
Note
Currently the sync is one time / one way only, (ie push from local to remote database) This means that any changes made in either database will not be reflected. This would be an interesting todo for the future.
The Database Upload (Push) functionality, enables a database on a remote server to be uploaded to a remote (central) server. Without having to resort to command line scripting, mysql dumps etc.
The push function is designed to be run as a daemon process, periodically pushing updates to the central point.
This functionality makes use of the REST interface (See Rest Interface.)
The Push Script currently lives in the Base Cogent-house software. Follow the install instructions at this site to install the push script.
Test the connection to the remote server by visiting the <base>/rest/sensortype/ url in your webbrowser (for example http://127.0.0.1:6543/rest/sensortype/ if you are running the web interface via the paste server) There should be a JSON dictionary of sensortype objects displayed.
Modify the synchronise.conf file (base/push/synchronise.conf) with the details of the remote rest server you visited above.
To run the push script:
python RestPusher.py
The script should output logging information to a logfile.
Note
Write code / Docs for this
Each Iteration of the sync function does the following:
These steps are described in detail below:
This method uses SQLA to synchronise the node tables between the local and remote servers. As nodeIds should be static (ie node 69 will allways be node 69) then this function can make use of a simplistic approach.
Note
Currently, we only create new sensors when adding a node. At some point we may need to update the code to deal with this
Note
We Assume that the following parameters are unique
To reduce the amount of network traffic, we only map Active Deployments / Houses, where an active house is defines as one that:
object.endDate == None
object.endDate >= lastUpdate
These database items are fetched from the local database, and mapped to their equivelent on the remote database. If no such item exists on the remote database then
The following queries are first run on the local database
Get Deployments / Houses to be updated
Given the date of the last update, we fetch all deployments and houses where the finishdate is either None, or After the last update. This should reduce the amount of locations mapped to a minimum.
If for some reason there are no deployments, then we get all active “houses” using the same parameters on the house table.
Get Locations to be Updated
Based on the houseID’s of those houses that need are current. We fetch a set of locations from the local database.
Get Rooms to be Updated
Now we have the location Id’s, it is possible to get a list of rooms that will need updating
Create new objects
| [locations] |
| [local] |