11package edu .tamu .app .service ;
22
3+ import static edu .tamu .app .enums .OverallMessageType .ERROR ;
4+ import static edu .tamu .app .enums .OverallMessageType .SUCCESS ;
5+
36import java .io .IOException ;
47import java .net .MalformedURLException ;
58import java .util .List ;
1417import com .fasterxml .jackson .databind .ObjectMapper ;
1518
1619import edu .tamu .app .enums .Status ;
20+ import edu .tamu .app .model .OverallStatus ;
1721import edu .tamu .app .model .repo .ServiceRepo ;
1822import edu .tamu .framework .util .HttpUtility ;
1923
@@ -27,6 +31,9 @@ public class SystemMonitorService implements MonitorService {
2731
2832 @ Autowired
2933 ObjectMapper objectMapper ;
34+
35+ private static final String SUCCESS_MESSAGE = "All services are working." ;
36+ private static final String ERROR_MESSAGE = "Some services are experiencing problems." ;
3037
3138 private Logger logger = LoggerFactory .getLogger (this .getClass ());
3239
@@ -49,6 +56,21 @@ public void updateAll() {
4956 });
5057 }
5158
59+ public OverallStatus getOverallStatus () {
60+ Long downCount = serviceRepo .countByStatus (Status .DOWN );
61+ if (downCount == 0 ) {
62+ return new OverallStatus (SUCCESS , SUCCESS_MESSAGE );
63+ }
64+ return new OverallStatus (ERROR , ERROR_MESSAGE );
65+ }
66+
67+ public OverallStatus getOverallStatusPublic () {
68+ Long downCount = serviceRepo .countByStatusAndIsPublic (Status .DOWN ,true );
69+ if (downCount == 0 ) {
70+ return new OverallStatus (SUCCESS , SUCCESS_MESSAGE );
71+ }
72+ return new OverallStatus (ERROR , ERROR_MESSAGE );
73+ }
5274 protected Status getServiceStatus (String serviceUrl ) throws MalformedURLException ,IOException {
5375 String rawStatusResponse = httpUtility .makeHttpRequest (serviceUrl , "GET" );
5476 List <Map <String ,String >> mappedStatusResponse = objectMapper .readValue (rawStatusResponse , new TypeReference <List <Map <String , String >>>(){});
0 commit comments