Search in sources :

Example 6 with LookupExtractorFactoryMapContainer

use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.

the class CoordinatorResourceTestClient method getLookupLoadStatus.

@Nullable
private Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> getLookupLoadStatus() {
    String url = StringUtils.format("%slookups/nodeStatus", getCoordinatorURL());
    Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> status;
    try {
        StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(url)), responseHandler).get();
        if (response.getStatus().getCode() == HttpResponseStatus.NOT_FOUND.getCode()) {
            return null;
        }
        if (response.getStatus().getCode() != HttpResponseStatus.OK.getCode()) {
            throw new ISE("Error while making request to url[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
        }
        status = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>>>() {
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return status;
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URL(java.net.URL) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) Nullable(javax.annotation.Nullable)

Example 7 with LookupExtractorFactoryMapContainer

use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.

the class LookupCoordinatorResource method getSimpleAllNodeStatus.

/**
 * Build 'simple' lookup cluster status, broken down by tier, host, and then the {@link LookupsState} with
 * the lookup name and version ({@link LookupExtractorFactoryMapContainer#version})
 */
private Map<String, Map<HostAndPort, LookupsState<String>>> getSimpleAllNodeStatus(Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts, Collection<String> tiers) {
    Map<String, Map<HostAndPort, LookupsState<String>>> results = new HashMap<>();
    for (String tier : tiers) {
        Map<HostAndPort, LookupsState<String>> tierNodesStatus = new HashMap<>();
        results.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 {
                Map<String, String> current = lookupsState.getCurrent().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getVersion()));
                Map<String, String> toLoad = lookupsState.getToLoad().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getVersion()));
                tierNodesStatus.put(node, new LookupsState<>(current, toLoad, lookupsState.getToDrop()));
            }
        }
    }
    return results;
}
Also used : Logger(org.apache.druid.java.util.common.logger.Logger) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) AuditInfo(org.apache.druid.audit.AuditInfo) PathParam(javax.ws.rs.PathParam) LookupCoordinatorManager(org.apache.druid.server.lookup.cache.LookupCoordinatorManager) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Inject(com.google.inject.Inject) Smile(org.apache.druid.guice.annotations.Smile) Path(javax.ws.rs.Path) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ServletResourceUtils(org.apache.druid.common.utils.ServletResourceUtils) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IAE(org.apache.druid.java.util.common.IAE) Nullable(javax.annotation.Nullable) DELETE(javax.ws.rs.DELETE) SmileMediaTypes(com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) RE(org.apache.druid.java.util.common.RE) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigResourceFilter(org.apache.druid.server.http.security.ConfigResourceFilter) Set(java.util.Set) IOException(java.io.IOException) Json(org.apache.druid.guice.annotations.Json) HostAndPort(com.google.common.net.HostAndPort) Collectors(java.util.stream.Collectors) AuditManager(org.apache.druid.audit.AuditManager) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) InputStream(java.io.InputStream) HashMap(java.util.HashMap) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) HostAndPort(com.google.common.net.HostAndPort) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with LookupExtractorFactoryMapContainer

use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.

the class LookupCoordinatorResource method getLookupStatus.

@VisibleForTesting
LookupStatus getLookupStatus(String lookupName, LookupExtractorFactoryMapContainer lookupDef, Collection<HostAndPort> nodes, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lastKnownLookupsState, boolean detailed) {
    boolean isReady = true;
    List<HostAndPort> pendingHosts = detailed ? new ArrayList<>() : null;
    for (HostAndPort node : nodes) {
        LookupsState<LookupExtractorFactoryMapContainer> hostState = lastKnownLookupsState.get(node);
        LookupExtractorFactoryMapContainer loadedOnHost = hostState != null ? hostState.getCurrent().get(lookupName) : null;
        if (loadedOnHost == null || lookupDef.replaces(loadedOnHost)) {
            isReady = false;
            if (detailed) {
                pendingHosts.add(node);
            } else {
                break;
            }
        }
    }
    return new LookupStatus(isReady, pendingHosts);
}
Also used : HostAndPort(com.google.common.net.HostAndPort) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with LookupExtractorFactoryMapContainer

use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.

the class LookupCoordinatorResource method getNodesStatusInTier.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/nodeStatus/{tier}")
public Response getNodesStatusInTier(@PathParam("tier") String tier) {
    try {
        Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
        Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> tierNodesStatus = new HashMap<>();
        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 Response.ok(tierNodesStatus).build();
    } catch (Exception ex) {
        LOG.error(ex, "Error getting node status for tier [%s].", tier);
        return Response.serverError().entity(ServletResourceUtils.sanitizeException(ex)).build();
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) HashMap(java.util.HashMap) LookupsState(org.apache.druid.query.lookup.LookupsState) 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 10 with LookupExtractorFactoryMapContainer

use of org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer in project druid by druid-io.

the class LookupCoordinatorResourceTest method testGetAllLookupSpecs.

@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);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(org.apache.druid.server.lookup.cache.LookupCoordinatorManager) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) 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