node-red-contrib-bluemix-hdfs
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -58,3 +58,3 @@ /** | ||
bigcredentials = service.credentials; | ||
node.log("BIG CREDENTIALS FOUND....."); | ||
console.log("BIG CREDENTIALS FOUND....."); | ||
break; | ||
@@ -107,4 +107,2 @@ } | ||
node.log("User = " + bigcredentials.userid); | ||
node.log("Password = " + bigcredentials.password); | ||
node.log("filename = " + filename); | ||
@@ -115,3 +113,2 @@ if (filename == "") { | ||
var opts = urllib.parse(url + "?op=OPEN"); | ||
node.log("URL = " + url + "?op=OPEN"); | ||
opts.method = "GET"; | ||
@@ -128,5 +125,6 @@ opts.headers = {}; | ||
msg.statusCode = res.statusCode; | ||
node.log("Status = " + msg.statusCode); | ||
msg.headers = res.headers; | ||
if(msg.payload !== null) { | ||
node.log("Payload = " + msg.payload); | ||
} else { | ||
@@ -137,3 +135,3 @@ msg.payload = ""; | ||
node.status({fill:"green",shape:"dot",text:"connected"}); | ||
msg.payload += chunk; | ||
msg.payload = chunk; | ||
payload = msg.payload; | ||
@@ -146,2 +144,5 @@ | ||
node.log("Payload in END = " + msg.payload); | ||
if(msg.payload.boolean == false) { | ||
node.error("Unable to delete the file"); | ||
} | ||
node.status({fill:"grey",shape:"dot",text:"done"}); | ||
@@ -158,3 +159,2 @@ }); | ||
req.write(payload); | ||
node.log("Payload written....."); | ||
} | ||
@@ -189,4 +189,3 @@ req.end(); | ||
node.log("User = " + bigcredentials.userid); | ||
node.log("Password = " + bigcredentials.password); | ||
var fileChanged = false; | ||
node.log("filename = " + filename); | ||
@@ -199,4 +198,13 @@ | ||
var opts; | ||
if (typeof data == "object") { data = JSON.stringify(data); } | ||
if (typeof data == "boolean") { data = data.toString(); } | ||
if (typeof data == "object") { | ||
data = JSON.stringify(data); | ||
} | ||
if (typeof data == "boolean") { | ||
data = data.toString(); | ||
} | ||
if (typeof data == "number") { | ||
data += ""; | ||
} | ||
if (appendNewline) { | ||
@@ -212,5 +220,3 @@ data += "\n"; | ||
else { | ||
node.log("\n\n\n\nCAME HERE 1.......\n\n\n\n"); | ||
if(n.overwriteFile) { | ||
node.log("\n\n\n\nCAME HERE 3.......\n\n\n\n"); | ||
opts = urllib.parse(url + "?op=CREATE&data=true"); | ||
@@ -223,3 +229,2 @@ opts.method = "PUT"; | ||
} else { | ||
node.log("\n\n\n\nCAME HERE 2.......\n\n\n\n"); | ||
opts = urllib.parse(url + "?op=APPEND&data=true"); | ||
@@ -229,11 +234,6 @@ opts.method = "POST"; | ||
opts.auth = bigcredentials.userid+":"+(bigcredentials.password||""); | ||
opts.headers['content-type'] = 'application/octet-stream'; | ||
} | ||
if (typeof data == "number") { | ||
data = data + ""; | ||
opts.headers['transfer-encoding'] = 'chunked'; | ||
opts.headers['content-type'] = 'application/octet-stream'; | ||
} | ||
if(n.appendNewline) { | ||
node.log("APPENDING NEW LINE"); | ||
payload += "\n"; | ||
} | ||
if (opts.headers['content-length'] == null) { | ||
@@ -252,11 +252,59 @@ opts.headers['content-length'] = Buffer.byteLength(data); | ||
if(msg.statusCode == 404 ) { | ||
node.error("FileNotFoundException thrown......"); | ||
node.error("File doesnt exist, so creating one"); | ||
opts = null; | ||
opts = urllib.parse(url + "?op=CREATE&data=true"); | ||
opts.method = "PUT"; | ||
opts.headers = {}; | ||
opts.auth = bigcredentials.userid+":"+(bigcredentials.password||""); | ||
opts.headers['transfer-encoding'] = 'chunked'; | ||
opts.headers['content-type'] = 'application/octet-stream'; | ||
if (opts.headers['content-length'] == null) { | ||
opts.headers['content-length'] = Buffer.byteLength(data); | ||
} | ||
var req1 = ((/^https/.test(url))?https:http).request(opts,function(res1) { | ||
res1.setEncoding('utf8'); | ||
msg.statusCode = res1.statusCode; | ||
msg.headers = res1.headers; | ||
res1.on('data',function(chunk) { | ||
node.status({fill:"green",shape:"dot",text:"connected"}); | ||
node.log("Status code = " + msg.statusCode); | ||
if(msg.statusCode == 404 ) { | ||
node.error("Unable to create the file......"); | ||
fileChanged = false; | ||
} else { | ||
data += chunk; | ||
fileChanged = true | ||
} | ||
node.log("\n\nPayload in DATA AGAIN= " + data); | ||
}); | ||
res1.on('end',function() { | ||
node.send(msg); | ||
node.log("\n\nPayload in END AGAIN= " + data); | ||
node.status({fill:"grey",shape:"dot",text:"done"}); | ||
}); | ||
}); | ||
req1.on('error',function(err) { | ||
data = err.toString(); | ||
msg.statusCode = err.code; | ||
node.send(msg); | ||
node.status({fill:"red",shape:"ring",text:err.code}); | ||
fileChanged = false; | ||
}); | ||
if (data) { | ||
req1.write(data); | ||
} | ||
req1.end(); | ||
} else { | ||
data += chunk; | ||
fileChanged = true | ||
} | ||
node.log("Payload in DATA = " + data); | ||
node.log("\n\n\n\n\n\n\nPayload in DATA = " + data + "\n\n"); | ||
}); | ||
res.on('end',function() { | ||
node.send(msg); | ||
node.log("Payload in END = " + data); | ||
node.log("\n\nPayload in END = " + data + "\n\n"); | ||
node.status({fill:"grey",shape:"dot",text:"done"}); | ||
@@ -266,10 +314,10 @@ }); | ||
req.on('error',function(err) { | ||
data = err.toString(); | ||
node.log("\n\nPayload in ERROR = " + data + "\n\n"); | ||
msg.statusCode = err.code; | ||
node.send(msg); | ||
node.status({fill:"red",shape:"ring",text:err.code}); | ||
fileChanged = false; | ||
}); | ||
if (data) { | ||
req.write(data); | ||
node.log("Payload written....."); | ||
} | ||
@@ -284,3 +332,2 @@ req.end(); | ||
RED.httpAdmin.get('/http-request/:id',function(req,res) { | ||
node.log("INSIDE HTTP GET REQUEST.......\n\n\n"); | ||
var credentials = RED.nodes.getCredentials(req.params.id); | ||
@@ -295,3 +342,2 @@ if (credentials) { | ||
RED.httpAdmin.delete('/http-request/:id',function(req,res) { | ||
node.log("INSIDE HTTP DELETE REQUEST.......\n\n\n"); | ||
RED.nodes.deleteCredentials(req.params.id); | ||
@@ -302,3 +348,2 @@ res.send(200); | ||
RED.httpAdmin.post('/http-request/:id',function(req,res) { | ||
node.log("INSIDE HTTP POST REQUEST.......\n\n\n"); | ||
var body = ""; | ||
@@ -305,0 +350,0 @@ req.on('data', function(chunk) { |
@@ -8,3 +8,3 @@ { | ||
"description": "Big Data node on IBM Bluemix. This version works fine, however, its not the final release and more changes are expected", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"keywords": [ | ||
@@ -11,0 +11,0 @@ "node-red" |
59758
316