Search in sources :

Example 1 with LookupExtractorFactoryMapContainer

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();
    }
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) IOException(java.io.IOException) IAE(org.apache.druid.java.util.common.IAE) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with LookupExtractorFactoryMapContainer

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();
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with LookupExtractorFactoryMapContainer

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;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) HashMap(java.util.HashMap) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) Map(java.util.Map) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer)

Example 4 with LookupExtractorFactoryMapContainer

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();
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with LookupExtractorFactoryMapContainer

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);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(org.apache.druid.server.lookup.cache.LookupCoordinatorManager) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) Test(org.junit.Test)

Aggregations

LookupExtractorFactoryMapContainer (org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer)10 HashMap (java.util.HashMap)6 Map (java.util.Map)6 IOException (java.io.IOException)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 HostAndPort (com.google.common.net.HostAndPort)4 GET (javax.ws.rs.GET)4 Response (javax.ws.rs.core.Response)3 LookupsState (org.apache.druid.query.lookup.LookupsState)3 LookupCoordinatorManager (org.apache.druid.server.lookup.cache.LookupCoordinatorManager)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Nullable (javax.annotation.Nullable)2 POST (javax.ws.rs.POST)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 SmileMediaTypes (com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes)1