Added evio control

master
ken 2021-09-03 23:37:04 +00:00
parent 513e94c506
commit cf8959f562
5 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,48 @@
/* EdgeVPNio
* Copyright 2021, University of Florida
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
const {evioControlModel} = require('../db/Model');
/**
* Function to retrieve all Intervals from the database
*/
exports.getControl = (req, res, dbInstance) => {
const nodeId = req.query.nodeid;
var tableName = null;
if (process.env.DB === 'mongo') {
tableName = evioControlModel;
} else if (process.env.DB === 'influx') {
console.error("Operation not supported for Influx")
return
}
dbInstance.getEvioControl(tableName, nodeId)
.then(data => {
// console.log("Control data:", data);
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "An error occurred while retrieving the Evio Control."
});
});
};

View File

@ -47,6 +47,10 @@ class DataBaseInterface {
close() {
console.log("close method not implemented by specific db");
}
getEvioControl(tableName, nodeId) {
console.log("getEvioControl method not implemented by specific db");
}
}
module.exports = { DataBaseInterface }

View File

@ -95,9 +95,31 @@ const topologySchema = new mongoose.Schema(
//----------------------------------- End of Topology collection schema ------------------------------------------
// var orderedControlSchema = new mongoose.Schema(
// {
// NodeId: String,
// Control: String,
// },
// { _id: false }
// );
const evioControlSchema = new mongoose.Schema(
{
_id: Number,
createdAt: {
type: Date,
expires: process.env.expireTime,
default: Date.now,
},
EvioControl: {},
},
{ _id: false }
)
//----------------------------------- Export the model so that they can be used ------------------------------------------
var overlayModel = mongoose.model("overlayData", overlaySchema, "Overlays");
var topologyModel = mongoose.model("topologyData", topologySchema, "Topology");
var evioControlModel = mongoose.model("evioControl", evioControlSchema, "EvioControl")
module.exports = { overlayModel, topologyModel };
module.exports = { overlayModel, topologyModel, evioControlModel };

View File

@ -186,5 +186,17 @@ class MongoDBImpl extends DataBaseInterface {
}
return topologyData;
}
/**
* Database call to get the intervals stored.
*
* @param {mogoose.Model} tableName Model Name to use to find the intervals.
* @param {String} nodeId
*/
async getEvioControl(tableName, nodeId) {
return tableName.find(
{ "EvioControl.NodeId": { $eq: nodeId } }
).sort({ _id: -1 }).limit(1);
}
}
module.exports = { MongoDBImpl };

View File

@ -26,6 +26,7 @@ const bodyParser = require('body-parser');
const {MongoDBImpl} = require('../db/MongoDBImpl')
const overlays = require("../controllers/Overlays.controller.js");
const topology = require("../controllers/Topology.controller.js");
const EvioControl = require("../controllers/EvioControl.controller.js");
const dotenv = require('dotenv')
const {InfluxDBImpl} = require('../db/InfluxDBImpl')
const app = express()
@ -78,6 +79,9 @@ app.get('/Overlays', (req, res) => overlays.findOverlays(req, res, dbInstance));
//Syntax: http://localhost:3000/topology?overlayid=overlayId&interval=intervalId
app.get('/Topology', (req, res) => topology.findTopology(req, res, dbInstance));
//Syntax: http://localhost:3000/eviocontrol?nodeid=value
app.get('/EvioControl', (req, resp) => EvioControl.getControl(req, resp, dbInstance))
// routing logic for the PUT request to gather data from all Evio nodes.
app.put('/EVIO/*', (req, res) => {
Data[Date.now()] = req.body