mirror of
https://github.com/apache/druid.git
synced 2025-02-17 07:25:02 +00:00
Make global lookup cache introspector class public (#3199)
* Make global lookup cache introspector class public * Fixes #3187 * Make KafkaLookupExtractorIntrospectionHandler a public static class
This commit is contained in:
parent
e1313e4b90
commit
bfa5c05aaa
@ -47,8 +47,6 @@ import kafka.serializer.Decoder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -344,7 +342,7 @@ public class KafkaLookupExtractorFactory implements LookupExtractorFactory
|
||||
@Override
|
||||
public LookupIntrospectHandler getIntrospectHandler()
|
||||
{
|
||||
return new KafkaLookupExtractorIntrospectionHandler();
|
||||
return new KafkaLookupExtractorIntrospectionHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -406,19 +404,4 @@ public class KafkaLookupExtractorFactory implements LookupExtractorFactory
|
||||
{
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
class KafkaLookupExtractorIntrospectionHandler implements LookupIntrospectHandler
|
||||
{
|
||||
@GET
|
||||
public Response getActive()
|
||||
{
|
||||
final ListenableFuture<?> future = getFuture();
|
||||
if (future != null && !future.isDone()) {
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Response.Status.GONE).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Metamarkets licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.druid.query.lookup;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class KafkaLookupExtractorIntrospectionHandler implements LookupIntrospectHandler
|
||||
{
|
||||
private KafkaLookupExtractorFactory kafkaLookupExtractorFactory;
|
||||
|
||||
public KafkaLookupExtractorIntrospectionHandler(KafkaLookupExtractorFactory kafkaLookupExtractorFactory) {this.kafkaLookupExtractorFactory = kafkaLookupExtractorFactory;}
|
||||
|
||||
@GET
|
||||
public Response getActive()
|
||||
{
|
||||
final ListenableFuture<?> future = kafkaLookupExtractorFactory.getFuture();
|
||||
if (future != null && !future.isDone()) {
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Response.Status.GONE).build();
|
||||
}
|
||||
}
|
||||
}
|
@ -25,21 +25,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.metamx.common.ISE;
|
||||
import com.metamx.common.StringUtils;
|
||||
import com.metamx.common.logger.Logger;
|
||||
import io.druid.common.utils.ServletResourceUtils;
|
||||
import io.druid.query.extraction.MapLookupExtractor;
|
||||
import io.druid.query.lookup.namespace.ExtractionNamespace;
|
||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -86,65 +79,7 @@ public class NamespaceLookupExtractorFactory implements LookupExtractorFactory
|
||||
this.injective = injective;
|
||||
this.manager = manager;
|
||||
this.extractorID = buildID();
|
||||
this.lookupIntrospectHandler = new LookupIntrospectHandler()
|
||||
{
|
||||
@GET
|
||||
@Path("/keys")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getKeys()
|
||||
{
|
||||
try {
|
||||
return Response.ok(getLatest().keySet()).build();
|
||||
}
|
||||
catch (ISE e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(e)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/values")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getValues()
|
||||
{
|
||||
try {
|
||||
return Response.ok(getLatest().values()).build();
|
||||
}
|
||||
catch (ISE e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(e)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/version")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getVersion()
|
||||
{
|
||||
final String version = manager.getVersion(extractorID);
|
||||
if (null == version) {
|
||||
// Handle race between delete and this method being called
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} else {
|
||||
return Response.ok(ImmutableMap.of("version", version)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getMap()
|
||||
{
|
||||
try {
|
||||
return Response.ok(getLatest()).build();
|
||||
}
|
||||
catch (ISE e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(e)).build();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getLatest()
|
||||
{
|
||||
return ((MapLookupExtractor) get()).getMap();
|
||||
}
|
||||
};
|
||||
this.lookupIntrospectHandler = new NamespaceLookupIntrospectHandler(this, manager, extractorID);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@ -166,13 +101,13 @@ public class NamespaceLookupExtractorFactory implements LookupExtractorFactory
|
||||
LOG.warn("Already started! [%s]", extractorID);
|
||||
return true;
|
||||
}
|
||||
if(firstCacheTimeout > 0) {
|
||||
if (firstCacheTimeout > 0) {
|
||||
if (!manager.scheduleAndWait(extractorID, extractionNamespace, firstCacheTimeout)) {
|
||||
LOG.error("Failed to schedule and wait for lookup [%s]", extractorID);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!manager.scheduleOrUpdate(extractorID, extractionNamespace)) {
|
||||
if (!manager.scheduleOrUpdate(extractorID, extractionNamespace)) {
|
||||
LOG.error("Failed to schedule lookup [%s]", extractorID);
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Metamarkets licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.druid.query.lookup;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.metamx.common.ISE;
|
||||
import io.druid.common.utils.ServletResourceUtils;
|
||||
import io.druid.query.extraction.MapLookupExtractor;
|
||||
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Map;
|
||||
|
||||
public class NamespaceLookupIntrospectHandler implements LookupIntrospectHandler
|
||||
{
|
||||
private final NamespaceLookupExtractorFactory factory;
|
||||
private final String extractorID;
|
||||
private final NamespaceExtractionCacheManager manager;
|
||||
public NamespaceLookupIntrospectHandler(
|
||||
NamespaceLookupExtractorFactory factory,
|
||||
NamespaceExtractionCacheManager manager,
|
||||
String extractorID
|
||||
) {
|
||||
this.factory = factory;
|
||||
this.extractorID = extractorID;
|
||||
this.manager = manager;
|
||||
}
|
||||
@GET
|
||||
@Path("/keys")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getKeys()
|
||||
{
|
||||
try {
|
||||
return Response.ok(getLatest().keySet()).build();
|
||||
}
|
||||
catch (ISE e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(e)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/values")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getValues()
|
||||
{
|
||||
try {
|
||||
return Response.ok(getLatest().values()).build();
|
||||
}
|
||||
catch (ISE e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(e)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/version")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getVersion()
|
||||
{
|
||||
final String version = manager.getVersion(extractorID);
|
||||
if (null == version) {
|
||||
// Handle race between delete and this method being called
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} else {
|
||||
return Response.ok(ImmutableMap.of("version", version)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getMap()
|
||||
{
|
||||
try {
|
||||
return Response.ok(getLatest()).build();
|
||||
}
|
||||
catch (ISE e) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.sanitizeException(e)).build();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getLatest()
|
||||
{
|
||||
return ((MapLookupExtractor) factory.get()).getMap();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user