Use released versions of maven artifacts
[ccsdk/distribution.git] / dgbuilder / red / sla.js
1 exports.listSLA =  function(settings,req,res) {
2 try{
3         var mysql = require('mysql');
4
5         //console.dir(settings);
6  
7         var connection = mysql.createConnection(
8         {
9         host     : settings.dbHost,
10         port     : settings.dbPort,
11         user     : settings.dbUser,
12         password : settings.dbPassword,
13         database : settings.dbName
14        });
15
16         var rows=[];
17
18         var sqlQuery = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
19         //console.log("sqlQuery:" + sqlQuery);
20          connection.query(sqlQuery, function(err, rows) {
21             if(!err) {
22                 if ( rows.length > 0 )
23                 {
24                         res.send({ 'rows': rows,'dbHost':settings.dbHost } );
25                 }else{
26                         res.send({'rows': [],'dbHost':settings.dbHost});
27                 }
28             } else {
29                         console.log("error:" + err);
30                     res.send({error: "Connection to DB failed.",'dbHost':settings.dbHost});
31             }
32                 //console.dir(rows);
33                 connection.end();
34         }); //end query
35 }catch(error){
36         console.log(error);
37         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
38 }
39 }
40
41 exports.listCurrentDGs =  function(settings,req,res) {
42         var _module = req.query.module;
43         var rpc = req.query.rpc;
44         console.log("_module:" + _module);
45         console.log("rpc:" + rpc);
46 try{
47         var mysql = require('mysql');
48
49         //console.dir(settings);
50  
51         var connection = mysql.createConnection(
52         {
53         host     : settings.dbHost,
54         port     : settings.dbPort,
55         user     : settings.dbUser,
56         password : settings.dbPassword,
57         database : settings.dbName
58        });
59
60         var rows=[];
61
62         var sqlQuery = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC where module ='" + _module + "' and rpc ='" + rpc + "'";
63         console.log("sqlQuery:" + sqlQuery);
64          connection.query(sqlQuery, function(err, rows) {
65             if(!err) {
66                 if ( rows.length > 0 )
67                 {
68                         res.send({ 'rows': rows,'dbHost':settings.dbHost } );
69                 }else{
70                         res.send({'rows': [],'dbHost':settings.dbHost});
71                 }
72             } else {
73                         console.log("error:" + err);
74                     res.send({error: "Connection to DB failed.",'dbHost':settings.dbHost});
75             }
76                 //console.dir(rows);
77                 connection.end();
78         }); //end query
79 }catch(error){
80         console.log(error);
81         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
82 }
83 }
84
85 exports.activateDG = function(settings,req,res){
86         var _module = req.query.module;
87         var rpc = req.query.rpc;
88         var version = req.query.version;
89         var mode = req.query.mode;
90         var displayOnlyCurrent = req.query.displayOnlyCurrent;
91
92 try{
93         var mysql = require('mysql');
94  
95         var connection = mysql.createConnection(
96         {
97         host     : settings.dbHost,
98         port     : settings.dbPort,
99         user     : settings.dbUser,
100         password : settings.dbPassword,
101         database : settings.dbName
102        });
103
104         var rows=[];
105
106         var updateStmt = "UPDATE SVC_LOGIC SET active=\'Y\' WHERE module=\'"
107                         + _module + "' AND rpc=\'"
108                         + rpc + "' AND version=\'"
109                         +  version + "' AND mode=\'"
110                         +  mode + "'";
111
112          connection.query(updateStmt, function(err, result) {
113                 var nextUpdateStmt = "UPDATE SVC_LOGIC SET active=\'N\' WHERE module=\'"
114                         + _module + "' AND rpc=\'"
115                         + rpc + "' AND version !=\'"
116                         +  version + "'";
117                 connection.query(nextUpdateStmt, function(err, result) {
118                         var query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
119                         if(displayOnlyCurrent == 'true'){
120                                 query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC WHERE module=\'"
121                                         +  _module + "' and rpc=\'" + rpc + "'";
122                         }
123                         connection.query(query, function(err, rows) {
124                                 if(!err) {
125                                         if ( rows.length > 0 )
126                                         {
127                                                 res.send({ 'rows': rows,'dbHost':settings.dbHost } );
128                                         }else{
129                                                 res.send({'rows': [],'dbHost':settings.dbHost});
130                                         }
131                                 } else {
132                                         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
133                                 }
134                                 connection.end();
135                         }); //end query
136                 }); //end query
137         }); //end query
138 }catch(error){
139         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
140 }
141 }
142
143
144 exports.deActivateDG = function(settings,req,res){
145
146         var _module = req.query.module;
147         var rpc = req.query.rpc;
148         var version = req.query.version;
149         var mode = req.query.mode;
150         var displayOnlyCurrent = req.query.displayOnlyCurrent;
151
152 try{
153         var mysql = require('mysql');
154  
155         var connection = mysql.createConnection(
156         {
157         host     : settings.dbHost,
158         port     : settings.dbPort,
159         user     : settings.dbUser,
160         password : settings.dbPassword,
161         database : settings.dbName
162        });
163
164         var rows=[];
165
166         var updateStmt = "UPDATE SVC_LOGIC SET active=\'N\' WHERE module=\'"
167                         + _module + "' AND rpc=\'"
168                         + rpc + "' AND version=\'"
169                         +  version + "' AND mode=\'"
170                         +  mode + "'";
171
172          connection.query(updateStmt, function(err, result) {
173                 var query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
174                 if(displayOnlyCurrent == 'true'){
175                         query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC WHERE module=\'"
176                                 +  _module + "' and rpc=\'" + rpc + "'";
177                 }
178                 connection.query(query, function(err, rows) {
179                 if(!err) {
180                         if ( rows.length > 0 )
181                         {
182                                 res.send({ 'rows': rows,'dbHost':settings.dbHost } );
183                         }else{
184                                 res.send({'rows': [],'dbHost':settings.dbHost});
185                         }
186                 } else {
187                         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
188                 }
189                 connection.end();
190                 }); //end query
191         }); //end query
192 }catch(error){
193         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
194 }
195 }
196
197 exports.deleteDG = function(settings,req,res){
198
199         var _module = req.query.module;
200         var rpc = req.query.rpc;
201         var version = req.query.version;
202         var mode = req.query.mode;
203         var displayOnlyCurrent = req.query.displayOnlyCurrent;
204
205 try{
206         var mysql = require('mysql');
207  
208         var connection = mysql.createConnection(
209         {
210         host     : settings.dbHost,
211         port     : settings.dbPort,
212         user     : settings.dbUser,
213         password : settings.dbPassword,
214         database : settings.dbName
215        });
216
217         var rows=[];
218
219         var deleteStmt = "DELETE FROM SVC_LOGIC  WHERE module=\'"
220                         + _module + "' AND rpc=\'"
221                         + rpc + "' AND version=\'"
222                         +  version + "' AND mode=\'"
223                         +  mode + "'";
224          console.log(deleteStmt);
225
226          connection.query(deleteStmt, function(err, result) {
227                 var query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC";
228                 if(displayOnlyCurrent == 'true'){
229                         query = "SELECT module,rpc,version,mode,active FROM SVC_LOGIC WHERE module=\'"
230                                 +  _module + "' and rpc=\'" + rpc + "'";
231                 }
232                 connection.query(query, function(err, rows) {
233                 if(!err) {
234                         if ( rows.length > 0 )
235                         {
236                                 res.send({ 'rows': rows,'dbHost':settings.dbHost } );
237                         }else{
238                                 res.send({'rows': [],'dbHost':settings.dbHost});
239                         }
240                 } else {
241                         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
242                 }
243                 connection.end();
244                 }); //end query
245         }); //end query
246 }catch(error){
247         res.send({'error': "Connection to DB failed.",'dbHost':settings.dbHost});
248 }
249 }

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use