use of org.apache.druid.client.DruidServer in project druid by druid-io.
the class TiersResource method getTiers.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTiers(@QueryParam("simple") String simple) {
Response.ResponseBuilder builder = Response.status(Response.Status.OK);
if (simple != null) {
Map<String, Map<TierMetadataKeys, Long>> metadata = new HashMap<>();
for (DruidServer druidServer : serverInventoryView.getInventory()) {
Map<TierMetadataKeys, Long> tierMetadata = metadata.computeIfAbsent(druidServer.getTier(), tier -> new EnumMap<>(TierMetadataKeys.class));
tierMetadata.merge(TierMetadataKeys.currSize, druidServer.getCurrSize(), Long::sum);
tierMetadata.merge(TierMetadataKeys.maxSize, druidServer.getMaxSize(), Long::sum);
}
return builder.entity(metadata).build();
}
Set<String> tiers = serverInventoryView.getInventory().stream().map(DruidServer::getTier).collect(Collectors.toSet());
return builder.entity(tiers).build();
}
use of org.apache.druid.client.DruidServer in project druid by druid-io.
the class DataSourcesResourceTest method testSimpleGetTheDataSourceManyTiers.
@Test
public void testSimpleGetTheDataSourceManyTiers() {
EasyMock.expect(server.getDataSource("datasource1")).andReturn(listDataSources.get(0)).atLeastOnce();
EasyMock.expect(server.getTier()).andReturn("cold").atLeastOnce();
DruidServer server2 = EasyMock.createStrictMock(DruidServer.class);
EasyMock.expect(server2.getDataSource("datasource1")).andReturn(listDataSources.get(1)).atLeastOnce();
EasyMock.expect(server2.getTier()).andReturn("hot").atLeastOnce();
DruidServer server3 = EasyMock.createStrictMock(DruidServer.class);
EasyMock.expect(server3.getDataSource("datasource1")).andReturn(listDataSources.get(1)).atLeastOnce();
EasyMock.expect(server3.getTier()).andReturn("cold").atLeastOnce();
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server, server2, server3)).atLeastOnce();
EasyMock.replay(inventoryView, server, server2, server3);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, null, null, null, null, null);
Response response = dataSourcesResource.getDataSource("datasource1", null);
Assert.assertEquals(200, response.getStatus());
Map<String, Map<String, Object>> result = (Map<String, Map<String, Object>>) response.getEntity();
Assert.assertEquals(2, ((Map) (result.get("tiers").get("cold"))).get("segmentCount"));
Assert.assertEquals(30L, ((Map) (result.get("tiers").get("cold"))).get("size"));
Assert.assertEquals(30L, ((Map) (result.get("tiers").get("cold"))).get("replicatedSize"));
Assert.assertEquals(1, ((Map) (result.get("tiers").get("hot"))).get("segmentCount"));
Assert.assertEquals(20L, ((Map) (result.get("tiers").get("hot"))).get("size"));
Assert.assertNotNull(result.get("segments"));
Assert.assertEquals("2010-01-01T00:00:00.000Z", result.get("segments").get("minTime").toString());
Assert.assertEquals("2010-01-23T00:00:00.000Z", result.get("segments").get("maxTime").toString());
Assert.assertEquals(2, result.get("segments").get("count"));
Assert.assertEquals(30L, result.get("segments").get("size"));
Assert.assertEquals(50L, result.get("segments").get("replicatedSize"));
EasyMock.verify(inventoryView, server, server2, server3);
}
use of org.apache.druid.client.DruidServer in project druid by druid-io.
the class DataSourcesResourceTest method testGetSegmentDataSourceIntervals.
@Test
public void testGetSegmentDataSourceIntervals() {
server = new DruidServer("who", "host", null, 1234, ServerType.HISTORICAL, "tier1", 0);
server.addDataSegment(dataSegmentList.get(0));
server.addDataSegment(dataSegmentList.get(1));
server.addDataSegment(dataSegmentList.get(2));
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
EasyMock.replay(inventoryView);
List<Interval> expectedIntervals = new ArrayList<>();
expectedIntervals.add(Intervals.of("2010-01-22T00:00:00.000Z/2010-01-23T00:00:00.000Z"));
expectedIntervals.add(Intervals.of("2010-01-01T00:00:00.000Z/2010-01-02T00:00:00.000Z"));
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, null, null, null, null, null);
Response response = dataSourcesResource.getIntervalsWithServedSegmentsOrAllServedSegmentsPerIntervals("invalidDataSource", null, null);
Assert.assertEquals(response.getEntity(), null);
response = dataSourcesResource.getIntervalsWithServedSegmentsOrAllServedSegmentsPerIntervals("datasource1", null, null);
TreeSet<Interval> actualIntervals = (TreeSet) response.getEntity();
Assert.assertEquals(2, actualIntervals.size());
Assert.assertEquals(expectedIntervals.get(0), actualIntervals.first());
Assert.assertEquals(expectedIntervals.get(1), actualIntervals.last());
response = dataSourcesResource.getIntervalsWithServedSegmentsOrAllServedSegmentsPerIntervals("datasource1", "simple", null);
TreeMap<Interval, Map<DataSourcesResource.SimpleProperties, Object>> results = (TreeMap) response.getEntity();
Assert.assertEquals(2, results.size());
Assert.assertEquals(expectedIntervals.get(0), results.firstKey());
Assert.assertEquals(expectedIntervals.get(1), results.lastKey());
Assert.assertEquals(1, results.firstEntry().getValue().get(DataSourcesResource.SimpleProperties.count));
Assert.assertEquals(1, results.lastEntry().getValue().get(DataSourcesResource.SimpleProperties.count));
response = dataSourcesResource.getIntervalsWithServedSegmentsOrAllServedSegmentsPerIntervals("datasource1", null, "full");
Map<Interval, Map<SegmentId, Object>> results2 = ((Map<Interval, Map<SegmentId, Object>>) response.getEntity());
int i = 1;
for (Map.Entry<Interval, Map<SegmentId, Object>> entry : results2.entrySet()) {
Assert.assertEquals(dataSegmentList.get(i).getInterval(), entry.getKey());
Assert.assertEquals(dataSegmentList.get(i), ((Map<String, Object>) entry.getValue().get(dataSegmentList.get(i).getId())).get("metadata"));
i--;
}
EasyMock.verify(inventoryView);
}
use of org.apache.druid.client.DruidServer in project druid by druid-io.
the class LoadRuleTest method testDrop.
@Test
public void testDrop() {
final LoadQueuePeon mockPeon = createEmptyPeon();
mockPeon.dropSegment(EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall().atLeastOnce();
EasyMock.expect(mockBalancerStrategy.pickServersToDrop(EasyMock.anyObject(), EasyMock.anyObject())).andDelegateTo(balancerStrategy).times(4);
EasyMock.replay(throttler, mockPeon, mockBalancerStrategy);
LoadRule rule = createLoadRule(ImmutableMap.of("hot", 0, DruidServer.DEFAULT_TIER, 0));
final DataSegment segment = createDataSegment("foo");
DruidServer server1 = new DruidServer("serverHot", "hostHot", null, 1000, ServerType.HISTORICAL, "hot", 0);
server1.addDataSegment(segment);
DruidServer server2 = new DruidServer("serverNorm", "hostNorm", null, 1000, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0);
server2.addDataSegment(segment);
DruidServer server3 = new DruidServer("serverNormNotServing", "hostNorm", null, 10, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0);
DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier("hot", new ServerHolder(server1.toImmutableDruidServer(), mockPeon)).addTier(DruidServer.DEFAULT_TIER, new ServerHolder(server2.toImmutableDruidServer(), mockPeon), new ServerHolder(server3.toImmutableDruidServer(), mockPeon)).build();
CoordinatorStats stats = rule.run(null, makeCoordinatorRuntimeParams(druidCluster, segment), segment);
Assert.assertEquals(1L, stats.getTieredStat("droppedCount", "hot"));
Assert.assertEquals(1L, stats.getTieredStat("droppedCount", DruidServer.DEFAULT_TIER));
EasyMock.verify(throttler, mockPeon);
}
use of org.apache.druid.client.DruidServer in project druid by druid-io.
the class ServersResourceTest method setUp.
@Before
public void setUp() {
DruidServer dummyServer = new DruidServer("dummy", "host", null, 1234L, ServerType.HISTORICAL, "tier", 0);
DataSegment segment = DataSegment.builder().dataSource("dataSource").interval(Intervals.of("2016-03-22T14Z/2016-03-22T15Z")).version("v0").size(1L).build();
dummyServer.addDataSegment(segment);
CoordinatorServerView inventoryView = EasyMock.createMock(CoordinatorServerView.class);
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(dummyServer)).anyTimes();
EasyMock.expect(inventoryView.getInventoryValue(dummyServer.getName())).andReturn(dummyServer).anyTimes();
EasyMock.replay(inventoryView);
server = dummyServer;
serversResource = new ServersResource(inventoryView);
}
Aggregations