16
16
17
17
package net .devh .boot .grpc .server .health ;
18
18
19
- import java .util .Objects ;
20
19
20
+ import static io .grpc .Status .NOT_FOUND ;
21
+
22
+ import org .springframework .boot .actuate .health .HealthComponent ;
21
23
import org .springframework .boot .actuate .health .HealthEndpoint ;
24
+ import org .springframework .boot .actuate .health .Status ;
22
25
23
- import io .grpc .Status ;
24
26
import io .grpc .StatusException ;
25
27
import io .grpc .health .v1 .HealthCheckRequest ;
26
28
import io .grpc .health .v1 .HealthCheckResponse ;
@@ -37,20 +39,20 @@ public ActuatorGrpcHealth(HealthEndpoint healthEndpoint) {
37
39
public void check (HealthCheckRequest request , StreamObserver <HealthCheckResponse > responseObserver ) {
38
40
39
41
if (!request .getService ().isEmpty ()) {
40
- var health = healthEndpoint .healthForPath (request .getService ());
42
+ HealthComponent health = healthEndpoint .healthForPath (request .getService ());
41
43
if (health == null ) {
42
- responseObserver .onError (new StatusException (
43
- Status . NOT_FOUND .withDescription ("unknown service " + request .getService ())));
44
+ responseObserver .onError (
45
+ new StatusException ( NOT_FOUND .withDescription ("unknown service " + request .getService ())));
44
46
return ;
45
47
}
46
- var status = health .getStatus ();
48
+ Status status = health .getStatus ();
47
49
HealthCheckResponse .ServingStatus result = resolveStatus (status );
48
50
HealthCheckResponse response = HealthCheckResponse .newBuilder ().setStatus (result ).build ();
49
51
responseObserver .onNext (response );
50
52
responseObserver .onCompleted ();
51
53
} else {
52
54
53
- var status = healthEndpoint .health ().getStatus ();
55
+ Status status = healthEndpoint .health ().getStatus ();
54
56
HealthCheckResponse .ServingStatus result = resolveStatus (status );
55
57
HealthCheckResponse response = HealthCheckResponse .newBuilder ().setStatus (result ).build ();
56
58
responseObserver .onNext (response );
@@ -59,12 +61,11 @@ public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse
59
61
60
62
}
61
63
62
- private HealthCheckResponse .ServingStatus resolveStatus (org . springframework . boot . actuate . health . Status status ) {
63
- if (Objects . equals ( org . springframework . boot . actuate . health . Status .UP .getCode (), status . getCode () )) {
64
+ private HealthCheckResponse .ServingStatus resolveStatus (Status status ) {
65
+ if (Status .UP .equals ( status )) {
64
66
return HealthCheckResponse .ServingStatus .SERVING ;
65
67
}
66
- if (Objects .equals (org .springframework .boot .actuate .health .Status .DOWN .getCode (), status .getCode ()) || Objects
67
- .equals (org .springframework .boot .actuate .health .Status .OUT_OF_SERVICE .getCode (), status .getCode ())) {
68
+ if (Status .DOWN .equals (status ) || Status .OUT_OF_SERVICE .equals (status )) {
68
69
return HealthCheckResponse .ServingStatus .NOT_SERVING ;
69
70
}
70
71
return HealthCheckResponse .ServingStatus .UNKNOWN ;
0 commit comments