Added errors when requesting VC in caching process (resolved #47)
Change-Id: I005cf20113c3badfed938117a93a505b3fedd6b9
Change-Id: I005cf20113c3badfed938117a93a505b3fedd6b9
diff --git a/core/Changes b/core/Changes
index 64c0651..6aa58f1 100644
--- a/core/Changes
+++ b/core/Changes
@@ -1,6 +1,9 @@
# version 0.62.3
03/12/2019
- Implemented pipe extension in the search API (margaretha)
+11/12/2019
+ - Added errors when requesting VC in caching process (margaretha,
+ resolved #47)
# version 0.62.2
13/11/2019
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index dcbc3cb..273250a 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -16,8 +16,6 @@
import java.util.Set;
import java.util.regex.Pattern;
-import org.apache.commons.io.FileUtils;
-
import de.ids_mannheim.korap.util.KrillProperties;
import de.ids_mannheim.korap.utils.TimeUtils;
import lombok.Getter;
@@ -41,6 +39,8 @@
public static final Map<String, Object> KUSTVAKT_USER = new HashMap<>();
+ private String vcInCaching;
+
private String indexDir;
private int port;
// todo: make exclusive so that the containg languages can really
diff --git a/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java b/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
index f65165e..a2ebe5f 100644
--- a/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -29,6 +29,7 @@
public static final int NON_UNIQUE_RESULT_FOUND = 113;
public static final int NO_RESOURCE_FOUND = 114;
public static final int DEPRECATED_PARAMETER = 115;
+ public static final int CACHING_VC = 116;
/**
* 200 status codes general JSON serialization error
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java b/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
index 23ff8e6..a94d0b3 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
@@ -98,6 +98,9 @@
case StatusCodes.NO_RESOURCE_FOUND:
status = Response.Status.NOT_FOUND;
break;
+ case StatusCodes.CACHING_VC:
+ status = Response.Status.SERVICE_UNAVAILABLE;
+ break;
}
return status;
}
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java b/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
index 43f3693..51bcaae 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
@@ -18,9 +18,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.spi.container.ResourceFilters;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.response.Notifications;
@@ -53,7 +55,9 @@
private CoreResponseHandler kustvaktResponseHandler;
@Autowired
private SearchKrill searchKrill;
-
+ @Autowired
+ private KustvaktConfiguration config;
+
/**
* Returns statistics of the virtual corpus defined by the given
* corpusQuery parameter.
@@ -91,6 +95,7 @@
isDeprecated = true;
}
+ checkVC(json);
stats = searchKrill.getStatistics(json);
if (isDeprecated){
@@ -116,6 +121,29 @@
return Response.ok(stats).build();
}
+ private void checkVC (String json) throws KustvaktException {
+ JsonNode node = JsonUtils.readTree(json);
+ node = node.at("/collection");
+ if (node.has("ref")){
+ String vcName = node.path("ref").asText();
+ if (vcName.contains("/")) {
+ String[] names = vcName.split("/");
+ if (names.length == 2) {
+ vcName = names[1];
+ }
+ }
+
+ String vcInCaching = config.getVcInCaching();
+ if (vcName.equals(vcInCaching)) {
+ throw new KustvaktException(
+ de.ids_mannheim.korap.exceptions.StatusCodes.CACHING_VC,
+ "VC is currently busy and unaccessible due to "
+ + "caching process",
+ node.get("ref").asText());
+ }
+ }
+ }
+
@POST
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
public Response getStatisticsFromKoralQuery (
@@ -124,6 +152,7 @@
String stats;
try {
if (koralQuery != null && !koralQuery.isEmpty()) {
+ checkVC(koralQuery);
stats = searchKrill.getStatistics(koralQuery);
}
else {
diff --git a/full/Changes b/full/Changes
index 6ce2b2a..8697d35 100644
--- a/full/Changes
+++ b/full/Changes
@@ -1,6 +1,9 @@
# version 0.62.3
03/12/2019
- Implemented pipe extension in the search API (margaretha)
+11/12/2019
+ - Added errors when requesting VC in caching process (margaretha,
+ resolved #47)
# version 0.62.2
17/10/2019
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
index 014a057..eaa462e 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
@@ -137,13 +137,14 @@
private void cacheVC (String json, String filename)
throws IOException, QueryException {
+ config.setVcInCaching(filename);
long start, end;
start = System.currentTimeMillis();
KrillCollection collection = new KrillCollection(json);
collection.setIndex(searchKrill.getIndex());
- jlog.info("Store {} in cache ", filename);
+ jlog.info("Storing {} in cache ", filename);
if (collection != null) {
collection.storeInCache(filename);
}
@@ -153,5 +154,6 @@
jlog.debug("memory cache: "
+ KrillCollection.cache.calculateInMemorySize());
}
+ config.setVcInCaching("");
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
index 39c76d4..3f25da1 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
@@ -26,6 +26,8 @@
public class VirtualCorpusRewrite implements RewriteTask.RewriteQuery {
@Autowired
+ private KustvaktConfiguration config;
+ @Autowired
private VirtualCorpusService vcService;
@Override
@@ -59,6 +61,15 @@
}
}
+ String vcInCaching = config.getVcInCaching();
+ if (vcName.equals(vcInCaching)) {
+ throw new KustvaktException(
+ de.ids_mannheim.korap.exceptions.StatusCodes.CACHING_VC,
+ "VC is currently busy and unaccessible due to "
+ + "caching process",
+ koralNode.get("ref"));
+ }
+
VirtualCorpus vc =
vcService.searchVCByName(username, vcName, vcOwner);
if (!vc.isCached()) {
diff --git a/full/src/main/resources/ehcache.xml b/full/src/main/resources/ehcache.xml
index cc06d48..da9acda 100644
--- a/full/src/main/resources/ehcache.xml
+++ b/full/src/main/resources/ehcache.xml
@@ -59,6 +59,6 @@
maxBytesLocalDisk="1G"
diskExpiryThreadIntervalSeconds = "120" >
<persistence strategy="localTempSwap"/>
- <sizeOfPolicy maxDepth="1000" maxDepthExceededBehavior="abort" />
+ <sizeOfPolicy maxDepth="2000" maxDepthExceededBehavior="abort" />
</cache>
</ehcache>