Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 3689072

Browse files
committed
added SystemHealth
1 parent eeb02f4 commit 3689072

File tree

7 files changed

+109
-5
lines changed

7 files changed

+109
-5
lines changed

pom.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,30 @@
2020

2121
<dependencies>
2222

23-
<dependency>
24-
<groupId>org.projectlombok</groupId>
25-
<artifactId>lombok</artifactId>
26-
<version>LATEST</version>
27-
</dependency>
2823
<dependency>
2924
<groupId>org.springframework.boot</groupId>
3025
<artifactId>spring-boot-starter-web</artifactId>
3126
</dependency>
3227

28+
<!--
3329
<dependency>
3430
<groupId>org.springframework.boot</groupId>
3531
<artifactId>spring-boot-starter-data-mongodb</artifactId>
3632
</dependency>
33+
-->
3734

3835
<dependency>
3936
<groupId>io.springfox</groupId>
4037
<artifactId>springfox-boot-starter</artifactId>
4138
<version>3.0.0</version>
4239
</dependency>
4340

41+
<dependency>
42+
<groupId>org.projectlombok</groupId>
43+
<artifactId>lombok</artifactId>
44+
<version>LATEST</version>
45+
</dependency>
46+
4447
<!-- tag::spring-hateoas[] -->
4548
<dependency>
4649
<groupId>org.springframework.boot</groupId>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)