use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.
the class LookupCoordinatorResource method createOrUpdateLookup.
@POST
@Produces({ MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE })
@Path("/config/{tier}/{lookup}")
public Response createOrUpdateLookup(@PathParam("tier") String tier, @PathParam("lookup") String lookup, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, InputStream in, @Context HttpServletRequest req) {
try {
if (Strings.isNullOrEmpty(tier)) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(new NullPointerException("`tier` required"))).build();
}
if (Strings.isNullOrEmpty(lookup)) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(new IAE("`lookup` required"))).build();
}
final boolean isSmile = SmileMediaTypes.APPLICATION_JACKSON_SMILE.equals(req.getContentType());
final ObjectMapper mapper = isSmile ? smileMapper : jsonMapper;
final LookupExtractorFactoryMapContainer lookupSpec;
try {
lookupSpec = mapper.readValue(in, LookupExtractorFactoryMapContainer.class);
} catch (IOException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(e)).build();
}
if (lookupCoordinatorManager.updateLookup(tier, lookup, lookupSpec, new AuditInfo(author, comment, req.getRemoteAddr()))) {
return Response.status(Response.Status.ACCEPTED).build();
} else {
throw new RuntimeException("Unknown error updating configuration");
}
} catch (Exception e) {
LOG.error(e, "Error updating tier [%s] lookup [%s]", tier, lookup);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.
the class LookupCoordinatorResource method getSpecificTier.
@GET
@Produces({ MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE })
@Path("/config/{tier}")
public Response getSpecificTier(@PathParam("tier") String tier, @DefaultValue("false") @QueryParam("detailed") boolean detailed) {
try {
if (Strings.isNullOrEmpty(tier)) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(new NullPointerException("`tier` required"))).build();
}
final Map<String, Map<String, LookupExtractorFactoryMapContainer>> map = lookupCoordinatorManager.getKnownLookups();
if (map == null) {
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(new RE("No lookups found"))).build();
}
final Map<String, LookupExtractorFactoryMapContainer> tierLookups = map.get(tier);
if (tierLookups == null) {
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(new RE("Tier [%s] not found", tier))).build();
}
if (detailed) {
return Response.ok().entity(tierLookups).build();
} else {
return Response.ok().entity(tierLookups.keySet()).build();
}
} catch (Exception e) {
LOG.error(e, "Error getting tier [%s]", tier);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.
the class LookupCoordinatorResource method getDetailedAllNodeStatus.
/**
* Build 'detailed' lookup cluster status, broken down by tier, host, and then the full {@link LookupsState} with
* complete {@link LookupExtractorFactoryMapContainer} information.
*/
private Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> getDetailedAllNodeStatus(Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts, Collection<String> tiers) {
Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> result = new HashMap<>();
for (String tier : tiers) {
Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> tierNodesStatus = new HashMap<>();
result.put(tier, tierNodesStatus);
Collection<HostAndPort> nodes = lookupCoordinatorManager.discoverNodesInTier(tier);
for (HostAndPort node : nodes) {
LookupsState<LookupExtractorFactoryMapContainer> lookupsState = lookupsStateOnHosts.get(node);
if (lookupsState == null) {
tierNodesStatus.put(node, new LookupsState<>(null, null, null));
} else {
tierNodesStatus.put(node, lookupsState);
}
}
}
return result;
}
use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.
the class LookupCoordinatorResource method getSpecificLookupStatus.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/status/{tier}/{lookup}")
public Response getSpecificLookupStatus(@PathParam("tier") String tier, @PathParam("lookup") String lookup, @QueryParam("detailed") boolean detailed) {
try {
Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager.getKnownLookups();
if (configuredLookups == null) {
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.jsonize("No lookups found")).build();
}
Map<String, LookupExtractorFactoryMapContainer> tierLookups = configuredLookups.get(tier);
if (tierLookups == null) {
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.jsonize("No lookups found for tier [%s].", tier)).build();
}
LookupExtractorFactoryMapContainer lookupDef = tierLookups.get(lookup);
if (lookupDef == null) {
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.jsonize("Lookup [%s] not found for tier [%s].", lookup, tier)).build();
}
return Response.ok(getLookupStatus(lookup, lookupDef, lookupCoordinatorManager.discoverNodesInTier(tier), lookupCoordinatorManager.getLastKnownLookupsStateOnNodes(), detailed)).build();
} catch (Exception ex) {
LOG.error(ex, "Error getting lookups status for tier [%s] and lookup [%s].", tier, lookup);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(ex)).build();
}
}
use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.
the class LookupCoordinatorResourceTest method testSimpleGetLookup.
@Test
public void testSimpleGetLookup() {
final LookupExtractorFactoryMapContainer container = new LookupExtractorFactoryMapContainer("v0", new HashMap<>());
final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
EasyMock.expect(lookupCoordinatorManager.getLookup(EasyMock.eq(LOOKUP_TIER), EasyMock.eq(LOOKUP_NAME))).andReturn(container).once();
EasyMock.replay(lookupCoordinatorManager);
final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, MAPPER, MAPPER);
final Response response = lookupCoordinatorResource.getSpecificLookup(LOOKUP_TIER, LOOKUP_NAME);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(container, response.getEntity());
EasyMock.verify(lookupCoordinatorManager);
}
Aggregations