diff --git a/pom.xml b/pom.xml
index 700f4a1..5be5c97 100644
--- a/pom.xml
+++ b/pom.xml
@@ -136,6 +136,11 @@
description-ml-api
0.1.0-SNAPSHOT
+
+ commons-validator
+ commons-validator
+ 1.3.1
+
diff --git a/src/main/java/com/wine/to/up/apigateway/service/controller/ApiGatewayController.java b/src/main/java/com/wine/to/up/apigateway/service/controller/ApiGatewayController.java
index 0269fdd..d49e58d 100644
--- a/src/main/java/com/wine/to/up/apigateway/service/controller/ApiGatewayController.java
+++ b/src/main/java/com/wine/to/up/apigateway/service/controller/ApiGatewayController.java
@@ -1,10 +1,12 @@
package com.wine.to.up.apigateway.service.controller;
import com.netflix.zuul.context.RequestContext;
+import com.wine.to.up.apigateway.service.dto.ServiceStatusDTO;
import com.wine.to.up.apigateway.service.dto.WinePositionWithFavorites;
import com.wine.to.up.apigateway.service.dto.WinePositionWithRecommendations;
import com.wine.to.up.apigateway.service.jwt.JwtTokenProvider;
import com.wine.to.up.apigateway.service.service.FavoritePositionService;
+import com.wine.to.up.apigateway.service.status.CallServices;
import com.wine.to.up.catalog.service.api.dto.WinePositionTrueResponse;
import com.wine.to.up.catalog.service.api.feign.FavoriteWinePositionsClient;
import com.wine.to.up.catalog.service.api.feign.WinePositionClient;
@@ -15,6 +17,8 @@
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -43,6 +47,8 @@ public class ApiGatewayController {
private final WineRecommendationServiceClient wineRecommendationServiceClient;
+ private final CallServices callServices;
+
@ApiOperation(value = "Get favourites wine positions",
nickname = "getFavouritesPositions",
@@ -97,6 +103,11 @@ public List getWinePositions(@RequestParam(required =
return favoritePositionService.convertWinePositions(positions, ids);
}
+ @GetMapping("/statuses")
+ public ResponseEntity> servicesStatuses() {
+ return new ResponseEntity<>(callServices.checkServices(), HttpStatus.OK);
+ }
+
@GetMapping("/position/true/byId/{id}")
public WinePositionWithFavorites getWineById(@Valid @PathVariable(name = "id") String winePositionId) {
log.info("Got request for positions by id");
@@ -163,11 +174,11 @@ private Set getFavoriteIds(String accessToken) {
private List getWinePositionTrueResponses(String page, String amount, List sortByPair, String filterBy) {
Map> query = new HashMap<>();
- List amountList = new ArrayList<>();
+ List amountList = new ArrayList<>();
amountList.add(amount);
- List pageList = new ArrayList<>();
+ List pageList = new ArrayList<>();
pageList.add(page);
- List filterByList = new ArrayList<>();
+ List filterByList = new ArrayList<>();
filterByList.add(filterBy);
query.put("sortByPair", sortByPair);
query.put("amount", amountList);
diff --git a/src/main/java/com/wine/to/up/apigateway/service/dto/ServiceStatusDTO.java b/src/main/java/com/wine/to/up/apigateway/service/dto/ServiceStatusDTO.java
new file mode 100644
index 0000000..fd6d060
--- /dev/null
+++ b/src/main/java/com/wine/to/up/apigateway/service/dto/ServiceStatusDTO.java
@@ -0,0 +1,13 @@
+package com.wine.to.up.apigateway.service.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class ServiceStatusDTO {
+ private String serviceName;
+ private Boolean isActive;
+}
diff --git a/src/main/java/com/wine/to/up/apigateway/service/status/CallServices.java b/src/main/java/com/wine/to/up/apigateway/service/status/CallServices.java
new file mode 100644
index 0000000..cce240e
--- /dev/null
+++ b/src/main/java/com/wine/to/up/apigateway/service/status/CallServices.java
@@ -0,0 +1,51 @@
+package com.wine.to.up.apigateway.service.status;
+
+import com.wine.to.up.apigateway.service.dto.ServiceStatusDTO;
+import org.apache.commons.validator.UrlValidator;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@Component
+public class CallServices {
+ private static final ArrayList services = (ArrayList) Arrays.asList(
+ "http://proxy-service:8080",
+ "http://catalog-service:8080",
+ "http://user-service:8080",
+ "http://ml-description-based-recommendation-service:5000",
+ "http://ml-team-2-service:80",
+ "http://ml3-recommendation-service:8000",
+ "http://segandrec-service:5000",
+ "http://notification-service:8080"
+ );
+ private static final String extractServiceNameRegExp = "http:\\/\\/([-\\w]+):[0-9]+";
+
+ private String extractServiceName(String service) {
+ Pattern pattern = Pattern.compile(extractServiceNameRegExp);
+ Matcher matcher = pattern.matcher(service);
+ return matcher.group(1);
+ }
+
+ private Boolean getStatus(String service) {
+ UrlValidator urlValidator = new UrlValidator();
+ return urlValidator.isValid(service);
+ }
+
+ public List checkServices() {
+ List serviceStatusDTOS = new ArrayList<>();
+
+ for(String service : services) {
+ ServiceStatusDTO serviceStatusDTO = new ServiceStatusDTO();
+
+ serviceStatusDTO.setServiceName(extractServiceName(service));
+ serviceStatusDTO.setIsActive(getStatus(service));
+ serviceStatusDTOS.add(serviceStatusDTO);
+ }
+
+ return serviceStatusDTOS;
+ }
+}