diff options
4 files changed, 323 insertions, 3 deletions
diff --git a/components/datalake-handler/admin/src/package.json b/components/datalake-handler/admin/src/package.json index 675a5f35..de89944b 100644 --- a/components/datalake-handler/admin/src/package.json +++ b/components/datalake-handler/admin/src/package.json @@ -1,5 +1,5 @@ { - "name": "admin", + "name": "DataLake-AdminUI", "version": "0.0.0", "scripts": { "ng": "ng", @@ -8,7 +8,8 @@ "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" + "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", + "mockup": "node ./src/app/mockup/index.js" }, "private": true, "dependencies": { @@ -33,7 +34,10 @@ "popper.js": "^1.15.0", "rxjs": "~6.3.3", "tslib": "^1.9.0", - "zone.js": "~0.8.26" + "zone.js": "~0.8.26", + "body-parser": "^1.18.2", + "json-server": "^0.15.0", + "lowdb": "^1.0.0" }, "devDependencies": { "@angular-devkit/build-angular": "^0.13.9", diff --git a/components/datalake-handler/admin/src/proxy.conf.json b/components/datalake-handler/admin/src/proxy.conf.json new file mode 100644 index 00000000..a485617b --- /dev/null +++ b/components/datalake-handler/admin/src/proxy.conf.json @@ -0,0 +1,8 @@ +{ + "/datalake/v1": { + "target": "http://10.103.12.175:1680", + "secure": false, + "logLevel": "debug", + "changeOrigin": true + } +} diff --git a/components/datalake-handler/admin/src/src/app/mockup/db.json b/components/datalake-handler/admin/src/src/app/mockup/db.json new file mode 100644 index 00000000..b45287bb --- /dev/null +++ b/components/datalake-handler/admin/src/src/app/mockup/db.json @@ -0,0 +1,139 @@ +{ + "dbs": [ + { + "name": "Couchbase", + "enabled": true, + "host": "dl_couchbase1", + "port": 567, + "login": "admin", + "pass": null, + "database": "datalake", + "encrypt": false, + "property1": null, + "property2": null, + "property3": null + }, + { + "name": "Druid", + "enabled": false, + "host": "dl_druid", + "port": null, + "login": null, + "pass": null, + "database": null, + "encrypt": null, + "property1": null, + "property2": null, + "property3": null + }, + { + "name": "Elasticsearch", + "enabled": false, + "host": "dl_es", + "port": null, + "login": null, + "pass": null, + "database": null, + "encrypt": null, + "property1": null, + "property2": null, + "property3": null + }, + { + "name": "HDFS", + "enabled": false, + "host": "dlhdfs", + "port": null, + "login": "dl", + "pass": null, + "database": null, + "encrypt": null, + "property1": null, + "property2": null, + "property3": null + }, + { + "name": "MongoDB", + "enabled": false, + "host": "dl_mongodb", + "port": 27017, + "login": null, + "pass": null, + "database": "datalake", + "encrypt": null, + "property1": null, + "property2": null, + "property3": null + } + ], + "topics": [ + { + "name": "unauthenticated.VES_MEASUREMENT_OUTPUT", + "login": null, + "password": null, + "sinkdbs": [ + "Druid", + "Couchbase", + "Elasticsearch", + "HDFS", + "MongoDB" + ], + "enabled": true, + "saveRaw": false, + "dataFormat": "JSON", + "ttl": 3650, + "correlateClearedMessage": false, + "messageIdPath": null, + "aggregateArrayPath": "/event/measurementsForVfScalingFields/memoryUsageArray,/event/measurementsForVfScalingFields/diskUsageArray,/event/measurementsForVfScalingFields/cpuUsageArray,/event/measurementsForVfScalingFields/vNicPerformanceArray", + "flattenArrayPath": "/event/measurementsForVfScalingFields/astriMeasurement/astriDPMeasurementArray/astriInterface", + "dataFormat2": "JSON", + "aggregateArrayPath2": [ + "/event/measurementsForVfScalingFields/memoryUsageArray", + "/event/measurementsForVfScalingFields/diskUsageArray", + "/event/measurementsForVfScalingFields/cpuUsageArray", + "/event/measurementsForVfScalingFields/vNicPerformanceArray" + ], + "flattenArrayPath2": [ + "/event/measurementsForVfScalingFields/astriMeasurement/astriDPMeasurementArray/astriInterface" + ] + }, + { + "name": "AAI-EVENT", + "login": null, + "password": null, + "sinkdbs": [ + "Druid", + "Couchbase", + "Elasticsearch", + "HDFS", + "MongoDB" + ], + "enabled": true, + "saveRaw": false, + "dataFormat": "JSON", + "ttl": 3650, + "correlateClearedMessage": false, + "messageIdPath": null, + "aggregateArrayPath": "", + "flattenArrayPath": "", + "dataFormat2": "JSON", + "aggregateArrayPath2": [], + "flattenArrayPath2": [] + }, + { + "name": "AAI-EVENT2", + "login": null, + "password": null, + "sinkdbs": [ + "Druid", + "Couchbase" + ], + "enabled": true, + "saveRaw": true, + "dataFormat": "JSON", + "ttl": 256, + "correlateClearedMessage": true, + "messageIdPath": "/event/commonEventHeader/eventName,/event/commonEventHeader/reportingEntityName" + } + ] +}
\ No newline at end of file diff --git a/components/datalake-handler/admin/src/src/app/mockup/index.js b/components/datalake-handler/admin/src/src/app/mockup/index.js new file mode 100644 index 00000000..f92c9a96 --- /dev/null +++ b/components/datalake-handler/admin/src/src/app/mockup/index.js @@ -0,0 +1,169 @@ +// Database +const low = require("lowdb"); +const FileSync = require("lowdb/adapters/FileSync"); +const adapter = new FileSync("src/app/mockup/db.json"); +const db = low(adapter); + +// Json Server +const jsonServer = require("json-server"); +const router = jsonServer.router(db); +const server = jsonServer.create(); +const middlewares = jsonServer.defaults(); + +// DataLake parameter +const endpoint = "/datalake/v1"; +const port = 1680; +var feederStatus = true; +var feederVersion = "v1.0.0"; + +server.use(middlewares); +server.use(jsonServer.bodyParser); + +// Methods +const postData = (func, req, res) => { + db.get(func) + .push(req.body) + .write(); + + let d = db.get(func).find({ + name: req.body.name + }); + + let response = { + statusCode: 200, + returnBody: d + }; + + res.status(200).jsonp(response); +}; + +const putData = (func, req, res) => { + db.get(func) + .find({ + name: req.body.name + }) + .assign(req.body) + .write(); + + let d = db.get(func).find({ + name: req.body.name + }); + + let response = { + statusCode: 200, + returnBody: d + }; + + res.status(200).jsonp(response); +}; + +const deleteData = (func, req, res) => { + db.get(func) + .remove({ + name: req.params.name + }) + .write(); + + res.status(204).jsonp({}); +}; + +// REST API: /dbs +server.post(endpoint + "/dbs", async (req, res) => { + postData("dbs", req, res); +}); + +server.put(endpoint + "/dbs/:name", async (req, res) => { + putData("dbs", req, res); +}); + +server.delete(endpoint + "/dbs/:name", async (req, res) => { + deleteData("dbs", req, res); +}); + +server.post(endpoint + "/dbs/verify", async (req, res) => { + res.status(200).jsonp({ + verify: true + }); +}); +// End REST API: /dbs + +// REST API: /topics +server.post(endpoint + "/topics", async (req, res) => { + postData("topics", req, res); +}); + +server.put(endpoint + "/topics/:name", async (req, res) => { + putData("topics", req, res); +}); + +server.delete(endpoint + "/topics/:name", async (req, res) => { + deleteData("topics", req, res); +}); +// End REST API: /topics + +// REST API: /feeder +server.get(endpoint + "/feeder/status", (req, res) => { + let response = { + running: feederStatus, + version: feederVersion + }; + + res.status(200).jsonp(response); +}); + +server.post(endpoint + "/feeder/start", (req, res) => { + feederStatus = true; + let response = { + running: feederStatus + }; + + res.status(200).jsonp(response); +}); + +server.post(endpoint + "/feeder/stop", (req, res) => { + feederStatus = false; + let response = { + running: feederStatus + }; + + res.status(200).jsonp(response); +}); +// End REST API: /feeder + +// Custom render data +router.render = (req, res) => { + if (req.method === "GET") { + // Return a array for dbs, topics + switch (req.originalUrl) { + case endpoint + "/dbs": + case endpoint + "/topics": + case endpoint + "/topics/dmaap": + let obj = res.locals.data; + let data = []; + for (let i = 0; i < obj.length; i++) { + data.push(obj[i].name); + } + res.jsonp(data); + break; + default: + res.jsonp(res.locals.data); + } + } +}; + +// Custom routes +// Add this before server.use(router) +server.use( + jsonServer.rewriter({ + "/datalake/v1/dbs/:name": "/dbs?name=:name", + "/datalake/v1/topics/dmaap": "/topics", + "/datalake/v1/topics/:name": "/topics?name=:name" + }) +); + +server.use(endpoint, router); +server.use(router); + +server.listen(port, () => { + console.log("JSON Server is running, http://localhost:" + port); +}); |