use of org.apache.druid.client.ImmutableDruidDataSource in project druid by druid-io.
the class DataSourcesSnapshotBenchmark method iterateUsing_forloops.
@Benchmark
public void iterateUsing_forloops(Blackhole blackhole) {
long totalSize = 0;
for (ImmutableDruidDataSource dataSource : snapshot.getDataSourcesWithAllUsedSegments()) {
for (DataSegment segment : dataSource.getSegments()) {
totalSize += segment.getSize();
}
}
blackhole.consume(totalSize);
}
use of org.apache.druid.client.ImmutableDruidDataSource in project druid by druid-io.
the class IntervalsResource method getIntervals.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntervals(@Context final HttpServletRequest req) {
final Comparator<Interval> comparator = Comparators.intervalsByStartThenEnd().reversed();
final Set<ImmutableDruidDataSource> datasources = InventoryViewUtils.getSecuredDataSources(req, serverInventoryView, authorizerMapper);
final Map<Interval, Map<String, Map<String, Object>>> retVal = new TreeMap<>(comparator);
for (ImmutableDruidDataSource dataSource : datasources) {
for (DataSegment dataSegment : dataSource.getSegments()) {
retVal.computeIfAbsent(dataSegment.getInterval(), i -> new HashMap<>());
setProperties(retVal, dataSource, dataSegment);
}
}
return Response.ok(retVal).build();
}
use of org.apache.druid.client.ImmutableDruidDataSource in project druid by druid-io.
the class IntervalsResource method getSpecificIntervals.
@GET
@Path("/{interval}")
@Produces(MediaType.APPLICATION_JSON)
public Response getSpecificIntervals(@PathParam("interval") String interval, @QueryParam("simple") String simple, @QueryParam("full") String full, @Context final HttpServletRequest req) {
final Interval theInterval = Intervals.of(interval.replace('_', '/'));
final Set<ImmutableDruidDataSource> datasources = InventoryViewUtils.getSecuredDataSources(req, serverInventoryView, authorizerMapper);
final Comparator<Interval> comparator = Comparators.intervalsByStartThenEnd().reversed();
if (full != null) {
final Map<Interval, Map<String, Map<String, Object>>> retVal = new TreeMap<>(comparator);
for (ImmutableDruidDataSource dataSource : datasources) {
for (DataSegment dataSegment : dataSource.getSegments()) {
if (theInterval.contains(dataSegment.getInterval())) {
retVal.computeIfAbsent(dataSegment.getInterval(), k -> new HashMap<>());
setProperties(retVal, dataSource, dataSegment);
}
}
}
return Response.ok(retVal).build();
}
if (simple != null) {
final Map<Interval, Map<String, Object>> retVal = new HashMap<>();
for (ImmutableDruidDataSource dataSource : datasources) {
for (DataSegment dataSegment : dataSource.getSegments()) {
if (theInterval.contains(dataSegment.getInterval())) {
Map<String, Object> properties = retVal.get(dataSegment.getInterval());
if (properties == null) {
properties = new HashMap<>();
properties.put("size", dataSegment.getSize());
properties.put("count", 1);
retVal.put(dataSegment.getInterval(), properties);
} else {
properties.put("size", MapUtils.getLong(properties, "size", 0L) + dataSegment.getSize());
properties.put("count", MapUtils.getInt(properties, "count", 0) + 1);
}
}
}
}
return Response.ok(retVal).build();
}
final Map<String, Object> retVal = new HashMap<>();
for (ImmutableDruidDataSource dataSource : datasources) {
for (DataSegment dataSegment : dataSource.getSegments()) {
if (theInterval.contains(dataSegment.getInterval())) {
retVal.put("size", MapUtils.getLong(retVal, "size", 0L) + dataSegment.getSize());
retVal.put("count", MapUtils.getInt(retVal, "count", 0) + 1);
}
}
}
return Response.ok(retVal).build();
}
use of org.apache.druid.client.ImmutableDruidDataSource in project druid by druid-io.
the class DataSourcesResource method getServedSegmentsInInterval.
private Response getServedSegmentsInInterval(String dataSourceName, boolean full, Predicate<Interval> intervalFilter) {
final ImmutableDruidDataSource dataSource = getDataSource(dataSourceName);
if (dataSource == null) {
return logAndCreateDataSourceNotFoundResponse(dataSourceName);
}
final Comparator<Interval> comparator = Comparators.intervalsByStartThenEnd().reversed();
if (full) {
final Map<Interval, Map<SegmentId, Object>> retVal = new TreeMap<>(comparator);
for (DataSegment dataSegment : dataSource.getSegments()) {
if (intervalFilter.test(dataSegment.getInterval())) {
Map<SegmentId, Object> segments = retVal.computeIfAbsent(dataSegment.getInterval(), i -> new HashMap<>());
Pair<DataSegment, Set<String>> segmentAndServers = getServersWhereSegmentIsServed(dataSegment.getId());
if (segmentAndServers != null) {
segments.put(dataSegment.getId(), ImmutableMap.of("metadata", segmentAndServers.lhs, "servers", segmentAndServers.rhs));
}
}
}
return Response.ok(retVal).build();
} else {
final Map<Interval, Map<SimpleProperties, Object>> statsPerInterval = new TreeMap<>(comparator);
for (DataSegment dataSegment : dataSource.getSegments()) {
if (intervalFilter.test(dataSegment.getInterval())) {
Map<SimpleProperties, Object> properties = statsPerInterval.computeIfAbsent(dataSegment.getInterval(), i -> new EnumMap<>(SimpleProperties.class));
properties.merge(SimpleProperties.size, dataSegment.getSize(), (a, b) -> (Long) a + (Long) b);
properties.merge(SimpleProperties.count, 1, (a, b) -> (Integer) a + (Integer) b);
}
}
return Response.ok(statsPerInterval).build();
}
}
use of org.apache.druid.client.ImmutableDruidDataSource in project druid by druid-io.
the class DataSourcesResource method getAllServedSegments.
@GET
@Path("/{dataSourceName}/segments")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Response getAllServedSegments(@PathParam("dataSourceName") String dataSourceName, @QueryParam("full") String full) {
ImmutableDruidDataSource dataSource = getDataSource(dataSourceName);
if (dataSource == null) {
return logAndCreateDataSourceNotFoundResponse(dataSourceName);
}
Response.ResponseBuilder builder = Response.ok();
if (full != null) {
return builder.entity(dataSource.getSegments()).build();
}
return builder.entity(Iterables.transform(dataSource.getSegments(), DataSegment::getId)).build();
}
Aggregations