-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into qa_tests/regression_test_authentication
- Loading branch information
Showing
15 changed files
with
277 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/main/java/hng_java_boilerplate/statusPage/controller/ApiStatusController.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/main/java/hng_java_boilerplate/statusPage/controller/StatusPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package hng_java_boilerplate.statusPage.controller; | ||
|
||
import hng_java_boilerplate.statusPage.entity.StatusPage; | ||
import hng_java_boilerplate.statusPage.service.StatusPageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/api-status") | ||
public class StatusPageController { | ||
|
||
private final StatusPageService statusPageService; | ||
|
||
@GetMapping | ||
public List<StatusPage> getAllApiStatuses() { | ||
return statusPageService.getAllApiStatuses(); | ||
} | ||
|
||
@PostMapping | ||
public void updateApiStatus() { | ||
statusPageService.updateApiStatus(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
src/main/java/hng_java_boilerplate/statusPage/repository/ApiStatusRepository.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/hng_java_boilerplate/statusPage/repository/StatusPageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package hng_java_boilerplate.statusPage.repository; | ||
|
||
import hng_java_boilerplate.statusPage.entity.StatusPage; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface StatusPageRepository extends JpaRepository<StatusPage, Long> { | ||
} |
12 changes: 0 additions & 12 deletions
12
src/main/java/hng_java_boilerplate/statusPage/service/ApiStatusService.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/java/hng_java_boilerplate/statusPage/service/ApiStatusServiceImpl.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/main/java/hng_java_boilerplate/statusPage/service/StatusPageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package hng_java_boilerplate.statusPage.service; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import hng_java_boilerplate.statusPage.entity.StatusPage; | ||
|
||
import java.util.List; | ||
|
||
public interface StatusPageService { | ||
void updateApiStatus(); | ||
void processJsonData(JsonNode jsonNode); | ||
List<StatusPage> getAllApiStatuses(); | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/hng_java_boilerplate/statusPage/service/StatusPageServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package hng_java_boilerplate.statusPage.service; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import hng_java_boilerplate.statusPage.entity.StatusPage; | ||
import hng_java_boilerplate.statusPage.entity.StatusPage.Status; | ||
import hng_java_boilerplate.statusPage.repository.StatusPageRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StatusPageServiceImpl implements StatusPageService { | ||
|
||
private final StatusPageRepository statusPageRepository; | ||
private final ObjectMapper objectMapper; | ||
private static final String RESULT_JSON_PATH = "/home/${{ secrets.USERNAME }}/hng_boilerplate_java_web/result.json"; | ||
|
||
@Override | ||
@Scheduled(fixedRate = 900000) | ||
public void updateApiStatus() { | ||
try { | ||
File jsonFile = new File(RESULT_JSON_PATH); | ||
JsonNode jsonNode = objectMapper.readTree(jsonFile); | ||
processJsonData(jsonNode); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void processJsonData(JsonNode jsonNode) { | ||
JsonNode executions = jsonNode.get("run").get("executions"); | ||
|
||
for (JsonNode execution : executions) { | ||
String apiGroup = execution.get("item").get("name").asText(); | ||
int responseTime = execution.get("response").get("responseTime").asInt(); | ||
int statusCode = execution.get("response").get("code").asInt(); | ||
String statusMessage = execution.get("response").get("status").asText(); | ||
|
||
StatusPage statusPage = new StatusPage(); | ||
statusPage.setApiGroup(apiGroup); | ||
statusPage.setResponseTime(responseTime); | ||
statusPage.setLastChecked(LocalDateTime.now()); | ||
|
||
if (statusCode >= 200 && statusCode < 300) { | ||
statusPage.setStatus(Status.OPERATIONAL); | ||
} else if (statusCode >= 500) { | ||
statusPage.setStatus(Status.DEGRADED); | ||
} else { | ||
statusPage.setStatus(Status.DOWN); | ||
} | ||
|
||
statusPage.setDetails(statusMessage); | ||
|
||
statusPageRepository.save(statusPage); | ||
} | ||
} | ||
|
||
@Override | ||
public List<StatusPage> getAllApiStatuses() { | ||
return statusPageRepository.findAll(); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
src/main/java/hng_java_boilerplate/statusPage/util/NewmanResultParser.java
This file was deleted.
Oops, something went wrong.
79 changes: 0 additions & 79 deletions
79
src/test/java/hng_java_boilerplate/statusPage/controller/ApiStatusControllerTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.