From d1569975bb18f4359fac18aa98f55b69c248a3ad Mon Sep 17 00:00:00 2001 From: "Chinthakayala, Sheshashailavas (sc2914)" Date: Mon, 28 Aug 2017 05:25:46 -0900 Subject: [CCSDK-28] populated the seed code for dgbuilder updated the code to point to the new package name for sli Change-Id: I3b5a1d05dc5193664fd4a667afdcd0b2354010a4 Issue-ID:{CCSDK-28} Signed-off-by: Chinthakayala, Sheshashailavas (sc2914) Signed-off-by: Chinthakayala, Sheshashailavas (sc2914) --- dgbuilder/nodes/dge/dgemain/GenericXML.html | 140 +++ dgbuilder/nodes/dge/dgemain/GenericXML.js | 31 + dgbuilder/nodes/dge/dgemain/comment.html | 97 ++ dgbuilder/nodes/dge/dgemain/comment.js | 23 + dgbuilder/nodes/dge/dgemain/dgstart.html | 1322 +++++++++++++++++++++++++ dgbuilder/nodes/dge/dgemain/dgstart.js | 594 +++++++++++ dgbuilder/nodes/dge/dgemain/method.html | 141 +++ dgbuilder/nodes/dge/dgemain/method.js | 31 + dgbuilder/nodes/dge/dgemain/serviceLogic.html | 125 +++ dgbuilder/nodes/dge/dgemain/serviceLogic.js | 31 + 10 files changed, 2535 insertions(+) create mode 100644 dgbuilder/nodes/dge/dgemain/GenericXML.html create mode 100644 dgbuilder/nodes/dge/dgemain/GenericXML.js create mode 100644 dgbuilder/nodes/dge/dgemain/comment.html create mode 100644 dgbuilder/nodes/dge/dgemain/comment.js create mode 100644 dgbuilder/nodes/dge/dgemain/dgstart.html create mode 100644 dgbuilder/nodes/dge/dgemain/dgstart.js create mode 100644 dgbuilder/nodes/dge/dgemain/method.html create mode 100644 dgbuilder/nodes/dge/dgemain/method.js create mode 100644 dgbuilder/nodes/dge/dgemain/serviceLogic.html create mode 100644 dgbuilder/nodes/dge/dgemain/serviceLogic.js (limited to 'dgbuilder/nodes/dge/dgemain') diff --git a/dgbuilder/nodes/dge/dgemain/GenericXML.html b/dgbuilder/nodes/dge/dgemain/GenericXML.html new file mode 100644 index 00000000..4c9c01a6 --- /dev/null +++ b/dgbuilder/nodes/dge/dgemain/GenericXML.html @@ -0,0 +1,140 @@ + + + + + + + + diff --git a/dgbuilder/nodes/dge/dgemain/GenericXML.js b/dgbuilder/nodes/dge/dgemain/GenericXML.js new file mode 100644 index 00000000..e5fc0624 --- /dev/null +++ b/dgbuilder/nodes/dge/dgemain/GenericXML.js @@ -0,0 +1,31 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(RED) { + "use strict"; + var util = require("util"); + var vm = require("vm"); + + function GenericXML(n) { + RED.nodes.createNode(this,n); + this.name = n.name; + this.xml = n.xml; + this.topic = n.topic; + } + + RED.nodes.registerType("GenericXML",GenericXML); + // RED.library.register("GenericXML"); +} diff --git a/dgbuilder/nodes/dge/dgemain/comment.html b/dgbuilder/nodes/dge/dgemain/comment.html new file mode 100644 index 00000000..c34d14c9 --- /dev/null +++ b/dgbuilder/nodes/dge/dgemain/comment.html @@ -0,0 +1,97 @@ + + + + + + + diff --git a/dgbuilder/nodes/dge/dgemain/comment.js b/dgbuilder/nodes/dge/dgemain/comment.js new file mode 100644 index 00000000..ef5f0800 --- /dev/null +++ b/dgbuilder/nodes/dge/dgemain/comment.js @@ -0,0 +1,23 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(RED) { + "use strict"; + function CommentNode(n) { + RED.nodes.createNode(this,n); + } + RED.nodes.registerType("comment",CommentNode); +} diff --git a/dgbuilder/nodes/dge/dgemain/dgstart.html b/dgbuilder/nodes/dge/dgemain/dgstart.html new file mode 100644 index 00000000..9caa841a --- /dev/null +++ b/dgbuilder/nodes/dge/dgemain/dgstart.html @@ -0,0 +1,1322 @@ + +
+ + + + + + + +
+ diff --git a/dgbuilder/nodes/dge/dgemain/dgstart.js b/dgbuilder/nodes/dge/dgemain/dgstart.js new file mode 100644 index 00000000..f2b4815e --- /dev/null +++ b/dgbuilder/nodes/dge/dgemain/dgstart.js @@ -0,0 +1,594 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + + +module.exports = function(RED) { + "use strict"; + var util = require("util"); + var vm = require("vm"); + //var dgxml=require("/home/users/schinthakayala/nodered/sheshi/dgxml/dgxml2"); + var _=require('lodash'); + var fs=require('fs'); + var path = require('path'); + var appDir = path.dirname(require.main.filename); + var userDir = appDir + "/" + RED.settings.userDir; + var dbHost = RED.settings.dbHost; + var request = require('request'); + var sharedDir = appDir + "/" + RED.settings.sharedDir; + var xmlDir = appDir + "/" + RED.settings.xmlPath; + + //console.log("appDir:" + appDir); + //var dgeraw=fs.readFileSync(appDir + "/dge.json").toString(); + //var dgejson=JSON.parse(dgeraw); + //var uploadUrl=dgejson.slaHost + dgejson.uploadUrl; + //var slaUrl=dgejson.slaHost + dgejson.slaUrl; + //var uploadUrl=RED.settings.slaHost + RED.settings.uploadUrl; + //var slaUrl=RED.settings.slaHost + RED.settings.slaUrl; + var uploadUrl=""; + var slaUrl=""; + //console.log("Upload url: " + uploadUrl); + + function dgstart(n) { + RED.nodes.createNode(this,n); + this.name = n.name; + this.topic = n.topic; + } + + function writeHtmlToFile(fileName,str){ + var localfile = appDir + "/" + RED.settings.htmlPath + fileName; + try{ + fs.writeFileSync(localfile,str); + }catch(e){ + console.log("Error:" + e); + } + } + + function writeXmlToFile(fileName,str){ + var localfile = appDir + "/" + RED.settings.xmlPath + fileName; + try{ + fs.writeFileSync(localfile,str); + }catch(e){ + console.log("Error:" + e); + } + } + + function sendXml(fileName,res) { + var needle, localfile, data; + needle = require('needle') + localfile = appDir + "/" + RED.settings.xmlPath + fileName; + console.log("localfile:" + localfile); + data={ + uploadedfile: { file: localfile, content_type: 'text/xml' } + } + needle.post(uploadUrl, data, { multipart: true }, function(err, resp, body) { + //console.log(body) + if(resp != undefined && resp != null){ + console.log("resp Code for sendXml:" + resp.statusCode); + } + fs.unlink(localfile, function (error) { + if (error) { + console.log("Error deleting file "+localfile); + }else{ + //console.log("deleted file:" + localfile); + } + }); + + if(err){ + console.log("Error posting to slaUrl:" + slaUrl); + console.log("Error:" +err); + res.json({"error":err}); + }else{ + //console.dir(resp); + //console.log("slaUrl:" + slaUrl); + res.json({"url":slaUrl}); + } + + }); + } + + function oldsendXml(fileName) { + console.log("In sendXML for file: " + fileName); + var fileStream, formdata, localfile; + localfile = appDir + "/" + RED.settings.xmlPath + fileName; + + formdata = { + MAX_FILE_SIZE: "100000", + uploadedfile: { + options: { + contentType: 'audio/mpeg' + } + } + + }; + + console.log("Attempting to upload file: " + localfile); + console.log("Sending to: " + uploadUrl); + formdata.uploadedfile.value = fs.createReadStream(localfile); + fileStream = formdata.uploadedfile.value; + +//console.log("Formdata:"); +//console.dir(formdata); + + request.post({ + url: uploadUrl, + proxy: false, + formData: formdata + }, function(err, resp, body) { + fileStream.close(); + console.log("err: " + err); + return console.log("body: " + body); + }); + + }; + + RED.nodes.registerType("dgstart",dgstart); +/* + RED.httpAdmin.post("/uploadxml", function(req,res) { + console.dir(req); + console.log("USER:" + req.user); + console.log("Got request to upload xml to SDN-C."); + console.log("Requested filename to upload: " + req.params.fileName); + console.log("Requested xml to upload: " + req.params.xmlStr); + writeToFile( req.params.fileName,req.params.xmlStr); + + sendXml(req.params.fileName,res); + // res.send("Attempt complete."); + // res.redirect(slaUrl); + }); +*/ + + RED.httpAdmin.post("/OldUploadxml", function(req,res) { + //console.dir(req); + //console.log("USER:" + req.user); + var qs = require('querystring'); + var body = ''; + req.on('data', function (data) { + body += data; + // Too much POST data, kill the connection! + /*if (body.length > 1e6) + request.connection.destroy(); + */ + }); + req.on('end', function () { + //console.log("BODY:" + body); + var d = new Date().getTime(); + var user = req.user; + var fileName= user + "_" + d +".xml"; + var post = qs.parse(body); + //console.log(JSON.stringify(post)); + // use post['blah'], etc. + var localfile = appDir + "/" + RED.settings.xmlPath + fileName; + //console.log("localfile:" + localfile); + var xmlStr = post['flowXml']; + writeXmlToFile(fileName,xmlStr); + sendXml(fileName,res); + + }); + + }); + + RED.httpAdmin.post("/uploadxml", function(req,res) { + //console.dir(req); + //console.log("USER:" + req.user); + var qs = require('querystring'); + var body = ''; + req.on('data', function (data) { + body += data; + // Too much POST data, kill the connection! + /*if (body.length > 1e6) + request.connection.destroy(); + */ + }); + req.on('end', function () { + //console.log("BODY:" + body); + var d = new Date().getTime(); + var user = req.user; + var fileName= user + "_" + d +".xml"; + var post = qs.parse(body); + //console.log(JSON.stringify(post)); + // use post['blah'], etc. + var localfile = appDir + "/" + RED.settings.xmlPath + fileName; + //console.log("localfile:" + localfile); + var xmlStr = post['flowXml']; + var moduleName = post['module']; + var rpc = post['rpc']; + writeXmlToFile(fileName,xmlStr); + uploadDG(localfile,moduleName,rpc,res); + }); + + }); + + +function uploadDG(filePath,moduleName,rpc,res){ + console.log("called uploadDG..."); + var exec = require('child_process').exec; + var commandToExec = appDir + "/svclogic/svclogic.sh load " + filePath + " " + userDir + "/conf/svclogic.properties"; + console.log("commandToExec:" + commandToExec); + var child = exec(commandToExec ,function (error,stdout,stderr){ + //console.log(error); + console.log("stdout:" + stdout); + console.log("stderr:" + stderr); + if(error){ + console.log("Error occured:" + error); + if(stderr){ + //console.log("stderr:" + stderr); + res.send(500,{'error':error,'stderr':stderr}); + }else{ + res.send(500,{'error':error}); + } + //console.log("stdout :" + stdout); + }else{ + if(stdout ){ + //console.log("output:" + stdout); + if(stdout.indexOf('Compiler error') != -1){ + //console.log("compileError occured."); + + var resp = { + 'stdout':stdout, + 'stderr':"COMPILE_ERROR", + 'url':dbHost, + 'module':moduleName, + 'rpc':rpc + } + res.send(500,resp); + }else{ + res.send(200,{'stdout':stdout,'stderr':stderr,"url":dbHost,"module" : moduleName,"rpc" : rpc}); + } + } + if(stderr && !stdout){ + //console.log("stderr:" + stderr); + if(stderr.indexOf("Saving SvcLogicGraph to database") != -1){ + res.send(200,{'error':error,'stdout' :'','stderr':stderr,"url":dbHost,"module" : moduleName,"rpc" : rpc}); + }else{ + res.send(500,{'error':error,'stdout' :'','stderr':stderr}); + } + } + } + }); +} + + RED.httpAdmin.get("/displayXml", function(req,res) { + var _module = req.query._module; + var rpc = req.query.rpc; + var version = req.query.version; + var mode = req.query.mode; + var d = new Date().getTime(); + displayXml(_module,rpc,version,mode,res); + }); + +function displayXml(_module,rpc,version,mode,res){ + var exec = require('child_process').exec; + var msg = { + '_module' : _module, + 'rpc' : rpc, + 'version' : version, + 'mode' : mode + } + var commandToExec = appDir + "/svclogic/svclogic.sh get-source " + _module + " " + + rpc + " " + mode + " " + version + " " + userDir + "/conf/svclogic.properties"; + console.log("commandToExec:" + commandToExec); + var child = exec(commandToExec ,{'maxBuffer':16*1024*1024},function (error,stdout,stderr){ + if(error){ + console.log("Error occured:" + error); + if(stderr){ + //console.log("stderr:" + stderr); + res.send(500,{'error':error,'stderr':stderr,'msg':msg}); + }else{ + res.send(500,{'error':error,'msg':msg}); + } + }else{ + if(stderr){ + console.log("stderr:" + stderr); + } + if(stdout){ + res.send({'xmldata' : "" + stdout + ""}); + } + } + }); +} + + + RED.httpAdmin.post("/downloadDGXml", function(req,res) { + //console.dir(req); + var qs = require('querystring'); + var body = ''; + req.on('data', function (data) { + body += data; + }); + + req.on('end', function () { + var post = qs.parse(body); + var _module = post._module; + var rpc = post.rpc; + var version = post.version; + var mode = post.mode; + var d = new Date().getTime(); + downloadDGXml(_module,rpc,version,mode,res); + }); + }); + +function downloadDGXml(_module,rpc,version,mode,res){ + var exec = require('child_process').exec; + var msg = { + '_module' : _module, + 'rpc' : rpc, + 'version' : version, + 'mode' : mode + } + var commandToExec = appDir + "/svclogic/svclogic.sh get-source " + _module + " " + + rpc + " " + mode + " " + version + " " + userDir + "/conf/svclogic.properties"; + console.log("commandToExec:" + commandToExec); + var child = exec(commandToExec ,function (error,stdout,stderr){ + if(error){ + console.log("Error occured:" + error); + if(stderr){ + //console.log("stderr:" + stderr); + res.send(500,{'error':error,'stderr':stderr,'msg':msg}); + }else{ + res.send(500,{'error':error,'msg':msg}); + } + }else{ + if(stderr){ + console.log("stderr:" + stderr); + } + if(stdout){ + //console.log("output:" + stdout); + //var newOutput = "
" + stdout.replace(/\n/g,'
') + "
"; + //res.json({'stdout': stdout ,'stderr':stderr,"msg":msg}); + //res.set('Content-Type', 'text/xml'); + //res.set('Content-Type', 'application/octet-stream'); + //res.end("" + stdout + "" ); + //var newOutput ="" + stdout + ""; + //res.send(new Buffer( "" + newOutput + "" ) ); + //res.send(newOutput); + + /* + var xslStr = '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + */ + + var formatted_date = getCurrentDate(); + var fileName= "db_" + _module + "_" +rpc+ "_" + version + "_" + formatted_date + ".html"; + var file = xmlDir + "/" + fileName; + var xmlStr = '' + stdout + ""; + //var xmlStr = "/g,">"); + //xmlStr = xmlStr.replace(/\n>/g,"
"); + //xmlStr = xmlStr.replace(/\t>/g,"   "); + + writeToFile(file,"" +xmlStr+ ""); + //console.log("xmlStr:" + xmlStr); + res.setHeader('Content-disposition', 'attachment; filename=' + file); + //res.setHeader('Content-type', 'text/html'); + res.setHeader('Content-type', 'text/xml'); + res.download(file); + } + } + }); +} + + + RED.httpAdmin.get("/displayAsGv", function(req,res) { + var _module = req.query._module; + var rpc = req.query.rpc; + var version = req.query.version; + var mode = req.query.mode; + var d = new Date().getTime(); + displayAsGv(_module,rpc,version,mode,res); + }); + +function displayAsGv(_module,rpc,version,mode,res){ + var exec = require('child_process').exec; + var msg = { + '_module' : _module, + 'rpc' : rpc, + 'version' : version, + 'mode' : mode + } + var commandToExec = appDir + "/svclogic/svclogic.sh print " + + _module + " " + rpc + " " + mode + " " + version + " " + //+ userDir + "/conf/svclogic.properties | dot -Tpng "; + //the label="""" is giving an error so replacing it with "null" + + userDir + "/conf/svclogic.properties |sed -e 's%label=\"\"\"\"%label=\"null\"%g'| dot -Tsvg "; + console.log("commandToExec:" + commandToExec); + //+ userDir + "/conf/svclogic.properties | dot -Tsvg "; + //var child = exec(commandToExec ,function (error,stdout,stderr){ + //var child = exec(commandToExec ,{maxBuffer:16*1024*1024},function (error,stdout,stderr){ + //var child = exec(commandToExec ,{encoding:'base64',maxBuffer:20*1024*1024},function (error,stdout,stderr){ + var child = exec(commandToExec ,{maxBuffer:20*1024*1024},function (error,stdout,stderr){ + if(error){ + console.log("Error occured:" + error); + if(stderr){ + console.log("stderr:" + stderr); + res.send(500,{'error':error,'stderr':stderr,"msg":msg}); + }else{ + res.send(500,{'error':error,"msg":msg}); + } + }else{ + if(stderr){ + console.log("stderr:" + stderr); + //To convert base64 to ascii + //console.log(new Buffer(stderr, 'base64').toString('ascii')); + } + if(stdout){ + //console.log(stdout.length); + //console.log("output:" + stdout); + //var svg_html = stdout ; + //var image = ""; + //var image = "