From b21e77b02426d69468a721e2f0bdc16ed13e6a88 Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Wed, 21 Aug 2024 15:47:59 +0200 Subject: [PATCH 1/7] feat: :sparkles: Pouvoir calculer les valeurs de chaque date Utiliser season-1.4.0, modifier le script de lancement refs agroclim/agrometinfo/AgroMetInfo_2.0#35 --- pom.xml | 2 +- scripts/send-safran-date.sh | 78 +++++++++++++++++++ scripts/test-jolokia.sh | 35 --------- sql/schema.functions.sql | 2 +- .../seasonhandler/jms/SafranReceiver.java | 16 +++- .../simulation-good-with-stages.properties | 3 +- src/test/resources/simulation-good.properties | 3 +- 7 files changed, 97 insertions(+), 42 deletions(-) create mode 100755 scripts/send-safran-date.sh delete mode 100755 scripts/test-jolokia.sh diff --git a/pom.xml b/pom.xml index a8361ca..819e4b8 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ <lombok.version>1.18.34</lombok.version> <mockito.version>5.12.0</mockito.version> <picoli.version>4.7.6</picoli.version> - <season.version>1.3.1</season.version> + <season.version>1.4.0-SNAPSHOT</season.version> <!-- Maven environment values --> <build.date>${maven.build.timestamp}</build.date> <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format> diff --git a/scripts/send-safran-date.sh b/scripts/send-safran-date.sh new file mode 100755 index 0000000..3e1a483 --- /dev/null +++ b/scripts/send-safran-date.sh @@ -0,0 +1,78 @@ +#!/bin/bash +set -e + +function usage { + echo "USAGE" + echo " $0 [OPTIONS]" + echo "" + echo " Environment variables AGROMETINFO_ACTIVEMQ_USER and AGROMETINFO_ACTIVEMQ_PASSWORD must be set." + echo "OPTIONS" + echo " -h show usage" + echo " -c compute each date" + echo " -l <DATE> send to localhost" + echo " -p <DATE> send to pre-production" +} + +if [[ -z "$AGROMETINFO_ACTIVEMQ_USER" ]]; then + echo "Missing AGROMETINFO_ACTIVEMQ_USER" + exit 1 +fi +if [[ -z "$AGROMETINFO_ACTIVEMQ_PASSWORD" ]]; then + echo "Missing AGROMETINFO_ACTIVEMQ_PASSWORD" + exit 1 +fi + +while getopts ":chl:p:" option +do + case "${option}" in + c) + COMPUTE_EACH_DATE='true' + ;; + h) + usage + exit 0 + ;; + l) + URL='http://localhost:8161/console/jolokia/' + DATE=$OPTARG + ;; + p) + URL='http://agrometinfo-preprod:8161/console/jolokia/' + DATE=$OPTARG + ;; + :) + echo "Option -$OPTARG requires an argument." + usage + exit 1 + ;; + \?) + echo "Invalid option: -$OPTARG" + usage + exit 1 + ;; + esac +done + +if [[ -z "$DATE" ]]; then + usage + exit 1 +fi + +BASE64=$(printf '%s:%s' "$AGROMETINFO_ACTIVEMQ_USER" "$AGROMETINFO_ACTIVEMQ_PASSWORD" | base64) + +JSON='{ +"type":"exec", +"mbean":"org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"agrometinfo-new-safran-data\"", +"operation":"sendMessage(java.util.Map, int, java.lang.String, boolean, java.lang.String, java.lang.String, boolean)", +"arguments":[ + {"compute_each_date": "'$COMPUTE_EACH_DATE'"}, + 3, + "'$DATE'", + true, + null, + null, + false +] +}' +curl --verbose $URL -H "Content-Type: text/json" -H "Authorization: Basic $BASE64" --data-raw "$JSON" +echo diff --git a/scripts/test-jolokia.sh b/scripts/test-jolokia.sh deleted file mode 100755 index f3e34c9..0000000 --- a/scripts/test-jolokia.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -set -e - -if [[ -z "$AGROMETINFO_ACTIVEMQ_USER" ]]; then - echo "Missing AGROMETINFO_ACTIVEMQ_USER" - exit 1 -fi -if [[ -z "$AGROMETINFO_ACTIVEMQ_PASSWORD" ]]; then - echo "Missing AGROMETINFO_ACTIVEMQ_PASSWORD" - exit 1 -fi -if [[ -z "$1" ]]; then - DATE=$(date +%Y-%m-%d) -else - DATE=$1 -fi -BASE64=$(printf '%s:%s' "$AGROMETINFO_ACTIVEMQ_USER" "$AGROMETINFO_ACTIVEMQ_PASSWORD" | base64) - -JSON='{ -"type":"exec", -"mbean":"org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"agrometinfo-new-safran-data\"", -"operation":"sendMessage(java.util.Map, int, java.lang.String, boolean, java.lang.String, java.lang.String, boolean)", -"arguments":[ - {}, - 3, - "'$DATE'", - true, - null, - null, - false -] -}' -URL='http://localhost:8161/console/jolokia/' -curl --verbose $URL -H "Content-Type: text/json" -H "Authorization: Basic $BASE64" --data-raw "$JSON" -echo diff --git a/sql/schema.functions.sql b/sql/schema.functions.sql index cc1b892..30c5937 100644 --- a/sql/schema.functions.sql +++ b/sql/schema.functions.sql @@ -9,7 +9,7 @@ BEGIN sql := format( $$ INSERT INTO agrometinfo.dailyvalue ("indicator", cell, date, computedvalue, comparedvalue) -SELECT +SELECT DISTINCT i.id AS "indicator", s.cell, s.enddate AS date, diff --git a/src/main/java/fr/agrometinfo/seasonhandler/jms/SafranReceiver.java b/src/main/java/fr/agrometinfo/seasonhandler/jms/SafranReceiver.java index 89afe4a..8e44ad6 100644 --- a/src/main/java/fr/agrometinfo/seasonhandler/jms/SafranReceiver.java +++ b/src/main/java/fr/agrometinfo/seasonhandler/jms/SafranReceiver.java @@ -119,10 +119,17 @@ public final class SafranReceiver implements MessageListener, Runnable { if (message instanceof final ActiveMQMessage msg) { try { final String body = msg.getBody(String.class); + final String property = SimulationProperties.Property.COMPUTE_EACH_DATE.name().toLowerCase(); + final boolean computeEachDate; + if (msg.propertyExists(property)) { + computeEachDate = msg.getBooleanProperty(property); + } else { + computeEachDate = false; + } LOGGER.info("Body from received message: {}", body); lastDate = LocalDate.parse(body); updateLastDateInTable(); - sendEvaluations(); + sendEvaluations(computeEachDate); msg.acknowledge(); } catch (final IndicatorsException | JMSException ex) { LOGGER.fatal(ex); @@ -139,6 +146,7 @@ public final class SafranReceiver implements MessageListener, Runnable { Objects.requireNonNull(launcher); Objects.requireNonNull(varietyParameterDao); consumer.setMessageListener(this); + fitter.setVarietyParameterDao(varietyParameterDao); } /** @@ -162,10 +170,11 @@ public final class SafranReceiver implements MessageListener, Runnable { } /** + * @param computeEachDate If evaluation computation is launched with {@link Evaluation#computeEachDate()} * @throws IndicatorsException should not occur at this point: error while getting XML from evaluation */ - private void sendEvaluations() throws IndicatorsException { - LOGGER.traceEntry("Loop on each evaluation"); + private void sendEvaluations(final boolean computeEachDate) throws IndicatorsException { + LOGGER.traceEntry("Loop on each evaluation, compute each date : {}", computeEachDate); final Optional<String> res = config.init(); if (!res.isEmpty()) { LOGGER.error("Configuration error: " + res.get()); @@ -176,6 +185,7 @@ public final class SafranReceiver implements MessageListener, Runnable { LOGGER.trace("SimulationProperties: {}", config.getSimulationProperties()); for (int i = 0; i < config.getEvaluations().size(); i++) { final SimulationProperties props = config.getSimulationProperties().get(i); + props.set(SimulationProperties.Property.COMPUTE_EACH_DATE, computeEachDate); final Evaluation evaluation = config.getEvaluations().get(i); sendEvaluation(evaluation, props); } diff --git a/src/test/resources/simulation-good-with-stages.properties b/src/test/resources/simulation-good-with-stages.properties index 1127b08..35fe90f 100644 --- a/src/test/resources/simulation-good-with-stages.properties +++ b/src/test/resources/simulation-good-with-stages.properties @@ -4,10 +4,11 @@ climatic_model = safran climatic_scenario = SAFRAN start_year = 1980 end_year = 2015 +compute_each_date = false species = bl\u00e9 variety = soissons # cell ids are provided in another file. cells = ./cells-good.json phenological_model = linear # stages -stages = s0: 274, s1: 307, s2: 366, s8: 730 \ No newline at end of file +stages = s0: 274, s1: 307, s2: 366, s8: 730 diff --git a/src/test/resources/simulation-good.properties b/src/test/resources/simulation-good.properties index 699c5a0..2ed8bd1 100644 --- a/src/test/resources/simulation-good.properties +++ b/src/test/resources/simulation-good.properties @@ -4,6 +4,7 @@ climatic_model = safran climatic_scenario = SAFRAN start_year = 1980 end_year = 2015 +compute_each_date = false species = bl\u00e9 variety = soissons # cell ids are provided in another file. @@ -11,4 +12,4 @@ cells = ./cells-good.json # phenological model phenological_model = linear # If computed soil data must be stored. default: false. -store_soil_data = true \ No newline at end of file +store_soil_data = true -- GitLab From 4828ca0205d179386f97fa5579f4ee577cf2a921 Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Wed, 21 Aug 2024 16:52:05 +0200 Subject: [PATCH 2/7] test season-1.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 819e4b8..43873bd 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ <lombok.version>1.18.34</lombok.version> <mockito.version>5.12.0</mockito.version> <picoli.version>4.7.6</picoli.version> - <season.version>1.4.0-SNAPSHOT</season.version> + <season.version>1.4.0</season.version> <!-- Maven environment values --> <build.date>${maven.build.timestamp}</build.date> <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format> -- GitLab From 33954fc3453a166d46041f0b1219109c9bc9573a Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Fri, 23 Aug 2024 15:50:14 +0200 Subject: [PATCH 3/7] =?UTF-8?q?feat!:=20=F0=9F=92=A5=20Ajouter=20une=20opt?= =?UTF-8?q?ion=20calculer=20les=20valeurs=20de=20tous=20les=20jours=20de?= =?UTF-8?q?=20la=20p=C3=A9riode.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Utiliser season-1.4.0 → nouvelle option nécessaire : compute_each_date Modifier le script de lancement refs agroclim/agrometinfo/AgroMetInfo_2.0#35 -- GitLab From 47af511eeebf126453226991b5aa7382d831068c Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Tue, 27 Aug 2024 16:05:57 +0200 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=F0=9F=92=A5=20Ajouter=20une=20opti?= =?UTF-8?q?on=20-f=20au=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/send-safran-date.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/send-safran-date.sh b/scripts/send-safran-date.sh index 3e1a483..da1b4bb 100755 --- a/scripts/send-safran-date.sh +++ b/scripts/send-safran-date.sh @@ -8,6 +8,7 @@ function usage { echo " Environment variables AGROMETINFO_ACTIVEMQ_USER and AGROMETINFO_ACTIVEMQ_PASSWORD must be set." echo "OPTIONS" echo " -h show usage" + echo " -f force, do not ask confirmation" echo " -c compute each date" echo " -l <DATE> send to localhost" echo " -p <DATE> send to pre-production" @@ -22,21 +23,28 @@ if [[ -z "$AGROMETINFO_ACTIVEMQ_PASSWORD" ]]; then exit 1 fi -while getopts ":chl:p:" option +while getopts ":cfhl:p:" option do case "${option}" in c) COMPUTE_EACH_DATE='true' ;; + f) + FORCE='true' + ;; h) usage exit 0 ;; l) + COLOR="\033[32;1;7m" + PROFILE=localhost URL='http://localhost:8161/console/jolokia/' DATE=$OPTARG ;; p) + COLOR="\033[33;1;7m" + PROFILE=preprod URL='http://agrometinfo-preprod:8161/console/jolokia/' DATE=$OPTARG ;; @@ -58,6 +66,16 @@ if [[ -z "$DATE" ]]; then exit 1 fi +if [[ -z "$FORCE" ]]; then + echo -e "Are you sure to send $DATE to $COLOR$URL\033[0m ($COLOR$PROFILE\033[0m)? (y/N)" + read -p "" -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Sending is cancelled!"; + exit 0; + fi +fi + BASE64=$(printf '%s:%s' "$AGROMETINFO_ACTIVEMQ_USER" "$AGROMETINFO_ACTIVEMQ_PASSWORD" | base64) JSON='{ -- GitLab From a37652d1d458d3e7271643eeb356c1b1e84ca544 Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Tue, 27 Aug 2024 16:12:46 +0200 Subject: [PATCH 5/7] =?UTF-8?q?pr=C3=A9ciser=20la=20documentation=20usage.?= =?UTF-8?q?md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/site/markdown/usage.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md index 22a73e1..ed7e2f6 100644 --- a/src/site/markdown/usage.md +++ b/src/site/markdown/usage.md @@ -95,4 +95,23 @@ The SEASON simulation format is described in the SEASON sources at `src/site/mar ### Runtime configuration The other lines are for the configuration of JMS, JDBC and SEASON database roles and connection. -This configuration must be adapted to the environment. \ No newline at end of file +This configuration must be adapted to the environment. + +## Asking AgroMetInfo-SEASON-handler for a new date + +To run the simulation with a new date, use `scripts/send-safran-date.sh`. + +Usages: + +```sh +scripts/send-safran-date.sh -h + +# to compute for pre-production with the date 2024-08-27 +scripts/send-safran-date.sh -p 2024-08-27 + +# to compute each date of phases +scripts/send-safran-date.sh -c -p 2024-08-27 + +# non interactive mode +scripts/send-safran-date.sh -c -f -p 2024-08-27 +``` -- GitLab From a8fd11cb01426d0ebe4322435b5ca2650c7daf32 Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Tue, 27 Aug 2024 16:29:49 +0200 Subject: [PATCH 6/7] =?UTF-8?q?Enlever=20--verbose=20=C3=A0=20curl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/send-safran-date.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/send-safran-date.sh b/scripts/send-safran-date.sh index da1b4bb..907d79a 100755 --- a/scripts/send-safran-date.sh +++ b/scripts/send-safran-date.sh @@ -92,5 +92,5 @@ JSON='{ false ] }' -curl --verbose $URL -H "Content-Type: text/json" -H "Authorization: Basic $BASE64" --data-raw "$JSON" +curl $URL -H "Content-Type: text/json" -H "Authorization: Basic $BASE64" --data-raw "$JSON" echo -- GitLab From f15d791c68d4941e624917b734bd231eb79bd10b Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Thu, 29 Aug 2024 15:41:44 +0200 Subject: [PATCH 7/7] Log --- .../agrometinfo/seasonhandler/jms/SimulationDoneReceiver.java | 2 +- src/main/resources/log4j2.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/agrometinfo/seasonhandler/jms/SimulationDoneReceiver.java b/src/main/java/fr/agrometinfo/seasonhandler/jms/SimulationDoneReceiver.java index acb91c3..c256a1f 100644 --- a/src/main/java/fr/agrometinfo/seasonhandler/jms/SimulationDoneReceiver.java +++ b/src/main/java/fr/agrometinfo/seasonhandler/jms/SimulationDoneReceiver.java @@ -108,7 +108,7 @@ public final class SimulationDoneReceiver implements MessageListener, Runnable { msg.acknowledge(); return; } - LOGGER.info("Simulation results in {}.{}", schemaName, tableName); + LOGGER.info("Insert simulation results from {}.{}", schemaName, tableName); dailyvalueDao.insertFromTable(tableName); simulationErrorDao.delete(simulation); simulationResultDao.delete(simulation); diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index aa4d88f..36d31af 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -4,7 +4,7 @@ <Appenders> <Console name="console" target="SYSTEM_OUT"> <PatternLayout> - <pattern>[%d] %-5p | %c#%M() | %L - %m%n</pattern> + <pattern>[%d] %-5p | %-40.40c{1.}#%M() | %L - %m%n</pattern> </PatternLayout> </Console> <!-- https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender --> -- GitLab