mirror of https://github.com/apache/druid.git
Add an api to get all lookup specs (#7025)
* Add an api to get all lookup specs * add doc
This commit is contained in:
parent
c9f21bc782
commit
d42de574d6
|
@ -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.
|
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
|
## 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
|
Using the prior example, a `GET` to `/druid/coordinator/v1/lookups/config/realtime_customer2/site_id_customer2` should return
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,8 @@ public class LookupCoordinatorResource
|
||||||
if (discover) {
|
if (discover) {
|
||||||
return Response.ok().entity(lookupCoordinatorManager.discoverTiers()).build();
|
return Response.ok().entity(lookupCoordinatorManager.discoverTiers()).build();
|
||||||
}
|
}
|
||||||
final Map<String, Map<String, LookupExtractorFactoryMapContainer>> knownLookups = lookupCoordinatorManager.getKnownLookups();
|
final Map<String, Map<String, LookupExtractorFactoryMapContainer>> knownLookups = lookupCoordinatorManager
|
||||||
|
.getKnownLookups();
|
||||||
if (knownLookups == null) {
|
if (knownLookups == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,6 +114,26 @@ public class LookupCoordinatorResource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
@Path("/config/all")
|
||||||
|
public Response getAllLookupSpecs()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
final Map<String, Map<String, LookupExtractorFactoryMapContainer>> 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
|
@POST
|
||||||
@Path("/config")
|
@Path("/config")
|
||||||
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
|
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
|
||||||
|
@ -314,14 +335,16 @@ public class LookupCoordinatorResource
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager.getKnownLookups();
|
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager
|
||||||
|
.getKnownLookups();
|
||||||
if (configuredLookups == null) {
|
if (configuredLookups == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND)
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity(ServletResourceUtils.jsonize("No lookups found"))
|
.entity(ServletResourceUtils.jsonize("No lookups found"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnNodes = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
|
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnNodes = lookupCoordinatorManager
|
||||||
|
.getLastKnownLookupsStateOnNodes();
|
||||||
|
|
||||||
Map<String, Map<String, LookupStatus>> result = new HashMap<>();
|
Map<String, Map<String, LookupStatus>> result = new HashMap<>();
|
||||||
|
|
||||||
|
@ -362,7 +385,8 @@ public class LookupCoordinatorResource
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager.getKnownLookups();
|
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager
|
||||||
|
.getKnownLookups();
|
||||||
if (configuredLookups == null) {
|
if (configuredLookups == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND)
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity(ServletResourceUtils.jsonize("No lookups found"))
|
.entity(ServletResourceUtils.jsonize("No lookups found"))
|
||||||
|
@ -380,7 +404,8 @@ public class LookupCoordinatorResource
|
||||||
Map<String, LookupStatus> lookupStatusMap = new HashMap<>();
|
Map<String, LookupStatus> lookupStatusMap = new HashMap<>();
|
||||||
Collection<HostAndPort> hosts = lookupCoordinatorManager.discoverNodesInTier(tier);
|
Collection<HostAndPort> hosts = lookupCoordinatorManager.discoverNodesInTier(tier);
|
||||||
|
|
||||||
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnNodes = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
|
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnNodes = lookupCoordinatorManager
|
||||||
|
.getLastKnownLookupsStateOnNodes();
|
||||||
|
|
||||||
for (Map.Entry<String, LookupExtractorFactoryMapContainer> lookupsEntry : tierLookups.entrySet()) {
|
for (Map.Entry<String, LookupExtractorFactoryMapContainer> lookupsEntry : tierLookups.entrySet()) {
|
||||||
lookupStatusMap.put(
|
lookupStatusMap.put(
|
||||||
|
@ -407,7 +432,8 @@ public class LookupCoordinatorResource
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager.getKnownLookups();
|
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager
|
||||||
|
.getKnownLookups();
|
||||||
if (configuredLookups == null) {
|
if (configuredLookups == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND)
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity(ServletResourceUtils.jsonize("No lookups found"))
|
.entity(ServletResourceUtils.jsonize("No lookups found"))
|
||||||
|
@ -486,7 +512,8 @@ public class LookupCoordinatorResource
|
||||||
if (discover) {
|
if (discover) {
|
||||||
tiers = lookupCoordinatorManager.discoverTiers();
|
tiers = lookupCoordinatorManager.discoverTiers();
|
||||||
} else {
|
} else {
|
||||||
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager.getKnownLookups();
|
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager
|
||||||
|
.getKnownLookups();
|
||||||
if (configuredLookups == null) {
|
if (configuredLookups == null) {
|
||||||
return Response.status(Response.Status.NOT_FOUND)
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity(ServletResourceUtils.jsonize("No lookups configured."))
|
.entity(ServletResourceUtils.jsonize("No lookups configured."))
|
||||||
|
@ -495,7 +522,8 @@ public class LookupCoordinatorResource
|
||||||
tiers = configuredLookups.keySet();
|
tiers = configuredLookups.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
|
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager
|
||||||
|
.getLastKnownLookupsStateOnNodes();
|
||||||
|
|
||||||
Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> result = new HashMap<>();
|
Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> result = new HashMap<>();
|
||||||
|
|
||||||
|
@ -531,7 +559,8 @@ public class LookupCoordinatorResource
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
|
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager
|
||||||
|
.getLastKnownLookupsStateOnNodes();
|
||||||
|
|
||||||
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> tierNodesStatus = new HashMap<>();
|
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> tierNodesStatus = new HashMap<>();
|
||||||
|
|
||||||
|
@ -563,7 +592,8 @@ public class LookupCoordinatorResource
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
|
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager
|
||||||
|
.getLastKnownLookupsStateOnNodes();
|
||||||
|
|
||||||
LookupsState<LookupExtractorFactoryMapContainer> lookupsState = lookupsStateOnHosts.get(hostAndPort);
|
LookupsState<LookupExtractorFactoryMapContainer> lookupsState = lookupsStateOnHosts.get(hostAndPort);
|
||||||
if (lookupsState == null) {
|
if (lookupsState == null) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.junit.Test;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -1078,4 +1079,68 @@ public class LookupCoordinatorResourceTest
|
||||||
|
|
||||||
EasyMock.verify(lookupCoordinatorManager);
|
EasyMock.verify(lookupCoordinatorManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllLookupSpecs()
|
||||||
|
{
|
||||||
|
final Map<String, Map<String, LookupExtractorFactoryMapContainer>> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue