1
|
package eu.dnetlib.uoamonitorservice.controllers;
|
2
|
|
3
|
import com.mongodb.BasicDBObject;
|
4
|
import com.mongodb.CommandResult;
|
5
|
import com.mongodb.DBObject;
|
6
|
import eu.dnetlib.uoamonitorservice.configuration.mongo.MongoConnection;
|
7
|
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
11
|
import org.springframework.security.access.prepost.PreAuthorize;
|
12
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
13
|
import org.springframework.web.bind.annotation.RequestMapping;
|
14
|
import org.springframework.web.bind.annotation.RequestMethod;
|
15
|
import org.springframework.web.bind.annotation.RestController;
|
16
|
|
17
|
import java.util.HashMap;
|
18
|
import java.util.Map;
|
19
|
|
20
|
@RestController
|
21
|
@CrossOrigin(origins = "*")
|
22
|
public class MonitorServiceCheckDeployController {
|
23
|
private final Logger log = Logger.getLogger(this.getClass());
|
24
|
|
25
|
@Autowired
|
26
|
private MongoConnection mongoConnection;
|
27
|
|
28
|
@Autowired
|
29
|
private MongoConfig mongoConfig;
|
30
|
|
31
|
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
32
|
public String hello() {
|
33
|
log.debug("Hello from uoa-monitor-service!");
|
34
|
return "Hello from uoa-monitor-service!";
|
35
|
}
|
36
|
|
37
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
38
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
39
|
public Map<String, String> checkEverything() {
|
40
|
Map<String, String> response = new HashMap<>();
|
41
|
|
42
|
MongoTemplate mt = mongoConnection.getMongoTemplate();
|
43
|
DBObject ping = new BasicDBObject("ping", "1");
|
44
|
try {
|
45
|
CommandResult answer = mt.getDb().command(ping);
|
46
|
response.put("Mongo try: error", answer.getErrorMessage());
|
47
|
} catch (Exception e) {
|
48
|
response.put("Mongo catch: error", e.getMessage());
|
49
|
}
|
50
|
|
51
|
response.put("monitorservice.mongodb.database", mongoConfig.getDatabase());
|
52
|
response.put("monitorservice.mongodb.host", mongoConfig.getHost());
|
53
|
response.put("monitorservice.mongodb.port", mongoConfig.getPort()+"");
|
54
|
response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
|
55
|
response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
|
56
|
// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password");
|
57
|
|
58
|
return response;
|
59
|
}
|
60
|
}
|