From 9bc6436176a39e3d339b088036483c4295a7491d Mon Sep 17 00:00:00 2001 From: fjy Date: Mon, 28 Apr 2014 15:55:03 -0700 Subject: [PATCH] Add more endpoints, fixes #517 --- .../server/http/DatasourcesResource.java | 126 +++++++++--------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/server/src/main/java/io/druid/server/http/DatasourcesResource.java b/server/src/main/java/io/druid/server/http/DatasourcesResource.java index ac2b2201237..f99586c1056 100644 --- a/server/src/main/java/io/druid/server/http/DatasourcesResource.java +++ b/server/src/main/java/io/druid/server/http/DatasourcesResource.java @@ -59,14 +59,6 @@ import java.util.TreeSet; @Path("/druid/coordinator/v1/datasources") public class DatasourcesResource { - private static Map makeSimpleDatasource(DruidDataSource input) - { - return new ImmutableMap.Builder() - .put("name", input.getName()) - .put("properties", input.getProperties()) - .build(); - } - private final InventoryView serverInventoryView; private final DatabaseSegmentManager databaseSegmentManager; private final IndexingServiceClient indexingServiceClient; @@ -145,58 +137,7 @@ public class DatasourcesResource return Response.ok(dataSource).build(); } - Map tiers = Maps.newHashMap(); - Map segments = Maps.newHashMap(); - Map> retVal = ImmutableMap.of( - "tiers", tiers, - "segments", segments - ); - - int totalSegmentCount = 0; - long totalSegmentSize = 0; - long minTime = Long.MAX_VALUE; - long maxTime = Long.MIN_VALUE; - for (DruidServer druidServer : serverInventoryView.getInventory()) { - DruidDataSource druidDataSource = druidServer.getDataSource(dataSourceName); - - if (druidDataSource == null) { - continue; - } - - long dataSourceSegmentSize = 0; - for (DataSegment dataSegment : druidDataSource.getSegments()) { - dataSourceSegmentSize += dataSegment.getSize(); - if (dataSegment.getInterval().getStartMillis() < minTime) { - minTime = dataSegment.getInterval().getStartMillis(); - } - if (dataSegment.getInterval().getEndMillis() > maxTime) { - maxTime = dataSegment.getInterval().getEndMillis(); - } - } - - // segment stats - totalSegmentCount += druidDataSource.getSegments().size(); - totalSegmentSize += dataSourceSegmentSize; - - // tier stats - Map tierStats = (Map) tiers.get(druidServer.getTier()); - if (tierStats == null) { - tierStats = Maps.newHashMap(); - tiers.put(druidServer.getTier(), tierStats); - } - int segmentCount = MapUtils.getInt(tierStats, "segmentCount", 0); - tierStats.put("segmentCount", segmentCount + druidDataSource.getSegments().size()); - - long segmentSize = MapUtils.getLong(tierStats, "size", 0L); - tierStats.put("size", segmentSize + dataSourceSegmentSize); - } - - segments.put("count", totalSegmentCount); - segments.put("size", totalSegmentSize); - segments.put("minTime", new DateTime(minTime)); - segments.put("maxTime", new DateTime(maxTime)); - - return Response.ok(retVal).build(); + return Response.ok(getSimpleDatasource(dataSourceName)).build(); } @POST @@ -281,7 +222,7 @@ public class DatasourcesResource } if (simple != null) { - final Map> retVal = Maps.newHashMap(); + final Map> retVal = Maps.newTreeMap(comparator); for (DataSegment dataSegment : dataSource.getSegments()) { Map properties = retVal.get(dataSegment.getInterval()); if (properties == null) { @@ -570,4 +511,67 @@ public class DatasourcesResource return new Pair<>(theSegment, servers); } + + private Map makeSimpleDatasource(DruidDataSource input) + { + return new ImmutableMap.Builder() + .put("name", input.getName()) + .put("properties", getSimpleDatasource(input.getName())) + .build(); + } + + private Map> getSimpleDatasource(String dataSourceName) + { + Map tiers = Maps.newHashMap(); + Map segments = Maps.newHashMap(); + Map> retVal = ImmutableMap.of( + "tiers", tiers, + "segments", segments + ); + + int totalSegmentCount = 0; + long totalSegmentSize = 0; + long minTime = Long.MAX_VALUE; + long maxTime = Long.MIN_VALUE; + for (DruidServer druidServer : serverInventoryView.getInventory()) { + DruidDataSource druidDataSource = druidServer.getDataSource(dataSourceName); + + if (druidDataSource == null) { + continue; + } + + long dataSourceSegmentSize = 0; + for (DataSegment dataSegment : druidDataSource.getSegments()) { + dataSourceSegmentSize += dataSegment.getSize(); + if (dataSegment.getInterval().getStartMillis() < minTime) { + minTime = dataSegment.getInterval().getStartMillis(); + } + if (dataSegment.getInterval().getEndMillis() > maxTime) { + maxTime = dataSegment.getInterval().getEndMillis(); + } + } + + // segment stats + totalSegmentCount += druidDataSource.getSegments().size(); + totalSegmentSize += dataSourceSegmentSize; + + // tier stats + Map tierStats = (Map) tiers.get(druidServer.getTier()); + if (tierStats == null) { + tierStats = Maps.newHashMap(); + tiers.put(druidServer.getTier(), tierStats); + } + int segmentCount = MapUtils.getInt(tierStats, "segmentCount", 0); + tierStats.put("segmentCount", segmentCount + druidDataSource.getSegments().size()); + + long segmentSize = MapUtils.getLong(tierStats, "size", 0L); + tierStats.put("size", segmentSize + dataSourceSegmentSize); + } + + segments.put("count", totalSegmentCount); + segments.put("size", totalSegmentSize); + segments.put("minTime", new DateTime(minTime)); + segments.put("maxTime", new DateTime(maxTime)); + return retVal; + } }