Revision 60955
Added by Konstantina Galouni about 3 years ago
AdminToolsCheckDeployController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintools.controllers; |
2 | 2 |
|
3 |
import com.mongodb.BasicDBObject; |
|
4 |
import com.mongodb.CommandResult; |
|
5 |
import com.mongodb.DBObject; |
|
6 |
import eu.dnetlib.uoaadmintools.configuration.mongo.MongoConnection; |
|
7 |
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig; |
|
8 |
import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig; |
|
3 | 9 |
import org.apache.log4j.Logger; |
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
import org.springframework.data.mongodb.core.MongoTemplate; |
|
12 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
4 | 13 |
import org.springframework.web.bind.annotation.CrossOrigin; |
5 | 14 |
import org.springframework.web.bind.annotation.RequestMapping; |
6 | 15 |
import org.springframework.web.bind.annotation.RequestMethod; |
7 | 16 |
import org.springframework.web.bind.annotation.RestController; |
8 | 17 |
|
18 |
import java.util.HashMap; |
|
19 |
import java.util.Map; |
|
20 |
|
|
9 | 21 |
@RestController |
10 | 22 |
@CrossOrigin(origins = "*") |
11 | 23 |
public class AdminToolsCheckDeployController { |
12 | 24 |
private final Logger log = Logger.getLogger(this.getClass()); |
13 | 25 |
|
14 |
@RequestMapping(value = "", method = RequestMethod.GET) |
|
26 |
@Autowired |
|
27 |
private MongoConnection mongoConnection; |
|
28 |
|
|
29 |
@Autowired |
|
30 |
private MongoConfig mongoConfig; |
|
31 |
|
|
32 |
@Autowired |
|
33 |
private ManagersApiConfig managersApiConfig; |
|
34 |
|
|
35 |
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET) |
|
15 | 36 |
public String hello() { |
16 | 37 |
log.debug("Hello from uoa-admin-tools!"); |
17 | 38 |
return "Hello from uoa-admin-tools!"; |
18 | 39 |
} |
40 |
|
|
41 |
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") |
|
42 |
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET) |
|
43 |
public Map<String, String> checkEverything() { |
|
44 |
Map<String, String> response = new HashMap<>(); |
|
45 |
|
|
46 |
MongoTemplate mt = mongoConnection.getMongoTemplate(); |
|
47 |
DBObject ping = new BasicDBObject("ping", "1"); |
|
48 |
try { |
|
49 |
CommandResult answer = mt.getDb().command(ping); |
|
50 |
response.put("Mongo try: error", answer.getErrorMessage()); |
|
51 |
} catch (Exception e) { |
|
52 |
response.put("Mongo catch: error", e.getMessage()); |
|
53 |
} |
|
54 |
|
|
55 |
response.put("admintool.mongodb.database", mongoConfig.getDatabase()); |
|
56 |
response.put("admintool.mongodb.host", mongoConfig.getHost()); |
|
57 |
response.put("admintool.mongodb.port", mongoConfig.getPort()+""); |
|
58 |
response.put("admintool.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]"); |
|
59 |
response.put("admintool.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]"); |
|
60 |
// response.put("Define also", "admintool.mongodb.username, admintool.mongodb.password"); |
|
61 |
|
|
62 |
response.put("admintool.managers.api.id", managersApiConfig.getId()); |
|
63 |
response.put("admintool.managers.api.email", managersApiConfig.getEmail()); |
|
64 |
return response; |
|
65 |
} |
|
19 | 66 |
} |
Also available in: Unified diff
[Trunk | Admin Tools]:
1. AdminToolsCheckDeployController.java:
a. In "hello()" method added @RequestMapping (except for existing ""), "/health_check".
b. Added method "checkEverything()" (/health_chech/advanced) only accessible by PORTAL ADMINS which checks connection with db and prints properties.
2. Layout.java: Commented all fields for layout configuration (e.g. mainColor, buttons,...) and added an Object layoutOptions which includes any required options.