feat(logging): Add logging for REST Controller
This commit is contained in:
parent
49646d97ed
commit
326c31c149
4 changed files with 37 additions and 3 deletions
|
|
@ -8,6 +8,8 @@ import io.github.js0ny.ilp_coursework.data.request.MovementRequest;
|
||||||
import io.github.js0ny.ilp_coursework.data.request.RegionCheckRequest;
|
import io.github.js0ny.ilp_coursework.data.request.RegionCheckRequest;
|
||||||
import io.github.js0ny.ilp_coursework.service.GpsCalculationService;
|
import io.github.js0ny.ilp_coursework.service.GpsCalculationService;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
@ -25,6 +27,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RequestMapping("/api/v1")
|
@RequestMapping("/api/v1")
|
||||||
public class ApiController {
|
public class ApiController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ApiController.class);
|
||||||
|
|
||||||
private final GpsCalculationService gpsService;
|
private final GpsCalculationService gpsService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,6 +49,7 @@ public class ApiController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/uid")
|
@GetMapping("/uid")
|
||||||
public String getUid() {
|
public String getUid() {
|
||||||
|
log.info("GET /api/v1/uid");
|
||||||
return "s2522255";
|
return "s2522255";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,6 +63,7 @@ public class ApiController {
|
||||||
public double getDistance(@RequestBody DistanceRequest request) {
|
public double getDistance(@RequestBody DistanceRequest request) {
|
||||||
LngLat position1 = request.position1();
|
LngLat position1 = request.position1();
|
||||||
LngLat position2 = request.position2();
|
LngLat position2 = request.position2();
|
||||||
|
log.info("POST /api/v1/distanceTo position1={} position2={}", position1, position2);
|
||||||
return gpsService.calculateDistance(position1, position2);
|
return gpsService.calculateDistance(position1, position2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,6 +78,7 @@ public class ApiController {
|
||||||
public boolean getIsCloseTo(@RequestBody DistanceRequest request) {
|
public boolean getIsCloseTo(@RequestBody DistanceRequest request) {
|
||||||
LngLat position1 = request.position1();
|
LngLat position1 = request.position1();
|
||||||
LngLat position2 = request.position2();
|
LngLat position2 = request.position2();
|
||||||
|
log.info("POST /api/v1/isCloseTo position1={} position2={}", position1, position2);
|
||||||
return gpsService.isCloseTo(position1, position2);
|
return gpsService.isCloseTo(position1, position2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,6 +93,7 @@ public class ApiController {
|
||||||
public LngLat getNextPosition(@RequestBody MovementRequest request) {
|
public LngLat getNextPosition(@RequestBody MovementRequest request) {
|
||||||
LngLat start = request.start();
|
LngLat start = request.start();
|
||||||
Angle angle = new Angle(request.angle());
|
Angle angle = new Angle(request.angle());
|
||||||
|
log.info("POST /api/v1/nextPosition start={} angle={}", start, angle);
|
||||||
return gpsService.nextPosition(start, angle);
|
return gpsService.nextPosition(start, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,6 +107,7 @@ public class ApiController {
|
||||||
public boolean getIsInRegion(@RequestBody RegionCheckRequest request) {
|
public boolean getIsInRegion(@RequestBody RegionCheckRequest request) {
|
||||||
LngLat position = request.position();
|
LngLat position = request.position();
|
||||||
Region region = request.region();
|
Region region = request.region();
|
||||||
|
log.info("POST /api/v1/isInRegion position={} region={}", position, region);
|
||||||
return gpsService.checkIsInRegion(position, region);
|
return gpsService.checkIsInRegion(position, region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import io.github.js0ny.ilp_coursework.service.DroneAttrComparatorService;
|
||||||
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
||||||
import io.github.js0ny.ilp_coursework.service.PathFinderService;
|
import io.github.js0ny.ilp_coursework.service.PathFinderService;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
@ -23,6 +25,8 @@ import java.util.List;
|
||||||
@RequestMapping("/api/v1")
|
@RequestMapping("/api/v1")
|
||||||
public class DroneController {
|
public class DroneController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(DroneController.class);
|
||||||
|
|
||||||
private final DroneInfoService droneInfoService;
|
private final DroneInfoService droneInfoService;
|
||||||
private final DroneAttrComparatorService droneAttrComparatorService;
|
private final DroneAttrComparatorService droneAttrComparatorService;
|
||||||
private final PathFinderService pathFinderService;
|
private final PathFinderService pathFinderService;
|
||||||
|
|
@ -55,6 +59,7 @@ public class DroneController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/dronesWithCooling/{state}")
|
@GetMapping("/dronesWithCooling/{state}")
|
||||||
public List<String> getDronesWithCoolingCapability(@PathVariable boolean state) {
|
public List<String> getDronesWithCoolingCapability(@PathVariable boolean state) {
|
||||||
|
log.info("GET /api/v1/dronesWithCooling/{}", state);
|
||||||
return droneInfoService.dronesWithCooling(state);
|
return droneInfoService.dronesWithCooling(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,9 +73,11 @@ public class DroneController {
|
||||||
@GetMapping("/droneDetails/{id}")
|
@GetMapping("/droneDetails/{id}")
|
||||||
public ResponseEntity<Drone> getDroneDetail(@PathVariable String id) {
|
public ResponseEntity<Drone> getDroneDetail(@PathVariable String id) {
|
||||||
try {
|
try {
|
||||||
|
log.info("GET /api/v1/droneDetails/{}", id);
|
||||||
Drone drone = droneInfoService.droneDetail(id);
|
Drone drone = droneInfoService.droneDetail(id);
|
||||||
return ResponseEntity.ok(drone);
|
return ResponseEntity.ok(drone);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
|
log.warn("GET /api/v1/droneDetails/{} not found", id);
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,26 +93,35 @@ public class DroneController {
|
||||||
@GetMapping("/queryAsPath/{attrName}/{attrVal}")
|
@GetMapping("/queryAsPath/{attrName}/{attrVal}")
|
||||||
public List<String> getIdByAttrMap(
|
public List<String> getIdByAttrMap(
|
||||||
@PathVariable String attrName, @PathVariable String attrVal) {
|
@PathVariable String attrName, @PathVariable String attrVal) {
|
||||||
|
log.info("GET /api/v1/queryAsPath/{}/{}", attrName, attrVal);
|
||||||
return droneAttrComparatorService.dronesWithAttribute(attrName, attrVal);
|
return droneAttrComparatorService.dronesWithAttribute(attrName, attrVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
public List<String> getIdByAttrMapPost(@RequestBody AttrQueryRequest[] attrComparators) {
|
public List<String> getIdByAttrMapPost(@RequestBody AttrQueryRequest[] attrComparators) {
|
||||||
|
int count = attrComparators == null ? 0 : attrComparators.length;
|
||||||
|
log.info("POST /api/v1/query comparators={}", count);
|
||||||
return droneAttrComparatorService.dronesSatisfyingAttributes(attrComparators);
|
return droneAttrComparatorService.dronesSatisfyingAttributes(attrComparators);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/queryAvailableDrones")
|
@PostMapping("/queryAvailableDrones")
|
||||||
public List<String> queryAvailableDrones(@RequestBody MedDispatchRecRequest[] records) {
|
public List<String> queryAvailableDrones(@RequestBody MedDispatchRecRequest[] records) {
|
||||||
|
int count = records == null ? 0 : records.length;
|
||||||
|
log.info("POST /api/v1/queryAvailableDrones records={}", count);
|
||||||
return droneInfoService.dronesMatchesRequirements(records);
|
return droneInfoService.dronesMatchesRequirements(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/calcDeliveryPath")
|
@PostMapping("/calcDeliveryPath")
|
||||||
public DeliveryPathResponse calculateDeliveryPath(@RequestBody MedDispatchRecRequest[] record) {
|
public DeliveryPathResponse calculateDeliveryPath(@RequestBody MedDispatchRecRequest[] record) {
|
||||||
|
int count = record == null ? 0 : record.length;
|
||||||
|
log.info("POST /api/v1/calcDeliveryPath records={}", count);
|
||||||
return pathFinderService.calculateDeliveryPath(record);
|
return pathFinderService.calculateDeliveryPath(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/calcDeliveryPathAsGeoJson")
|
@PostMapping("/calcDeliveryPathAsGeoJson")
|
||||||
public String calculateDeliveryPathAsGeoJson(@RequestBody MedDispatchRecRequest[] record) {
|
public String calculateDeliveryPathAsGeoJson(@RequestBody MedDispatchRecRequest[] record) {
|
||||||
|
int count = record == null ? 0 : record.length;
|
||||||
|
log.info("POST /api/v1/calcDeliveryPathAsGeoJson records={}", count);
|
||||||
return pathFinderService.calculateDeliveryPathAsGeoJson(record);
|
return pathFinderService.calculateDeliveryPathAsGeoJson(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import io.github.js0ny.ilp_coursework.data.external.RestrictedArea;
|
||||||
import io.github.js0ny.ilp_coursework.data.external.ServicePoint;
|
import io.github.js0ny.ilp_coursework.data.external.ServicePoint;
|
||||||
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -14,6 +16,8 @@ import java.util.List;
|
||||||
@RequestMapping("/api/v1")
|
@RequestMapping("/api/v1")
|
||||||
public class MapMetaController {
|
public class MapMetaController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(MapMetaController.class);
|
||||||
|
|
||||||
private final DroneInfoService droneInfoService;
|
private final DroneInfoService droneInfoService;
|
||||||
|
|
||||||
public MapMetaController(DroneInfoService droneInfoService) {
|
public MapMetaController(DroneInfoService droneInfoService) {
|
||||||
|
|
@ -22,11 +26,13 @@ public class MapMetaController {
|
||||||
|
|
||||||
@GetMapping("/restrictedAreas")
|
@GetMapping("/restrictedAreas")
|
||||||
public List<RestrictedArea> getRestrictedAreas() {
|
public List<RestrictedArea> getRestrictedAreas() {
|
||||||
|
log.info("GET /api/v1/restrictedAreas");
|
||||||
return droneInfoService.fetchRestrictedAreas();
|
return droneInfoService.fetchRestrictedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/servicePoints")
|
@GetMapping("/servicePoints")
|
||||||
public List<ServicePoint> getServicePoints() {
|
public List<ServicePoint> getServicePoints() {
|
||||||
|
log.info("GET /api/v1/servicePoints");
|
||||||
return droneInfoService.fetchServicePoints();
|
return droneInfoService.fetchServicePoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.github.js0ny.ilp_coursework.data.common.DroneEvent;
|
import io.github.js0ny.ilp_coursework.data.common.DroneEvent;
|
||||||
import io.github.js0ny.ilp_coursework.data.response.DeliveryPathResponse;
|
import io.github.js0ny.ilp_coursework.data.response.DeliveryPathResponse;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
|
|
@ -15,6 +17,8 @@ import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TelemetryService {
|
public class TelemetryService {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TelemetryService.class);
|
||||||
|
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
|
@ -56,7 +60,7 @@ public class TelemetryService {
|
||||||
() -> {
|
() -> {
|
||||||
try {
|
try {
|
||||||
String json = mapper.writeValueAsString(event);
|
String json = mapper.writeValueAsString(event);
|
||||||
System.out.println("[INFO] Sending telemetry event: " + json);
|
log.debug("Sending telemetry event: {}", json);
|
||||||
var request =
|
var request =
|
||||||
java.net.http.HttpRequest.newBuilder()
|
java.net.http.HttpRequest.newBuilder()
|
||||||
.uri(java.net.URI.create(BLACKBOX_URL + "/ingest"))
|
.uri(java.net.URI.create(BLACKBOX_URL + "/ingest"))
|
||||||
|
|
@ -68,8 +72,7 @@ public class TelemetryService {
|
||||||
|
|
||||||
client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
|
client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(
|
log.error("Failed to send telemetry event: {}", e.getMessage());
|
||||||
"[ERROR] Failed to send telemetry event: " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue