-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
102 lines (98 loc) · 3.23 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var express = require("express");
var app = express();
const cors = require("cors");
var jenkinsJobsCollector = require("./jenkins-collector/jobs");
const { upsertJobsDetails } = require("./database/upsertJobsDetails");
var jenkinsSlavesCollector = require("./jenkins-collector/slaves");
const { upsertSlavesDetails } = require("./database/upsertSlavesDetails");
const { getDetails } = require("./database/getDetails");
app.use(cors());
app.get("/getJobsDetails", (req, res, next) => {
jenkinsJobsCollector.collectData(function(jobsDetails) {
if (jobsDetails != "ERROR AT JENKINS") {
upsertJobsDetails(jobsDetails)
.then(data => {
console.log(`${data[0]} jobs were inserted`);
console.log(`${data[1]} jobs were updated`);
})
.catch(err => {
console.log(
"###########################################################################"
);
console.log("");
console.log("");
console.log(
"There is some problem while connecting to mongoDB. Please check logs."
);
console.log("");
console.log("");
console.log(
"###########################################################################"
);
});
return res.json(jobsDetails);
} else {
getDetails("jenkins", "jobsDetails")
.then(data => {
if (data.length > 0) {
res.json(data);
} else {
res.json(
"No data is present at moment. Please check your configuration..."
);
}
})
.catch(err => {
res.json(
"Either Jenkins or mongoDB is not configured properly. Please check logs and configuration..."
);
});
}
});
});
app.get("/getSlavesDetails", (req, res, next) => {
jenkinsSlavesCollector.collectData(function(slavesDetails) {
if (slavesDetails != "ERROR AT JENKINS") {
upsertSlavesDetails(slavesDetails.computers)
.then(data => {
console.log(`${data[0]} slaves were inserted`);
console.log(`${data[1]} slaves were updated`);
})
.catch(err => {
console.log(
"###########################################################################"
);
console.log("");
console.log("");
console.log(
"There is some problem while connecting to mongoDB. Please check logs."
);
console.log("");
console.log("");
console.log(
"###########################################################################"
);
});
return res.json(slavesDetails);
} else {
getDetails("jenkins", "slavesDetails")
.then(data => {
if (data.length > 0) {
res.json(data);
} else {
res.json(
"No data is present at moment. Please check your configuration..."
);
}
})
.catch(err => {
res.json(
"Either Jenkins or mongoDB is not configured properly. Please check logs and configuration..."
);
});
}
});
});
app.listen(5000, () => {
console.log("Server running on port 5000");
});