summaryrefslogtreecommitdiffstats
path: root/dgbuilder/red/sla.js
diff options
context:
space:
mode:
authorTimoney, Daniel (dt5972) <dtimoney@att.com>2017-02-15 10:37:53 -0500
committerTimoney, Daniel (dt5972) <dtimoney@att.com>2017-02-15 10:40:37 -0500
commit324ee36fe31763e507b422ab0a88e4230045e205 (patch)
treed0b04520f6657601c918ce63fd27575977624187 /dgbuilder/red/sla.js
parentf0c97e8db427481e28c0a16b789bc73801b35e47 (diff)
Initial commit for OpenECOMP SDN-C OA&M
Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680 Signed-off-by: Timoney, Daniel (dt5972) <dtimoney@att.com> Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba
Diffstat (limited to 'dgbuilder/red/sla.js')
-rw-r--r--dgbuilder/red/sla.js249
1 files changed, 249 insertions, 0 deletions
diff --git a/dgbuilder/red/sla.js b/dgbuilder/red/sla.js
new file mode 100644
index 00000000..1729ecbb
--- /dev/null
+++ b/dgbuilder/red/sla.js
@@ -0,0 +1,249 @@
+exports.listSLA = function(settings,req,res) {
+try{
+ var mysql = require('mysql');
+
+ //console.dir(settings);
+
+ var connection = mysql.createConnection(
+ {
+ host : settings.dbHost,
+ port : settings.dbPort,
+ user : settings.dbUser,
+ password : settings.dbPassword,
+ database : settings.dbName
+ });
+
+ var rows=[];
+
+ var sqlQuery = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
+ //console.log("sqlQuery:" + sqlQuery);
+ connection.query(sqlQuery, function(err, rows) {
+ if(!err) {
+ if ( rows.length > 0 )
+ {
+ res.send({ 'rows': rows,'dbHost':settings.dbHost } );
+ }else{
+ res.send({'rows': [],'dbHost':settings.dbHost});
+ }
+ } else {
+ console.log("error:" + err);
+ res.send({error: "Connection to DB failed.",'dbHost':settings.dbHost});
+ }
+ //console.dir(rows);
+ connection.end();
+ }); //end query
+}catch(error){
+ console.log(error);
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+}
+}
+
+exports.listCurrentDGs = function(settings,req,res) {
+ var _module = req.query.module;
+ var rpc = req.query.rpc;
+ console.log("_module:" + _module);
+ console.log("rpc:" + rpc);
+try{
+ var mysql = require('mysql');
+
+ //console.dir(settings);
+
+ var connection = mysql.createConnection(
+ {
+ host : settings.dbHost,
+ port : settings.dbPort,
+ user : settings.dbUser,
+ password : settings.dbPassword,
+ database : settings.dbName
+ });
+
+ var rows=[];
+
+ var sqlQuery = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC where module ='" + _module + "' and rpc ='" + rpc + "'";
+ console.log("sqlQuery:" + sqlQuery);
+ connection.query(sqlQuery, function(err, rows) {
+ if(!err) {
+ if ( rows.length > 0 )
+ {
+ res.send({ 'rows': rows,'dbHost':settings.dbHost } );
+ }else{
+ res.send({'rows': [],'dbHost':settings.dbHost});
+ }
+ } else {
+ console.log("error:" + err);
+ res.send({error: "Connection to DB failed.",'dbHost':settings.dbHost});
+ }
+ //console.dir(rows);
+ connection.end();
+ }); //end query
+}catch(error){
+ console.log(error);
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+}
+}
+
+exports.activateDG = function(settings,req,res){
+ var _module = req.query.module;
+ var rpc = req.query.rpc;
+ var version = req.query.version;
+ var mode = req.query.mode;
+ var displayOnlyCurrent = req.query.displayOnlyCurrent;
+
+try{
+ var mysql = require('mysql');
+
+ var connection = mysql.createConnection(
+ {
+ host : settings.dbHost,
+ port : settings.dbPort,
+ user : settings.dbUser,
+ password : settings.dbPassword,
+ database : settings.dbName
+ });
+
+ var rows=[];
+
+ var updateStmt = "UPDATE SVC_LOGIC SET active=\'Y\' WHERE module=\'"
+ + _module + "' AND rpc=\'"
+ + rpc + "' AND version=\'"
+ + version + "' AND mode=\'"
+ + mode + "'";
+
+ connection.query(updateStmt, function(err, result) {
+ var nextUpdateStmt = "UPDATE SVC_LOGIC SET active=\'N\' WHERE module=\'"
+ + _module + "' AND rpc=\'"
+ + rpc + "' AND version !=\'"
+ + version + "'";
+ connection.query(nextUpdateStmt, function(err, result) {
+ var query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
+ if(displayOnlyCurrent == 'true'){
+ query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC WHERE module=\'"
+ + _module + "' and rpc=\'" + rpc + "'";
+ }
+ connection.query(query, function(err, rows) {
+ if(!err) {
+ if ( rows.length > 0 )
+ {
+ res.send({ 'rows': rows,'dbHost':settings.dbHost } );
+ }else{
+ res.send({'rows': [],'dbHost':settings.dbHost});
+ }
+ } else {
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+ }
+ connection.end();
+ }); //end query
+ }); //end query
+ }); //end query
+}catch(error){
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+}
+}
+
+
+exports.deActivateDG = function(settings,req,res){
+
+ var _module = req.query.module;
+ var rpc = req.query.rpc;
+ var version = req.query.version;
+ var mode = req.query.mode;
+ var displayOnlyCurrent = req.query.displayOnlyCurrent;
+
+try{
+ var mysql = require('mysql');
+
+ var connection = mysql.createConnection(
+ {
+ host : settings.dbHost,
+ port : settings.dbPort,
+ user : settings.dbUser,
+ password : settings.dbPassword,
+ database : settings.dbName
+ });
+
+ var rows=[];
+
+ var updateStmt = "UPDATE SVC_LOGIC SET active=\'N\' WHERE module=\'"
+ + _module + "' AND rpc=\'"
+ + rpc + "' AND version=\'"
+ + version + "' AND mode=\'"
+ + mode + "'";
+
+ connection.query(updateStmt, function(err, result) {
+ var query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
+ if(displayOnlyCurrent == 'true'){
+ query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC WHERE module=\'"
+ + _module + "' and rpc=\'" + rpc + "'";
+ }
+ connection.query(query, function(err, rows) {
+ if(!err) {
+ if ( rows.length > 0 )
+ {
+ res.send({ 'rows': rows,'dbHost':settings.dbHost } );
+ }else{
+ res.send({'rows': [],'dbHost':settings.dbHost});
+ }
+ } else {
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+ }
+ connection.end();
+ }); //end query
+ }); //end query
+}catch(error){
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+}
+}
+
+exports.deleteDG = function(settings,req,res){
+
+ var _module = req.query.module;
+ var rpc = req.query.rpc;
+ var version = req.query.version;
+ var mode = req.query.mode;
+ var displayOnlyCurrent = req.query.displayOnlyCurrent;
+
+try{
+ var mysql = require('mysql');
+
+ var connection = mysql.createConnection(
+ {
+ host : settings.dbHost,
+ port : settings.dbPort,
+ user : settings.dbUser,
+ password : settings.dbPassword,
+ database : settings.dbName
+ });
+
+ var rows=[];
+
+ var deleteStmt = "DELETE FROM SVC_LOGIC WHERE module=\'"
+ + _module + "' AND rpc=\'"
+ + rpc + "' AND version=\'"
+ + version + "' AND mode=\'"
+ + mode + "'";
+ console.log(deleteStmt);
+
+ connection.query(deleteStmt, function(err, result) {
+ var query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
+ if(displayOnlyCurrent == 'true'){
+ query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC WHERE module=\'"
+ + _module + "' and rpc=\'" + rpc + "'";
+ }
+ connection.query(query, function(err, rows) {
+ if(!err) {
+ if ( rows.length > 0 )
+ {
+ res.send({ 'rows': rows,'dbHost':settings.dbHost } );
+ }else{
+ res.send({'rows': [],'dbHost':settings.dbHost});
+ }
+ } else {
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+ }
+ connection.end();
+ }); //end query
+ }); //end query
+}catch(error){
+ res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
+}
+}