This repository was archived by the owner on Apr 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +109
-5
lines changed
src/main/java/de/filefighter/rest/health Expand file tree Collapse file tree 7 files changed +109
-5
lines changed Original file line number Diff line number Diff line change 20
20
21
21
<dependencies >
22
22
23
- <dependency >
24
- <groupId >org.projectlombok</groupId >
25
- <artifactId >lombok</artifactId >
26
- <version >LATEST</version >
27
- </dependency >
28
23
<dependency >
29
24
<groupId >org.springframework.boot</groupId >
30
25
<artifactId >spring-boot-starter-web</artifactId >
31
26
</dependency >
32
27
28
+ <!--
33
29
<dependency>
34
30
<groupId>org.springframework.boot</groupId>
35
31
<artifactId>spring-boot-starter-data-mongodb</artifactId>
36
32
</dependency>
33
+ -->
37
34
38
35
<dependency >
39
36
<groupId >io.springfox</groupId >
40
37
<artifactId >springfox-boot-starter</artifactId >
41
38
<version >3.0.0</version >
42
39
</dependency >
43
40
41
+ <dependency >
42
+ <groupId >org.projectlombok</groupId >
43
+ <artifactId >lombok</artifactId >
44
+ <version >LATEST</version >
45
+ </dependency >
46
+
44
47
<!-- tag::spring-hateoas[] -->
45
48
<dependency >
46
49
<groupId >org.springframework.boot</groupId >
Original file line number Diff line number Diff line change
1
+ package de .filefighter .rest .health .business ;
2
+
3
+ import de .filefighter .rest .health .data .SystemHealth ;
4
+ import org .springframework .stereotype .Service ;
5
+
6
+ import java .time .Instant ;
7
+
8
+ @ Service
9
+ public class SystemHealthBusinessService {
10
+
11
+ private final long serverStartedAt = Instant .now ().getEpochSecond ();
12
+
13
+ public SystemHealth getCurrentSystemHealthInfo (){
14
+ long currentEpoch = Instant .now ().getEpochSecond ();
15
+ return SystemHealth .builder ()
16
+ .uptimeInSeconds (currentEpoch - serverStartedAt )
17
+ .create ();
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package de .filefighter .rest .health .business ;
2
+
3
+ import de .filefighter .rest .health .data .SystemHealth ;
4
+ import org .jetbrains .annotations .NotNull ;
5
+ import org .springframework .hateoas .EntityModel ;
6
+ import org .springframework .hateoas .server .RepresentationModelAssembler ;
7
+ import org .springframework .stereotype .Component ;
8
+
9
+ @ Component
10
+ public class SystemHealthModelAssembler implements RepresentationModelAssembler <SystemHealth , EntityModel <SystemHealth >> {
11
+
12
+ @ Override
13
+ public @ NotNull EntityModel <SystemHealth > toModel (@ NotNull SystemHealth entity ) {
14
+ return EntityModel .of (entity );
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ package de .filefighter .rest .health .data ;
2
+
3
+ import lombok .Builder ;
4
+ import lombok .Data ;
5
+
6
+ @ Data
7
+ @ Builder (buildMethodName = "create" )
8
+ public class SystemHealth {
9
+ private long uptimeInSeconds ;
10
+ }
Original file line number Diff line number Diff line change
1
+ package de .filefighter .rest .health .rest ;
2
+
3
+ import de .filefighter .rest .health .data .SystemHealth ;
4
+ import org .springframework .hateoas .EntityModel ;
5
+ import org .springframework .web .bind .annotation .GetMapping ;
6
+ import org .springframework .web .bind .annotation .RequestMapping ;
7
+ import org .springframework .web .bind .annotation .RestController ;
8
+
9
+ @ RestController
10
+ @ RequestMapping ("/health" )
11
+ public class HealthRestController {
12
+
13
+ private final HealthRestInterface healthRestService ;
14
+
15
+ public HealthRestController (HealthRestInterface healthRestService ) {
16
+ this .healthRestService = healthRestService ;
17
+ }
18
+
19
+ @ GetMapping ("/" )
20
+ public EntityModel <SystemHealth > getSystemHealthInfo (){
21
+ return healthRestService .getSystemHealth ();
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ package de .filefighter .rest .health .rest ;
2
+
3
+ import de .filefighter .rest .health .data .SystemHealth ;
4
+ import org .springframework .hateoas .EntityModel ;
5
+
6
+ public interface HealthRestInterface {
7
+ EntityModel <SystemHealth > getSystemHealth ();
8
+ }
Original file line number Diff line number Diff line change
1
+ package de .filefighter .rest .health .rest ;
2
+
3
+ import de .filefighter .rest .health .business .SystemHealthBusinessService ;
4
+ import de .filefighter .rest .health .business .SystemHealthModelAssembler ;
5
+ import de .filefighter .rest .health .data .SystemHealth ;
6
+ import org .springframework .hateoas .EntityModel ;
7
+ import org .springframework .stereotype .Service ;
8
+
9
+ @ Service
10
+ public class HealthRestService implements HealthRestInterface {
11
+
12
+ private final SystemHealthBusinessService systemHealthBusinessService ;
13
+ private final SystemHealthModelAssembler systemHealthModelAssembler ;
14
+
15
+ public HealthRestService (SystemHealthBusinessService systemHealthBusinessService , SystemHealthModelAssembler systemHealthModelAssembler ) {
16
+ this .systemHealthBusinessService = systemHealthBusinessService ;
17
+ this .systemHealthModelAssembler = systemHealthModelAssembler ;
18
+ }
19
+
20
+ @ Override
21
+ public EntityModel <SystemHealth > getSystemHealth () {
22
+ SystemHealth systemHealth = systemHealthBusinessService .getCurrentSystemHealthInfo ();
23
+ return systemHealthModelAssembler .toModel (systemHealth );
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments