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;
}
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;
}
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);
}
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();
}
}
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);
}
Aggregations