forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make global lookup cache introspector class public (apache#3199)
* Make global lookup cache introspector class public * Fixes apache#3187 * Make KafkaLookupExtractorIntrospectionHandler a public static class
- Loading branch information
1 parent
e1313e4
commit bfa5c05
Showing
4 changed files
with
152 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...mespace/src/main/java/io/druid/query/lookup/KafkaLookupExtractorIntrospectionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...s-cached-global/src/main/java/io/druid/query/lookup/NamespaceLookupIntrospectHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |