Search in sources :

Example 16 with ImmutableDruidDataSource

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);
}
Also used : ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) DataSegment(org.apache.druid.timeline.DataSegment) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 17 with ImmutableDruidDataSource

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();
}
Also used : ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) DataSegment(org.apache.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with ImmutableDruidDataSource

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();
}
Also used : ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) DataSegment(org.apache.druid.timeline.DataSegment) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Interval(org.joda.time.Interval) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with ImmutableDruidDataSource

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();
    }
}
Also used : ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SegmentId(org.apache.druid.timeline.SegmentId) TreeMap(java.util.TreeMap) DataSegment(org.apache.druid.timeline.DataSegment) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) EnumMap(java.util.EnumMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Object2LongMap(it.unimi.dsi.fastutil.objects.Object2LongMap) TreeMap(java.util.TreeMap) Interval(org.joda.time.Interval)

Example 20 with ImmutableDruidDataSource

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();
}
Also used : Response(javax.ws.rs.core.Response) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) DataSegment(org.apache.druid.timeline.DataSegment) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ImmutableDruidDataSource (org.apache.druid.client.ImmutableDruidDataSource)33 DataSegment (org.apache.druid.timeline.DataSegment)26 Test (org.junit.Test)12 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)10 SegmentId (org.apache.druid.timeline.SegmentId)10 Interval (org.joda.time.Interval)9 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 Produces (javax.ws.rs.Produces)8 HashMap (java.util.HashMap)7 TreeSet (java.util.TreeSet)7 Path (javax.ws.rs.Path)7 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)6 List (java.util.List)6 Response (javax.ws.rs.core.Response)6 DataSourcesSnapshot (org.apache.druid.client.DataSourcesSnapshot)6 Set (java.util.Set)5 DruidDataSource (org.apache.druid.client.DruidDataSource)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4