diff --git a/docs/content/querying/lookups.md b/docs/content/querying/lookups.md index 7c7ad81df2f..14d9fe2813c 100644 --- a/docs/content/querying/lookups.md +++ b/docs/content/querying/lookups.md @@ -260,8 +260,11 @@ For example, a post to `/druid/coordinator/v1/lookups/config/realtime_customer1/ This will replace the `site_id_customer1` lookup in the `realtime_customer1` with the definition above. +## Get All Lookups +A `GET` to `/druid/coordinator/v1/lookups/config/all` will return all known lookup specs for all tiers. + ## Get Lookup -A `GET` to a particular lookup extractor factory is accomplished via `/druid/coordinator/v1/lookups/{tier}/{id}` +A `GET` to a particular lookup extractor factory is accomplished via `/druid/coordinator/v1/lookups/config/{tier}/{id}` Using the prior example, a `GET` to `/druid/coordinator/v1/lookups/config/realtime_customer2/site_id_customer2` should return diff --git a/server/src/main/java/org/apache/druid/server/http/LookupCoordinatorResource.java b/server/src/main/java/org/apache/druid/server/http/LookupCoordinatorResource.java index 90e56941ce7..b79acea7161 100644 --- a/server/src/main/java/org/apache/druid/server/http/LookupCoordinatorResource.java +++ b/server/src/main/java/org/apache/druid/server/http/LookupCoordinatorResource.java @@ -100,7 +100,8 @@ public class LookupCoordinatorResource if (discover) { return Response.ok().entity(lookupCoordinatorManager.discoverTiers()).build(); } - final Map> knownLookups = lookupCoordinatorManager.getKnownLookups(); + final Map> knownLookups = lookupCoordinatorManager + .getKnownLookups(); if (knownLookups == null) { return Response.status(Response.Status.NOT_FOUND).build(); } else { @@ -113,6 +114,26 @@ public class LookupCoordinatorResource } } + @GET + @Produces({MediaType.APPLICATION_JSON}) + @Path("/config/all") + public Response getAllLookupSpecs() + { + try { + final Map> knownLookups = lookupCoordinatorManager + .getKnownLookups(); + if (knownLookups == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } else { + return Response.ok().entity(knownLookups).build(); + } + } + catch (Exception ex) { + LOG.error(ex, "Error getting lookups status"); + return Response.serverError().entity(ServletResourceUtils.sanitizeException(ex)).build(); + } + } + @POST @Path("/config") @Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE}) @@ -314,14 +335,16 @@ public class LookupCoordinatorResource ) { try { - Map> configuredLookups = lookupCoordinatorManager.getKnownLookups(); + Map> configuredLookups = lookupCoordinatorManager + .getKnownLookups(); if (configuredLookups == null) { return Response.status(Response.Status.NOT_FOUND) .entity(ServletResourceUtils.jsonize("No lookups found")) .build(); } - Map> lookupsStateOnNodes = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes(); + Map> lookupsStateOnNodes = lookupCoordinatorManager + .getLastKnownLookupsStateOnNodes(); Map> result = new HashMap<>(); @@ -362,7 +385,8 @@ public class LookupCoordinatorResource ) { try { - Map> configuredLookups = lookupCoordinatorManager.getKnownLookups(); + Map> configuredLookups = lookupCoordinatorManager + .getKnownLookups(); if (configuredLookups == null) { return Response.status(Response.Status.NOT_FOUND) .entity(ServletResourceUtils.jsonize("No lookups found")) @@ -380,7 +404,8 @@ public class LookupCoordinatorResource Map lookupStatusMap = new HashMap<>(); Collection hosts = lookupCoordinatorManager.discoverNodesInTier(tier); - Map> lookupsStateOnNodes = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes(); + Map> lookupsStateOnNodes = lookupCoordinatorManager + .getLastKnownLookupsStateOnNodes(); for (Map.Entry lookupsEntry : tierLookups.entrySet()) { lookupStatusMap.put( @@ -407,7 +432,8 @@ public class LookupCoordinatorResource ) { try { - Map> configuredLookups = lookupCoordinatorManager.getKnownLookups(); + Map> configuredLookups = lookupCoordinatorManager + .getKnownLookups(); if (configuredLookups == null) { return Response.status(Response.Status.NOT_FOUND) .entity(ServletResourceUtils.jsonize("No lookups found")) @@ -486,7 +512,8 @@ public class LookupCoordinatorResource if (discover) { tiers = lookupCoordinatorManager.discoverTiers(); } else { - Map> configuredLookups = lookupCoordinatorManager.getKnownLookups(); + Map> configuredLookups = lookupCoordinatorManager + .getKnownLookups(); if (configuredLookups == null) { return Response.status(Response.Status.NOT_FOUND) .entity(ServletResourceUtils.jsonize("No lookups configured.")) @@ -495,7 +522,8 @@ public class LookupCoordinatorResource tiers = configuredLookups.keySet(); } - Map> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes(); + Map> lookupsStateOnHosts = lookupCoordinatorManager + .getLastKnownLookupsStateOnNodes(); Map>> result = new HashMap<>(); @@ -531,7 +559,8 @@ public class LookupCoordinatorResource ) { try { - Map> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes(); + Map> lookupsStateOnHosts = lookupCoordinatorManager + .getLastKnownLookupsStateOnNodes(); Map> tierNodesStatus = new HashMap<>(); @@ -563,7 +592,8 @@ public class LookupCoordinatorResource ) { try { - Map> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes(); + Map> lookupsStateOnHosts = lookupCoordinatorManager + .getLastKnownLookupsStateOnNodes(); LookupsState lookupsState = lookupsStateOnHosts.get(hostAndPort); if (lookupsState == null) { diff --git a/server/src/test/java/org/apache/druid/server/http/LookupCoordinatorResourceTest.java b/server/src/test/java/org/apache/druid/server/http/LookupCoordinatorResourceTest.java index 621479b8a2e..17f3d46e11e 100644 --- a/server/src/test/java/org/apache/druid/server/http/LookupCoordinatorResourceTest.java +++ b/server/src/test/java/org/apache/druid/server/http/LookupCoordinatorResourceTest.java @@ -39,6 +39,7 @@ import org.junit.Test; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -1078,4 +1079,68 @@ public class LookupCoordinatorResourceTest EasyMock.verify(lookupCoordinatorManager); } + + @Test + public void testGetAllLookupSpecs() + { + final Map> lookups = ImmutableMap.of( + "tier1", + ImmutableMap.of( + "lookup1", + new LookupExtractorFactoryMapContainer( + "v0", + ImmutableMap.of("k1", "v2") + ), + "lookup2", + new LookupExtractorFactoryMapContainer( + "v1", + ImmutableMap.of("k", "v") + ) + ), + "tier2", + ImmutableMap.of( + "lookup1", + new LookupExtractorFactoryMapContainer( + "v0", + ImmutableMap.of("k1", "v2") + ) + ) + ); + final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock( + LookupCoordinatorManager.class + ); + EasyMock.expect(lookupCoordinatorManager.getKnownLookups()) + .andReturn(lookups) + .once(); + EasyMock.replay(lookupCoordinatorManager); + final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource( + lookupCoordinatorManager, + mapper, + mapper + ); + final Response response = lookupCoordinatorResource.getAllLookupSpecs(); + Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus()); + Assert.assertEquals(lookups, response.getEntity()); + EasyMock.verify(lookupCoordinatorManager); + } + + @Test + public void testGetEmptyAllLookupSpecs() + { + final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock( + LookupCoordinatorManager.class + ); + EasyMock.expect(lookupCoordinatorManager.getKnownLookups()) + .andReturn(null) + .once(); + EasyMock.replay(lookupCoordinatorManager); + final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource( + lookupCoordinatorManager, + mapper, + mapper + ); + final Response response = lookupCoordinatorResource.getAllLookupSpecs(); + Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); + EasyMock.verify(lookupCoordinatorManager); + } }