Search in sources :

Example 1 with ResourceFilters

use of com.sun.jersey.spi.container.ResourceFilters in project druid by druid-io.

the class ClientInfoResource method getDatasourceMetrics.

@GET
@Path("/{dataSourceName}/metrics")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Iterable<String> getDatasourceMetrics(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval) {
    final List<DataSegment> segments = getSegmentsForDatasources().get(dataSourceName);
    final Set<String> metrics = Sets.newHashSet();
    if (segments == null || segments.isEmpty()) {
        return metrics;
    }
    Interval theInterval;
    if (interval == null || interval.isEmpty()) {
        DateTime now = getCurrentTime();
        theInterval = new Interval(segmentMetadataQueryConfig.getDefaultHistory(), now);
    } else {
        theInterval = new Interval(interval);
    }
    for (DataSegment segment : segments) {
        if (theInterval.overlaps(segment.getInterval())) {
            metrics.addAll(segment.getMetrics());
        }
    }
    return metrics;
}
Also used : DataSegment(io.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ResourceFilters

use of com.sun.jersey.spi.container.ResourceFilters in project druid by druid-io.

the class DatasourcesResource method getSegmentDataSourceSpecificInterval.

/**
   * Provides serverView for a datasource and Interval which gives details about servers hosting segments for an interval
   * Used by the realtime tasks to fetch a view of the interval they are interested in.
   */
@GET
@Path("/{dataSourceName}/intervals/{interval}/serverview")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Response getSegmentDataSourceSpecificInterval(@PathParam("dataSourceName") String dataSourceName, @PathParam("interval") String interval, @QueryParam("partial") final boolean partial) {
    TimelineLookup<String, SegmentLoadInfo> timeline = serverInventoryView.getTimeline(new TableDataSource(dataSourceName));
    final Interval theInterval = new Interval(interval.replace("_", "/"));
    if (timeline == null) {
        log.debug("No timeline found for datasource[%s]", dataSourceName);
        return Response.ok(Lists.<ImmutableSegmentLoadInfo>newArrayList()).build();
    }
    Iterable<TimelineObjectHolder<String, SegmentLoadInfo>> lookup = timeline.lookupWithIncompletePartitions(theInterval);
    FunctionalIterable<ImmutableSegmentLoadInfo> retval = FunctionalIterable.create(lookup).transformCat(new Function<TimelineObjectHolder<String, SegmentLoadInfo>, Iterable<ImmutableSegmentLoadInfo>>() {

        @Override
        public Iterable<ImmutableSegmentLoadInfo> apply(TimelineObjectHolder<String, SegmentLoadInfo> input) {
            return Iterables.transform(input.getObject(), new Function<PartitionChunk<SegmentLoadInfo>, ImmutableSegmentLoadInfo>() {

                @Override
                public ImmutableSegmentLoadInfo apply(PartitionChunk<SegmentLoadInfo> chunk) {
                    return chunk.getObject().toImmutableSegmentLoadInfo();
                }
            });
        }
    });
    return Response.ok(retval).build();
}
Also used : FunctionalIterable(io.druid.java.util.common.guava.FunctionalIterable) ImmutableSegmentLoadInfo(io.druid.client.ImmutableSegmentLoadInfo) SegmentLoadInfo(io.druid.client.SegmentLoadInfo) Function(com.google.common.base.Function) TimelineObjectHolder(io.druid.timeline.TimelineObjectHolder) TableDataSource(io.druid.query.TableDataSource) ImmutableSegmentLoadInfo(io.druid.client.ImmutableSegmentLoadInfo) PartitionChunk(io.druid.timeline.partition.PartitionChunk) Interval(org.joda.time.Interval) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ResourceFilters

use of com.sun.jersey.spi.container.ResourceFilters in project druid by druid-io.

the class DatasourcesResource method getSegmentDataSourceIntervals.

@GET
@Path("/{dataSourceName}/intervals")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Response getSegmentDataSourceIntervals(@PathParam("dataSourceName") String dataSourceName, @QueryParam("simple") String simple, @QueryParam("full") String full) {
    final DruidDataSource dataSource = getDataSource(dataSourceName);
    if (dataSource == null) {
        return Response.noContent().build();
    }
    final Comparator<Interval> comparator = Comparators.inverse(Comparators.intervalsByStartThenEnd());
    if (full != null) {
        final Map<Interval, Map<String, Object>> retVal = Maps.newTreeMap(comparator);
        for (DataSegment dataSegment : dataSource.getSegments()) {
            Map<String, Object> segments = retVal.get(dataSegment.getInterval());
            if (segments == null) {
                segments = Maps.newHashMap();
                retVal.put(dataSegment.getInterval(), segments);
            }
            Pair<DataSegment, Set<String>> val = getSegment(dataSegment.getIdentifier());
            segments.put(dataSegment.getIdentifier(), ImmutableMap.of("metadata", val.lhs, "servers", val.rhs));
        }
        return Response.ok(retVal).build();
    }
    if (simple != null) {
        final Map<Interval, Map<String, Object>> retVal = Maps.newTreeMap(comparator);
        for (DataSegment dataSegment : dataSource.getSegments()) {
            Map<String, Object> properties = retVal.get(dataSegment.getInterval());
            if (properties == null) {
                properties = Maps.newHashMap();
                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 Set<Interval> intervals = Sets.newTreeSet(comparator);
    for (DataSegment dataSegment : dataSource.getSegments()) {
        intervals.add(dataSegment.getInterval());
    }
    return Response.ok(intervals).build();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DruidDataSource(io.druid.client.DruidDataSource) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ResourceFilters

use of com.sun.jersey.spi.container.ResourceFilters in project druid by druid-io.

the class DatasourcesResource method getSegmentDataSourceSegments.

@GET
@Path("/{dataSourceName}/segments")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Response getSegmentDataSourceSegments(@PathParam("dataSourceName") String dataSourceName, @QueryParam("full") String full) {
    DruidDataSource dataSource = getDataSource(dataSourceName);
    if (dataSource == null) {
        return Response.noContent().build();
    }
    Response.ResponseBuilder builder = Response.ok();
    if (full != null) {
        return builder.entity(dataSource.getSegments()).build();
    }
    return builder.entity(Iterables.transform(dataSource.getSegments(), new Function<DataSegment, Object>() {

        @Override
        public Object apply(DataSegment segment) {
            return segment.getIdentifier();
        }
    })).build();
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(io.druid.client.DruidDataSource) DataSegment(io.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)

Example 5 with ResourceFilters

use of com.sun.jersey.spi.container.ResourceFilters in project druid by druid-io.

the class MetadataResource method getDatabaseSegmentDataSourceSegments.

@GET
@Path("/datasources/{dataSourceName}/segments")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(DatasourceResourceFilter.class)
public Response getDatabaseSegmentDataSourceSegments(@PathParam("dataSourceName") String dataSourceName, @QueryParam("full") String full) {
    DruidDataSource dataSource = metadataSegmentManager.getInventoryValue(dataSourceName);
    if (dataSource == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    Response.ResponseBuilder builder = Response.status(Response.Status.OK);
    if (full != null) {
        return builder.entity(dataSource.getSegments()).build();
    }
    return builder.entity(Iterables.transform(dataSource.getSegments(), new Function<DataSegment, String>() {

        @Override
        public String apply(DataSegment segment) {
            return segment.getIdentifier();
        }
    })).build();
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(io.druid.client.DruidDataSource) DataSegment(io.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

ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)12 Path (javax.ws.rs.Path)12 GET (javax.ws.rs.GET)11 Produces (javax.ws.rs.Produces)11 DataSegment (io.druid.timeline.DataSegment)8 Interval (org.joda.time.Interval)6 DruidDataSource (io.druid.client.DruidDataSource)5 Set (java.util.Set)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 DateTime (org.joda.time.DateTime)3 Function (com.google.common.base.Function)2 Worker (io.druid.indexing.worker.Worker)2 TableDataSource (io.druid.query.TableDataSource)2 TimelineObjectHolder (io.druid.timeline.TimelineObjectHolder)2 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)2 Response (javax.ws.rs.core.Response)2 Predicate (com.google.common.base.Predicate)1