Skip to content

Commit

Permalink
introducing parameter timeout
Browse files Browse the repository at this point in the history
to define a smaller timeout threshold
  • Loading branch information
FabiKo117 committed Feb 15, 2019
1 parent 01eca91 commit 8ebec3b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void run(ApplicationArguments args) throws Exception {
DbConnData.mapTagTranslator = new RemoteTagTranslator(DbConnData.tagTranslator);
}
if (DbConnData.db instanceof OSHDBIgnite) {
ProcessingData.setTimeout(timeout/1000);
((OSHDBIgnite) DbConnData.db).timeoutInMilliseconds(timeout);
RemoteTagTranslator mtt = DbConnData.mapTagTranslator;
((OSHDBIgnite) DbConnData.db).onClose(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.heigit.bigspatialdata.ohsome.ohsomeapi.exception;

import org.heigit.bigspatialdata.ohsome.ohsomeapi.inputprocessing.ProcessingData;

/** Holds custom error messages used in several classes for different exceptions. */
public class ExceptionMessages {

Expand Down Expand Up @@ -39,6 +41,8 @@ public class ExceptionMessages {
"You need to give at least two timestamps or a time interval for this resource.";
public static final String SHOWMETADATA_PARAM = "The showMetadata parameter can only contain the "
+ "values 'true', 'yes', 'false', or 'no'.";
public static final String TIMEOUT = "The given timeout is too long. It has to be shorter than "
+ ProcessingData.getTimeout() + " seconds";

private ExceptionMessages() {
throw new IllegalStateException("Utility class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,13 @@ public static Response executeCountLengthPerimeterAreaShareRatio(RequestResource
osmTypes.stream().map(OSMType::toString).map(String::toLowerCase).toArray(String[]::new);
if (!inputProcessor.compareKeysValues(requestParameters.getKeys(), keys2,
requestParameters.getValues(), values2)) {
RequestParameters requestParams = new RequestParameters(servletRequest.getMethod(),
isSnapshot, isDensity, servletRequest.getParameter("bboxes"),
servletRequest.getParameter("bcircles"), servletRequest.getParameter("bpolys"),
osmTypesString, new String[] {}, new String[] {},
servletRequest.getParameterValues("userids"), servletRequest.getParameterValues("time"),
servletRequest.getParameter("format"), servletRequest.getParameter("showMetadata"));
RequestParameters requestParams =
new RequestParameters(servletRequest.getMethod(), isSnapshot, isDensity,
servletRequest.getParameter("bboxes"), servletRequest.getParameter("bcircles"),
servletRequest.getParameter("bpolys"), osmTypesString, new String[] {},
new String[] {}, servletRequest.getParameterValues("userids"),
servletRequest.getParameterValues("time"), servletRequest.getParameter("format"),
servletRequest.getParameter("showMetadata"), ProcessingData.getTimeout());
ProcessingData pD = new ProcessingData(requestParams);
InputProcessor iP =
new InputProcessor(servletRequest, isSnapshot, isDensity, RequestInterceptor.requestUrl);
Expand Down Expand Up @@ -1102,12 +1103,13 @@ public static <P extends Geometry & Polygonal> Response executeCountLengthPerime
osmTypes.stream().map(OSMType::toString).map(String::toLowerCase).toArray(String[]::new);
if (!inputProcessor.compareKeysValues(requestParameters.getKeys(), keys2,
requestParameters.getValues(), values2)) {
RequestParameters requestParams = new RequestParameters(servletRequest.getMethod(),
isSnapshot, isDensity, servletRequest.getParameter("bboxes"),
servletRequest.getParameter("bcircles"), servletRequest.getParameter("bpolys"),
osmTypesString, new String[] {}, new String[] {},
servletRequest.getParameterValues("userids"), servletRequest.getParameterValues("time"),
servletRequest.getParameter("format"), servletRequest.getParameter("showMetadata"));
RequestParameters requestParams =
new RequestParameters(servletRequest.getMethod(), isSnapshot, isDensity,
servletRequest.getParameter("bboxes"), servletRequest.getParameter("bcircles"),
servletRequest.getParameter("bpolys"), osmTypesString, new String[] {},
new String[] {}, servletRequest.getParameterValues("userids"),
servletRequest.getParameterValues("time"), servletRequest.getParameter("format"),
servletRequest.getParameter("showMetadata"), ProcessingData.getTimeout());
ProcessingData pD = new ProcessingData(requestParams);
InputProcessor iP =
new InputProcessor(servletRequest, isSnapshot, isDensity, RequestInterceptor.requestUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public class RequestParameters {
private String[] time;
private String format;
private String showMetadata;
private double timeout;

public RequestParameters(String requestMethod, boolean isSnapshot, boolean isDensity,
String bboxes, String bcircles, String bpolys, String[] types, String[] keys, String[] values,
String[] userids, String[] time, String format, String showMetadata) {
String[] userids, String[] time, String format, String showMetadata, double timeout) {
this.requestMethod = requestMethod;
this.isDensity = isDensity;
this.isSnapshot = isSnapshot;
Expand All @@ -33,6 +34,7 @@ public RequestParameters(String requestMethod, boolean isSnapshot, boolean isDen
this.time = time;
this.format = format;
this.showMetadata = showMetadata;
this.timeout = timeout;
}

public String getRequestMethod() {
Expand Down Expand Up @@ -86,4 +88,8 @@ public String getFormat() {
public String getShowMetadata() {
return showMetadata;
}

public double getTimeout() {
return timeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ public InputProcessor(HttpServletRequest servletRequest, boolean isSnapshot, boo
this.servletRequest = servletRequest;
this.isSnapshot = isSnapshot;
this.isDensity = isDensity;
processingData =
new ProcessingData(new RequestParameters(servletRequest.getMethod(), isSnapshot, isDensity,
servletRequest.getParameter("bboxes"), servletRequest.getParameter("bcircles"),
servletRequest.getParameter("bpolys"), servletRequest.getParameterValues("types"),
servletRequest.getParameterValues("keys"), servletRequest.getParameterValues("values"),
servletRequest.getParameterValues("userids"), servletRequest.getParameterValues("time"),
servletRequest.getParameter("format"), servletRequest.getParameter("showMetadata")));
processingData = new ProcessingData(new RequestParameters(servletRequest.getMethod(),
isSnapshot, isDensity, servletRequest.getParameter("bboxes"),
servletRequest.getParameter("bcircles"), servletRequest.getParameter("bpolys"),
servletRequest.getParameterValues("types"), servletRequest.getParameterValues("keys"),
servletRequest.getParameterValues("values"), servletRequest.getParameterValues("userids"),
servletRequest.getParameterValues("time"), servletRequest.getParameter("format"),
servletRequest.getParameter("showMetadata"), ProcessingData.getTimeout()));
// } else {
// try {
// BufferedReader reader = servletRequest.getReader();
// while (reader.readLine() != null) {
// System.out.println(reader.readLine());
// }
// } catch (IOException e) {
// // TODO Auto-generated catch block
// throw new RuntimeException();
// }
// }
this.requestUrl = requestUrl;
}

Expand Down Expand Up @@ -95,10 +106,11 @@ public <T extends OSHDBMapReducible> MapReducer<T> processParameters() throws Ex
String format = createEmptyStringIfNull(processingData.getRequestParameters().getFormat());
String showMetadata =
createEmptyStringIfNull(processingData.getRequestParameters().getShowMetadata());
double timeout = defineRequestTimeout();
// overwriting RequestParameters object with splitted/non-null parameters
processingData.setRequestParameters(
new RequestParameters(servletRequest.getMethod(), isSnapshot, isDensity, bboxes, bcircles,
bpolys, types, keys, values, userids, time, format, showMetadata));
bpolys, types, keys, values, userids, time, format, showMetadata, timeout));
processingData.setFormat(format);
geomBuilder = new GeometryBuilder(processingData);
utils = new InputProcessingUtils();
Expand Down Expand Up @@ -521,6 +533,27 @@ private void checkFormat(String format) throws BadRequestException {
}
}

/**
* Defines the timeout for this request depending on the given timeout parameter. If it is smaller
* than the predefined value, it is used for this request.
*
* @return <code>double</code> value defining the timeout for this request
* @throws BadRequestException if the given timeout is larger than the predefined one
*/
private double defineRequestTimeout() throws BadRequestException {
double timeout = ProcessingData.getTimeout();
String requestTimeoutString = createEmptyStringIfNull(servletRequest.getParameter("timeout"));
if (!requestTimeoutString.isEmpty()) {
double requestTimeoutDouble = Double.parseDouble(requestTimeoutString);
if (requestTimeoutDouble > timeout) {
timeout = requestTimeoutDouble;
} else {
throw new BadRequestException(ExceptionMessages.TIMEOUT);
}
}
return timeout;
}

/**
* Sets a corresponding enum (NOBOUNDARY for no boundary, BBOXES for bboxes, BCIRCLES for
* bcircles, BPOLYS for bpolys) based on the given boundary parameter(s). Only one of them is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class ProcessingData {

private static Geometry dataPolyGeom;
private static double timeout;
private RequestParameters requestParameters;
private String requestUrl;
private BoundaryType boundary;
Expand All @@ -30,6 +31,22 @@ public ProcessingData(RequestParameters requestParameters) {
this.requestParameters = requestParameters;
}

public static Geometry getDataPolyGeom() {
return dataPolyGeom;
}

public static void setDataPolyGeom(Geometry dataPolyGeom) {
ProcessingData.dataPolyGeom = dataPolyGeom;
}

public static double getTimeout() {
return timeout;
}

public static void setTimeout(double timeout) {
ProcessingData.timeout = timeout;
}

public RequestParameters getRequestParameters() {
return requestParameters;
}
Expand Down Expand Up @@ -126,14 +143,6 @@ public void setGeoJsonGeoms(GeoJsonObject[] geoJsonGeoms) {
this.geoJsonGeoms = geoJsonGeoms;
}

public static Geometry getDataPolyGeom() {
return dataPolyGeom;
}

public static void setDataPolyGeom(Geometry dataPolyGeom) {
ProcessingData.dataPolyGeom = dataPolyGeom;
}

public boolean isShowMetadata() {
return showMetadata;
}
Expand Down

0 comments on commit 8ebec3b

Please sign in to comment.