diff --git a/controllers/EvioControl.controller.js b/controllers/EvioControl.controller.js new file mode 100644 index 0000000..86a24e3 --- /dev/null +++ b/controllers/EvioControl.controller.js @@ -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." + }); + }); +}; + diff --git a/db/DatabaseInterface.js b/db/DatabaseInterface.js index b52eb7a..edecfe2 100644 --- a/db/DatabaseInterface.js +++ b/db/DatabaseInterface.js @@ -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 } diff --git a/db/Model.js b/db/Model.js index 22c2149..0d83f2f 100644 --- a/db/Model.js +++ b/db/Model.js @@ -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 }; diff --git a/db/MongoDBImpl.js b/db/MongoDBImpl.js index 62e749c..c14f795 100644 --- a/db/MongoDBImpl.js +++ b/db/MongoDBImpl.js @@ -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 }; diff --git a/server/Server.js b/server/Server.js index df10bde..3d674ad 100644 --- a/server/Server.js +++ b/server/Server.js @@ -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