-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport-common.js
58 lines (58 loc) · 2.15 KB
/
support-common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//************************************************
var dateFormat = require('dateformat');
module.exports = {
//****************************************************
//This function flush the pending operations to the DataBase.
my_flush: function( remoteAddress, es_server, my_index){
var testhttp = require('http');
var rescode="";
var myres = { code: "", text: "" };
var currentdate = dateFormat(new Date(), "yyyy-mm-dd'T'HH:MM:ss.l");
return new Promise( (resolve,reject) => {
testhttp.get('http://'+es_server+'/'+my_index+'/_flush', function(rescode) {
myres.code="200";
myres.text="200 Succeed";
resolve (myres);
}).on('error', function(e) {
myres.code="400";
myres.text="400"+"Flush error "+currentdate;
LogsModule.register_log(es_servername+":"+es_port,SERVERDB, 400, remoteAddress,"Flush error "+e,currentdate,"");
reject (myres);
});
});
},
// curl -XPOST localhost:9400/_flush/synced
synced_flush: function( remoteAddress, es_server, my_index){
var testhttp = require('http');
var rescode="";
var myres = { code: "", text: "" };
var currentdate = dateFormat(new Date(), "yyyy-mm-dd'T'HH:MM:ss.l");
return new Promise( (resolve,reject) => {
testhttp.get('http://'+es_server+'/'+my_index+'/_flush/synced', function(rescode) {
myres.code="200";
myres.text="200 Succeed";
resolve (myres);
}).on('error', function(e) {
myres.code="400";
myres.text="400"+"Flush error "+currentdate;
LogsModule.register_log(es_servername+":"+es_port,SERVERDB, 400, remoteAddress,"Flush error "+e,currentdate,"");
reject (myres);
});
});
},
//**********************************************************
//This function removes double quotation marks if present at the beginning and the end of the input string
remove_quotation_marks: function(input_string){
if(input_string ==undefined){
return("");
}
if(input_string.charAt(0) === '"') {
input_string = input_string.substr(1);
}
if(input_string.length>0){
if(input_string.charAt(input_string.length-1) === '"') {
input_string = input_string.substring(0, input_string.length - 1);
}}
return (input_string);
}
}//end module.exports