use of org.graylog.plugins.sidecar.rest.models.SidecarSummary in project graylog2-server by Graylog2.
the class SidecarResource method sidecars.
@GET
@Timed
@ApiOperation(value = "Lists existing Sidecar registrations using pagination")
@RequiresPermissions(SidecarRestPermissions.SIDECARS_READ)
public SidecarListResponse sidecars(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "title,description,name,id") @DefaultValue(Sidecar.FIELD_NODE_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "only_active") @QueryParam("only_active") @DefaultValue("false") boolean onlyActive) {
final String mappedQuery = sidecarStatusMapper.replaceStringStatusSearchQuery(query);
SearchQuery searchQuery;
try {
searchQuery = searchQueryParser.parse(mappedQuery);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final PaginatedList<Sidecar> sidecars = onlyActive ? sidecarService.findPaginated(searchQuery, activeSidecarFilter, page, perPage, sort, order) : sidecarService.findPaginated(searchQuery, page, perPage, sort, order);
final List<SidecarSummary> collectorSummaries = sidecarService.toSummaryList(sidecars, activeSidecarFilter);
final long total = sidecarService.count();
return SidecarListResponse.create(query, sidecars.pagination(), total, onlyActive, sort, order, collectorSummaries);
}
use of org.graylog.plugins.sidecar.rest.models.SidecarSummary in project graylog2-server by Graylog2.
the class AdministrationResource method administration.
@POST
@Timed
@ApiOperation(value = "Lists existing Sidecar registrations including compatible sidecars using pagination")
@RequiresPermissions({ SidecarRestPermissions.SIDECARS_READ, SidecarRestPermissions.COLLECTORS_READ, SidecarRestPermissions.CONFIGURATIONS_READ })
@NoAuditEvent("this is not changing any data")
public SidecarListResponse administration(@ApiParam(name = "JSON body", required = true) @Valid @NotNull AdministrationRequest request) {
final String sort = Sidecar.FIELD_NODE_NAME;
final String order = "asc";
final String mappedQuery = sidecarStatusMapper.replaceStringStatusSearchQuery(request.query());
SearchQuery searchQuery;
try {
searchQuery = searchQueryParser.parse(mappedQuery);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
}
final long total = sidecarService.count();
final Optional<Predicate<Sidecar>> filters = administrationFiltersFactory.getFilters(request.filters());
final List<Collector> collectors = getCollectors(request.filters());
final PaginatedList<Sidecar> sidecars = sidecarService.findPaginated(searchQuery, filters.orElse(null), request.page(), request.perPage(), sort, order);
final List<SidecarSummary> sidecarSummaries = sidecarService.toSummaryList(sidecars, activeSidecarFilter);
final List<SidecarSummary> summariesWithCollectors = sidecarSummaries.stream().map(collector -> {
final List<String> compatibleCollectors = collectors.stream().filter(c -> c.nodeOperatingSystem().equalsIgnoreCase(collector.nodeDetails().operatingSystem())).map(Collector::id).collect(Collectors.toList());
return collector.toBuilder().collectors(compatibleCollectors).build();
}).filter(collectorSummary -> !filters.isPresent() || collectorSummary.collectors().size() > 0).collect(Collectors.toList());
return SidecarListResponse.create(request.query(), sidecars.pagination(), total, false, sort, order, summariesWithCollectors, request.filters());
}
use of org.graylog.plugins.sidecar.rest.models.SidecarSummary in project graylog2-server by Graylog2.
the class SidecarResourceTest method testGetNotExisting.
@Test(expected = NotFoundException.class)
public void testGetNotExisting() throws Exception {
final SidecarSummary response = this.resource.get("Nonexisting");
assertNull(response);
}
use of org.graylog.plugins.sidecar.rest.models.SidecarSummary in project graylog2-server by Graylog2.
the class SidecarResourceTest method testGet.
@Test
public void testGet() throws Exception {
final Sidecar sidecar = sidecars.get(sidecars.size() - 1);
when(sidecarService.findByNodeId(sidecar.nodeId())).thenReturn(sidecar);
final SidecarSummary sidecarSummary = mock(SidecarSummary.class);
when(sidecar.toSummary(any(ActiveSidecarFilter.class))).thenReturn(sidecarSummary);
final SidecarSummary response = this.resource.get(sidecar.nodeId());
assertNotNull(response);
assertEquals(sidecarSummary, response);
}
Aggregations