Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import com.navercorp.pinpoint.service.web.vo.ServiceName;
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.service.AdminService;
import com.navercorp.pinpoint.web.service.AgentListV2Service;
import com.navercorp.pinpoint.web.service.ServiceModelResolver;
import com.navercorp.pinpoint.web.view.tree.AgentIdView;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.Service;
import jakarta.validation.constraints.Min;
Expand All @@ -35,7 +33,6 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -60,16 +57,13 @@ public class AdminController {
private final AdminService adminService;
private final ApplicationFactory applicationFactory;
private final ServiceModelResolver serviceModelResolver;
private final AgentListV2Service agentListV2Service;

public AdminController(AdminService adminService,
ApplicationFactory applicationFactory,
ServiceModelResolver serviceModelResolver,
AgentListV2Service agentListV2Service) {
ServiceModelResolver serviceModelResolver) {
this.adminService = Objects.requireNonNull(adminService, "adminService");
this.applicationFactory = Objects.requireNonNull(applicationFactory, "applicationFactory");
this.serviceModelResolver = Objects.requireNonNull(serviceModelResolver, "serviceModelResolver");
this.agentListV2Service = Objects.requireNonNull(agentListV2Service, "agentListV2Service");
}

@Deprecated
Expand Down Expand Up @@ -184,22 +178,6 @@ public Map<String, List<Application>> getInactiveAgents(
return this.adminService.getInactiveAgents(applicationName, durationDays);
}

@GetMapping(value = "/agents")
public List<AgentIdView> getAgents(
@ServiceParam ServiceName serviceName,
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeCode", required = false) Integer serviceTypeCode,
@RequestParam(value = "serviceTypeName", required = false) String serviceTypeName) {
final Service service = serviceModelResolver.getService(serviceName.getName());
final Application application = getApplication(service, applicationName, serviceTypeCode, serviceTypeName);
if (application.getServiceType().equals(ServiceType.UNDEFINED)) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceType. ServiceType is required");
}
return agentListV2Service.getAllAgentList(service, applicationName, application.getServiceType()).stream()
.map(AgentIdView::of)
.toList();
}

private Application getApplication(Service service, String applicationName, Integer serviceTypeCode, String serviceTypeName) {
if (serviceTypeCode != null) {
return applicationFactory.createApplication(service, applicationName, serviceTypeCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public AgentV2Controller(ServiceTypeRegistryService serviceTypeRegistryService,

@PreAuthorize("@naverPermissionEvaluator.hasInspectorPermission(#serviceName.getName(), #applicationName)")
@GetMapping(value = "/agents", params = {"applicationName", "from", "to"})
public List<AgentIdView> getAgentsV2(
public List<AgentIdView> getAgents(
Comment on lines 68 to +69
@ServiceParam ServiceName serviceName,
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeCode", required = false) Short serviceTypeCode,
@RequestParam(value = "serviceTypeCode", required = false) Integer serviceTypeCode,
@RequestParam(value = "serviceTypeName", required = false) String serviceTypeName,
@RequestParam("from") Timestamp from,
@RequestParam("to") Timestamp to) {
Expand All @@ -79,14 +79,31 @@ public List<AgentIdView> getAgentsV2(
rangeValidator.validate(range);

if (serviceType.equals(ServiceType.UNDEFINED)) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceType. ServiceType is required for v2 table");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceType. ServiceType is required");
}
return agentListV2Service.getActiveAgentList(service, applicationName, serviceType, range).stream()
.map(entry -> AgentIdView.of(entry, range.getTo()))
.toList();
}

private ServiceType findServiceType(Short serviceTypeCode, String serviceTypeName) {
@PreAuthorize("@naverPermissionEvaluator.hasInspectorPermission(#serviceName.getName(), #applicationName)")
@GetMapping(value = "/agents", params = {"applicationName", "!from", "!to"})
public List<AgentIdView> getAgents(
Comment on lines +89 to +91
@ServiceParam ServiceName serviceName,
@RequestParam("applicationName") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeCode", required = false) Integer serviceTypeCode,
@RequestParam(value = "serviceTypeName", required = false) String serviceTypeName) {
final Service service = serviceModelResolver.getService(serviceName.getName());
final ServiceType serviceType = findServiceType(serviceTypeCode, serviceTypeName);
if (serviceType.equals(ServiceType.UNDEFINED)) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceType. ServiceType is required");
}
return agentListV2Service.getAllAgentList(service, applicationName, serviceType).stream()
.map(AgentIdView::of)
.toList();
}

private ServiceType findServiceType(Integer serviceTypeCode, String serviceTypeName) {
if (serviceTypeCode != null) {
return serviceTypeRegistryService.findServiceType(serviceTypeCode);
} else if (serviceTypeName != null) {
Expand Down