1
|
package eu.dnetlib.uoaorcidservice.controllers;
|
2
|
|
3
|
import com.mongodb.BasicDBObject;
|
4
|
import com.mongodb.CommandResult;
|
5
|
import com.mongodb.DBObject;
|
6
|
import com.mongodb.MongoTimeoutException;
|
7
|
import eu.dnetlib.uoaorcidservice.configuration.GlobalVars;
|
8
|
import eu.dnetlib.uoaorcidservice.configuration.mongo.MongoConnection;
|
9
|
import eu.dnetlib.uoaorcidservice.configuration.properties.MongoConfig;
|
10
|
import eu.dnetlib.uoaorcidservice.configuration.properties.OrcidConfig;
|
11
|
import eu.dnetlib.uoaorcidservice.handlers.utils.AESUtils;
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.bson.*;
|
14
|
import org.bson.conversions.Bson;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
17
|
import org.springframework.security.access.prepost.PreAuthorize;
|
18
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
19
|
import org.springframework.web.bind.annotation.RequestMapping;
|
20
|
import org.springframework.web.bind.annotation.RequestMethod;
|
21
|
import org.springframework.web.bind.annotation.RestController;
|
22
|
|
23
|
import java.util.Date;
|
24
|
import java.util.HashMap;
|
25
|
import java.util.Map;
|
26
|
|
27
|
@RestController
|
28
|
@CrossOrigin(origins = "*")
|
29
|
public class OrcidServiceCheckDeployController {
|
30
|
private final Logger log = Logger.getLogger(this.getClass());
|
31
|
|
32
|
@Autowired
|
33
|
private MongoConnection mongoConnection;
|
34
|
|
35
|
@Autowired
|
36
|
private MongoConfig mongoConfig;
|
37
|
|
38
|
@Autowired
|
39
|
private OrcidConfig orcidConfig;
|
40
|
|
41
|
@Autowired
|
42
|
private GlobalVars globalVars;
|
43
|
|
44
|
@Autowired
|
45
|
private AESUtils aesUtils;
|
46
|
|
47
|
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
48
|
public String hello() {
|
49
|
log.debug("Hello from uoa-orcid-service!");
|
50
|
return "Hello from uoa-orcid-service!";
|
51
|
}
|
52
|
|
53
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
54
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
55
|
public Map<String, String> checkEverything() {
|
56
|
Map<String, String> response = new HashMap<>();
|
57
|
|
58
|
MongoTemplate mt = mongoConnection.getMongoTemplate();
|
59
|
DBObject ping = new BasicDBObject("ping", "1");
|
60
|
try {
|
61
|
CommandResult answer = mt.getDb().command(ping);
|
62
|
response.put("Mongo try: error", answer.getErrorMessage());
|
63
|
} catch (Exception e) {
|
64
|
response.put("Mongo catch: error", e.getMessage());
|
65
|
}
|
66
|
|
67
|
// Document ping = new Document("ping", "1");
|
68
|
// try {
|
69
|
// Document answer = mt.getDb().runCommand(ping);//.command(ping);
|
70
|
//
|
71
|
// for(String key : answer.keySet()) {
|
72
|
// log.debug("answer pair: "+key + ": "+answer.get(key));
|
73
|
// }
|
74
|
//
|
75
|
// if (answer != null && answer.get("ok") != null && (Double)answer.get("ok") == 1.0d) {
|
76
|
// response.put("Mongo try: everything is ok", answer.toString());//.getErrorMessage());
|
77
|
// } else {
|
78
|
// response.put("Mongo try: error", answer.toString());//.getErrorMessage());
|
79
|
// }
|
80
|
// } catch (MongoTimeoutException e) {
|
81
|
// response.put("Mongo catch timeout: error", e.getMessage());
|
82
|
// } catch (Exception e) {
|
83
|
// response.put("Mongo catch: error", e.getMessage());
|
84
|
// }
|
85
|
|
86
|
response.put("orcidservice.mongodb.database", mongoConfig.getDatabase());
|
87
|
response.put("orcidservice.mongodb.host", mongoConfig.getHost());
|
88
|
response.put("orcidservice.mongodb.port", mongoConfig.getPort()+"");
|
89
|
response.put("orcidservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
|
90
|
response.put("orcidservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
|
91
|
|
92
|
response.put("orcidservice.orcid.apiURL", orcidConfig.getApiURL());
|
93
|
response.put("orcidservice.orcid.tokenURL", orcidConfig.getTokenURL());
|
94
|
response.put("orcidservice.orcid.clientId", orcidConfig.getClientId() == null ? null : "[unexposed value]");
|
95
|
response.put("orcidservice.orcid.clientSecret", orcidConfig.getClientSecret() == null ? null : "[unexposed value]");
|
96
|
|
97
|
response.put("orcidservice.encryption.password", aesUtils.getPassword() == null ? null : "[unexposed value]");
|
98
|
|
99
|
if(globalVars.date != null) {
|
100
|
response.put("Date of deploy", globalVars.date.toString());
|
101
|
}
|
102
|
if(globalVars.getBuildDate() != null) {
|
103
|
response.put("Date of build", globalVars.getBuildDate());
|
104
|
}
|
105
|
if(globalVars.getVersion() != null) {
|
106
|
response.put("Version", globalVars.getVersion());
|
107
|
}
|
108
|
return response;
|
109
|
}
|
110
|
}
|