| 1 | package edu.ucsb.cs156.diningcachingproxy.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.diningcachingproxy.services.HostCount; | |
| 4 | import edu.ucsb.cs156.diningcachingproxy.services.HostTrackingService; | |
| 5 | import edu.ucsb.cs156.diningcachingproxy.services.PathCount; | |
| 6 | import edu.ucsb.cs156.diningcachingproxy.services.ResolveHostnameJobFactory; | |
| 7 | import edu.ucsb.cs156.jobs.entities.Job; | |
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import java.util.LinkedHashMap; | |
| 12 | import java.util.List; | |
| 13 | import java.util.Map; | |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestParam; | |
| 20 | import org.springframework.web.bind.annotation.RestController; | |
| 21 | ||
| 22 | /** Lets an admin see every host that has sent requests through the proxy, with a count for each. */ | |
| 23 | @Tag(name = "Admin - Requesting Hosts") | |
| 24 | @RequestMapping("/api/admin/hosts") | |
| 25 | @RestController | |
| 26 | public class HostTrackingController { | |
| 27 | ||
| 28 | @Autowired private HostTrackingService hostTrackingService; | |
| 29 | @Autowired private ResolveHostnameJobFactory resolveHostnameJobFactory; | |
| 30 | ||
| 31 | @Operation(summary = "List all hosts that have sent requests through the proxy, with counts") | |
| 32 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 33 | @GetMapping("") | |
| 34 | public List<HostCount> allHosts() { | |
| 35 |
1
1. allHosts : replaced return value with Collections.emptyList for edu/ucsb/cs156/diningcachingproxy/controller/HostTrackingController::allHosts → KILLED |
return hostTrackingService.getHostCounts(); |
| 36 | } | |
| 37 | ||
| 38 | @Operation( | |
| 39 | summary = "Request counts for each host, broken down by request path", | |
| 40 | description = | |
| 41 | "Returns a JSON object keyed by host (hostname if resolved, else IP address). Each value" | |
| 42 | + " is an object mapping a request path to how many times that host has requested" | |
| 43 | + " it.") | |
| 44 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 45 | @GetMapping("/paths") | |
| 46 | public Map<String, Map<String, Long>> requestCountsByHostAndPath() { | |
| 47 | Map<String, Map<String, Long>> result = new LinkedHashMap<>(); | |
| 48 | for (HostCount hostCount : hostTrackingService.getHostCounts()) { | |
| 49 | Map<String, Long> paths = | |
| 50 |
1
1. lambda$requestCountsByHostAndPath$0 : replaced return value with Collections.emptyMap for edu/ucsb/cs156/diningcachingproxy/controller/HostTrackingController::lambda$requestCountsByHostAndPath$0 → KILLED |
result.computeIfAbsent(hostCount.host(), host -> new LinkedHashMap<>()); |
| 51 | for (PathCount pathCount : hostCount.pathCounts()) { | |
| 52 | paths.merge(pathCount.path(), pathCount.count(), Long::sum); | |
| 53 | } | |
| 54 | } | |
| 55 |
1
1. requestCountsByHostAndPath : replaced return value with Collections.emptyMap for edu/ucsb/cs156/diningcachingproxy/controller/HostTrackingController::requestCountsByHostAndPath → KILLED |
return result; |
| 56 | } | |
| 57 | ||
| 58 | @Operation(summary = "Retry hostname resolution for one IP address") | |
| 59 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 60 | @PostMapping("/resolve") | |
| 61 | public Job resolveHostname(@Parameter(name = "ip") @RequestParam String ip) { | |
| 62 |
1
1. resolveHostname : replaced return value with null for edu/ucsb/cs156/diningcachingproxy/controller/HostTrackingController::resolveHostname → KILLED |
return resolveHostnameJobFactory.launch(ip); |
| 63 | } | |
| 64 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 50 |
1.1 |
|
| 55 |
1.1 |
|
| 62 |
1.1 |