1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.ui.commons.actuate;
20
21 import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
22 import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
23 import org.apache.syncope.common.keymaster.client.api.ServiceOps;
24 import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
25 import org.apache.syncope.common.rest.api.service.UserSelfService;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.boot.actuate.health.Health;
29 import org.springframework.boot.actuate.health.HealthIndicator;
30 import org.springframework.boot.actuate.health.Status;
31
32 public class SyncopeCoreHealthIndicator implements HealthIndicator {
33
34 protected static final Logger LOG = LoggerFactory.getLogger(SyncopeCoreHealthIndicator.class);
35
36 protected final ServiceOps serviceOps;
37
38 protected final String anonymousUser;
39
40 protected final String anonymousKey;
41
42 protected final boolean useGZIPCompression;
43
44 private UserSelfService service;
45
46 public SyncopeCoreHealthIndicator(
47 final ServiceOps serviceOps,
48 final String anonymousUser,
49 final String anonymousKey,
50 final boolean useGZIPCompression) {
51
52 this.serviceOps = serviceOps;
53 this.anonymousUser = anonymousUser;
54 this.anonymousKey = anonymousKey;
55 this.useGZIPCompression = useGZIPCompression;
56 }
57
58 protected UserSelfService service() {
59 synchronized (this) {
60 if (service == null) {
61 service = new SyncopeClientFactoryBean().
62 setAddress(serviceOps.get(NetworkService.Type.CORE).getAddress()).
63 setUseCompression(useGZIPCompression).
64 create(new AnonymousAuthenticationHandler(anonymousUser, anonymousKey)).
65 getService(UserSelfService.class);
66 }
67 }
68 return service;
69 }
70
71 @Override
72 public Health health() {
73 Health.Builder builder = new Health.Builder();
74
75 try {
76 service().read();
77 builder.status(Status.UP);
78 } catch (Exception e) {
79 LOG.debug("When attempting to connect to Syncope Core", e);
80 builder.status(Status.DOWN);
81 }
82
83 return builder.build();
84 }
85 }