cablelabs / lpwanserver

LPWAN Provisioning & Management Server
https://lpwanserver.com
Apache License 2.0
39 stars 11 forks source link

Implement NetworkDeployments, Rewrite NetworkProtocol handler API #350

Closed rhythnic closed 4 years ago

rhythnic commented 4 years ago

What does this PR do?

Network Deployments

I removed ProtocolData, which was essentially a key/value store for remote network IDs, and I added a NetworkDeployment model, which tracks the meta and sync state for records deployed to networks. One NetworkDeployment record can be used for any type of record that is deployed. The NetworkDeployment currently tracks the remoteID, sync status, sync errors, and whether or not the the network is the origin of the record. Along with the updates, LPWAN Server will no longer delete records on the network from which they originated. All the hooks are in place to create/update/delete NetworkDeployments as needed when other records change. This is a first pass of NetworkDeployments, so while the model would support a scheduler that would attempt to re-deploy failed deployments, it doesn't work that way yet. An operation such as updating an Application will succeed even if the deployment fails. One of the goals of implementing NetworkDeployments was to make LPWAN Server operations less dependent on deployments. The error is available in the NetworkDeployment record. The front-end should be enhanced to display NetworkDeployment info and notify the user on failures.

NetworkProtocol Handler API

I moved a lot of business logic common to all NetworkProtocol handlers into the NetworkProtcol model. I reduced the amount of methods in a handler and made the methods smaller in scope (#347 ). Handler methods no longer have access to the models. They receive all the data that they might need, and return all results to the NetworkProtocol model, which then calls other model methods. This makes for a grossly simpler NetworkProtocol handler, and will make it easier to add NetworkProtocols in the future. The methods are generally CRUD methods for Applications, DeviceProfiles, and Devices.

NetworkProtocol handlers now extend the EventEmitter class, so a handler is now also an event bus between the handler and the NetworkProtocol model. This enables the handler to use any strategy for receiving uplinks, and then notify the app. This was previously supported by the handler having access to the models, and calling model methods. So that all uplink flows are the same, I updated the HTTP handler for uplinks to pass the uplink directly to the NetworkProtocol handler.

Do you have any concerns with this PR?

This PR gives the v2 release a good foundation. There's still a lot of work to be done, but NetworkDeployments are in place, and all tests are passing. The front-end will need a lot of updates.

How can the reviewer verify this PR?

Read. Run tests.

Any background context you want to provide?

Screenshots or logs (if appropriate)

Questions: