From 96445606134950a03264b66551e23180311653a4 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Tue, 16 Oct 2018 16:12:48 +0200 Subject: [PATCH] bugfixes in weather data handling --- .../controller/session/SchedulingBean.java | 2 +- .../AppleScabModelPreprocessor.java | 21 +------------------ .../NaerstadModelPreprocessor.java | 2 +- .../logic/service/WeatherProxyService.java | 4 ++-- .../util/weather/WeatherDataSourceUtil.java | 10 +++++++++ 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java b/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java index 2e8922cc..311c368e 100755 --- a/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java +++ b/src/main/java/no/nibio/vips/logic/controller/session/SchedulingBean.java @@ -449,7 +449,7 @@ public class SchedulingBean { " failed at + " + taskExecutor.getStartTime() + ", finished at " + new Date() + ". Status is " + taskHistory.getTaskHistoryStatusId() + - ". Error was " + taskHistory.getMessage().substring(0,400) + "[...]" + + ". Error was " + taskHistory.getMessage().substring(0, Math.min(400, taskHistory.getMessage().length())) + "[...]" + " ############"); } diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java index 58829987..4de8ad02 100755 --- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java +++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/AppleScabModelPreprocessor.java @@ -249,7 +249,7 @@ public class AppleScabModelPreprocessor extends ModelRunPreprocessor{ //System.out.println(wUtil.dumpWeatherObservationList(RR)); } - BT = wUtil.checkForAndFixHourlyTimeSeriesHoles(BT); + // Unequal length of lists if ( @@ -267,25 +267,6 @@ public class AppleScabModelPreprocessor extends ModelRunPreprocessor{ // Fallback if missing leaf wetness: If we have relative humidity. leaf wetness may be calculated if(BT.size() != TM.size() && UM.size() == TM.size()) { - Q0 = wUtil.fixHourlyValuesForParameters( - Q0, - new HashSet(Arrays.asList("Q0")), - firstTimeStamp, - null - ); - FM2 = wUtil.fixHourlyValuesForParameters( - FM2, - new HashSet(Arrays.asList("FM2")), - firstTimeStamp, - null - ); - - BT = wUtil.fixHourlyValuesForParameters( - BT, - new HashSet(Arrays.asList("BT")), - firstTimeStamp, - null - ); BT = wUtil.calculateLeafWetnessHourSeriesBestEffort(BT,TM, RR, Q0, FM2, UM); if(BT.size() != TM.size()) diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java index e1199dc2..ce971de0 100755 --- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java +++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NaerstadModelPreprocessor.java @@ -210,7 +210,7 @@ public class NaerstadModelPreprocessor extends ModelRunPreprocessor{ // Problems with weather observations //System.out.println("BT=" + BT.size() + " [First=," + BT.get(0).getTimeMeasured() + " last=" + BT.get(BT.size()-1).getTimeMeasured() + "]"); - BT = wUtil.checkForAndFixHourlyTimeSeriesHoles(BT); + //BT = wUtil.checkForAndFixHourlyTimeSeriesHoles(BT); // Unequal length of lists if ( diff --git a/src/main/java/no/nibio/vips/logic/service/WeatherProxyService.java b/src/main/java/no/nibio/vips/logic/service/WeatherProxyService.java index 4f91248f..a42071b4 100755 --- a/src/main/java/no/nibio/vips/logic/service/WeatherProxyService.java +++ b/src/main/java/no/nibio/vips/logic/service/WeatherProxyService.java @@ -99,7 +99,7 @@ public class WeatherProxyService { @Path("fmi/{stationId}") @GZIP @Produces("application/json;charset=UTF-8") - public Response getMetosRIMProWeatherData( + public Response getFMIVIPSWeatherData( @PathParam("stationId") String stationId, @FormParam("timeZone") String timeZonePOST, @QueryParam("timeZone") String timeZoneGET, @@ -109,7 +109,7 @@ public class WeatherProxyService { @QueryParam("endDate") String endDateGET ) { - String FMI_URL_TEMPLATE="http://www.cropinfra.com:8080/weather/resources/fmi/temporal/vips/{0}/{1}/{2}"; + String FMI_URL_TEMPLATE="http://192.194.211.203/weather/resources/fmi/temporal/vips/{0}/{1}/{2}"; List<WeatherObservation> observations; try { diff --git a/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java b/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java index e79b30a8..80590d55 100755 --- a/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java +++ b/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLConnection; import java.text.SimpleDateFormat; @@ -181,10 +182,15 @@ public class WeatherDataSourceUtil { InputStream URLStream = null; InputStream error = null; String URLOutput; + int connectTimeout = 30; + int readTimeout = 120; try { URL weatherURL = new URL(URL.toString()); //System.out.println("URL=" + weatherURL); URLConn = weatherURL.openConnection(); + + URLConn.setConnectTimeout(1000 * connectTimeout); // If weather data server does not reply in 30 seconds, abort + URLConn.setReadTimeout(1000 * readTimeout); // If weather data server is not done delivering the data in two minutes, abort URLStream = URLConn.getInputStream(); URLOutput = IOUtils.toString(URLStream); List<WeatherObservation> preliminaryResult = this.getWeatherObservations(URLOutput); @@ -207,6 +213,10 @@ public class WeatherDataSourceUtil { errorOutput = IOUtils.toString(error); } catch (IOException | NullPointerException ex2) { } + if(ex instanceof SocketTimeoutException) + { + errorMessage.append("The weather data server is deemed unresponsive. The connection times out after " + connectTimeout + " seconds of no reply and " + readTimeout + " seconds of no data received after established connection.\n"); + } if (errorOutput.isEmpty()) { errorMessage.append("There was no output from weather data server to explain this."); } else { -- GitLab