diff --git a/README.md b/README.md index 25e9677d..d5de6767 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,10 @@ To build the project, you will have to install [Java](http://www.oracle.com/tech Pull requests and new commits to any branch are automatically built by a Jenkins service. A Gitea webhook informs the service about changes to the repository. In addition, the service will automatically scan the lbs Gitea organization for new repositories every hour. Successful builds of new commits are indicated by a green tick on the commit page. The build status of pull requests is currently not shown in Gitea. However, you can go to the [Jenkins](https://project.nes.uni-due.de/jenkins/job/LocationBasedServices/job/mowesta/) service to view the result of builds including the console output. To modify the build process, you can change the Jenkinsfile groovy script in the root of the repository, if necessary. +# Configuration + +The MoWeSta backend uses a number of system properties to configure the location of input and output folders, the base url of videos and the forecast downlods. You can set them when starting wildfly by passing a ```-DpropretyName=propertyValue``` switch to the standalone.sh. The configurations are: + +- *baseDirectory*: Defines where the input and output folders are placed. Default is working directory. +- *limitedMode*: Defines whether to limit the forecast download to cosmo europe. Default is false. +- *videoUrl*: Define the url to prefix the file names with. Default is https://www.mowesta.com/data/video. diff --git a/service-war/src/main/java/com/mowesta/service/injection/Settings.java b/service-war/src/main/java/com/mowesta/service/injection/Settings.java index 5c75f34e..cb3c6444 100644 --- a/service-war/src/main/java/com/mowesta/service/injection/Settings.java +++ b/service-war/src/main/java/com/mowesta/service/injection/Settings.java @@ -1,18 +1,13 @@ package com.mowesta.service.injection; +import java.io.File; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.naming.InitialContext; -import javax.naming.NamingException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.inject.Produces; -import jakarta.inject.Inject; import jakarta.inject.Qualifier; /** @@ -54,7 +49,7 @@ public class Settings { @Qualifier @Target({ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) - public @interface InfinispanFolder { } + public @interface ForecastFolder { } /** * The annotation to fetch the video base folder. @@ -81,50 +76,36 @@ public class Settings { @Retention(RetentionPolicy.RUNTIME) public @interface LimitPredictions { } + /** + * The system property to access the base directory. + */ + private static final String PROPERTY_BASE_DIRECTORY = "baseDirectory"; /** - * The base folder to store lucene indexes. Note that this folder - * is also contained in the persistence.xml as a property for - * the hibernate search configuration. + * The system property to set the video url. */ - private static final NameValuePair FOLDER_LUCENCE = new NameValuePair<>("java:global/mowesta/folderLucene", "/Users/marcus/Data/mowesta/lucene"); + private static final String PROPERTY_VIDEO_URL = "videoUrl"; /** - * The folder that contains the nominatim data to import. + * The system property to enable the limited predictions mode for testing. */ - private static final NameValuePair FOLDER_NOMINATIM = new NameValuePair<>("java:global/mowesta/folderNominatim", "/Users/marcus/Data/mowesta/nominatim"); + private static final String PROPERTY_LIMITED_MODE = "limitedMode"; /** - * The base folder that contains the data from the dwd that is downloaded - * periodically and imported. + * The default base directory. */ - private static final NameValuePair FOLDER_DWD = new NameValuePair<>("java:global/mowesta/folderDwd", "/Users/marcus/Data/mowesta/dwd"); - + private static final String DEFAULT_BASE_DIRECTORY = "."; + /** - * The base folder that contains the infinispan data cache on the machine. + * The default value for the limited mode. */ - private static final NameValuePair FOLDER_INFINISPAN = new NameValuePair<>("java:global/mowesta/folderInfinispan", "/Users/marcus/Data/mowesta/infinispan"); - + private static final String DEFAULT_LIMITED_MODE = "false"; + /** - * The folder that contains the generated video files. + * The default value for the video url. */ - private static final NameValuePair FOLDER_VIDEO = new NameValuePair<>("java:global/mowesta/folderVideo", "/Users/marcus/Data/mowesta/video"); - - /** - * The base url for videos. - */ - private static final NameValuePair URL_VIDEO = new NameValuePair<>("java:global/mowesta/urlVideo", "https://www.mowesta.com/data/video/"); - - /** - * A boolean flag to limit the amount of predictions to process. - */ - private static final NameValuePair LIMIT_PREDICTIONS = new NameValuePair<>("java:global/mowesta/limitPredictions", Boolean.FALSE); - - /** - * The logger. - */ - @Inject - private Logger logger; + private static final String DEFAULT_VIDEO_URL = "https://www.mowesta.com/data/video"; + /** * Produces the video url. @@ -134,7 +115,7 @@ public class Settings { @Produces @VideoUrl public String getVideoURL() { - return lookup(URL_VIDEO); + return System.getProperty(PROPERTY_VIDEO_URL, DEFAULT_VIDEO_URL); } /** @@ -143,8 +124,10 @@ public class Settings { * @return The infinispan folder. */ @Produces - @InfinispanFolder - public String getInfinispanFolder() { return lookup(FOLDER_INFINISPAN); } + @ForecastFolder + public String getForecastFolder() { + return getFolder("forecast"); + } /** * Produces the lucene folder. @@ -153,7 +136,9 @@ public class Settings { */ @Produces @LuceneFolder - public String getLuceneFolder() { return lookup(FOLDER_LUCENCE); } + public String getLuceneFolder() { + return getFolder("lucene"); + } /** * Produces the video folder. @@ -162,7 +147,7 @@ public class Settings { */ @Produces @VideoFolder - public String getVideoFolder() { return lookup(FOLDER_VIDEO); } + public String getVideoFolder() { return getFolder("video"); } /** * Produces the dwd folder. @@ -171,7 +156,7 @@ public class Settings { */ @Produces @DwdFolder - public String getDwdFolder() { return lookup(FOLDER_DWD); } + public String getDwdFolder() { return getFolder("dwd"); } /** * Produces the nominatim folder. @@ -180,7 +165,7 @@ public class Settings { */ @Produces @NominatimFolder - public String getNominatimFolder() { return lookup(FOLDER_NOMINATIM); } + public String getNominatimFolder() { return getFolder("nominatim"); } /** * A flag to reduce the amount of predictions to process. @@ -191,62 +176,22 @@ public class Settings { */ @Produces @LimitPredictions - public boolean isLimitPredicitons() { return lookup(LIMIT_PREDICTIONS); } - - /** - * Performs a lookup of a name using JNDI and returns - * a value, or the default value if not present. - * - * @param nameValuePair The name value pair. - * @return The value bound to the name or the default value. - * @throws RuntimeException Thrown if something fails. - */ - @SuppressWarnings("unchecked") - private T lookup(NameValuePair nameValuePair) { - try { - InitialContext context = new InitialContext(); - try { - return (T)context.lookup(nameValuePair.name); - } catch (NamingException e) { - // may happen, if name is not bound - } catch (RuntimeException e) { - logger.log(Level.SEVERE, "Found an unexpected data type when resolving " + nameValuePair.name + ". Consider adjusting it."); - } - logger.log(Level.INFO, "Using default value to resolve " + nameValuePair.name + ". Consider setting it explicitly."); - return nameValuePair.value; - } catch (NamingException e) { - throw new RuntimeException("Failed to resolve initial context.", e); - } + public boolean isLimitPredicitons() { + return Boolean.valueOf(System.getProperty(PROPERTY_LIMITED_MODE, DEFAULT_LIMITED_MODE)); } - /** - * An internal class to represent a name with a default value. + * Creates and returns the folder in the base directory. + * + * @param folder The folder. + * @return The absolute path to the folder inside the base directory. */ - private static final class NameValuePair { - /** - * The name. - */ - final String name; - /** - * The value. - */ - final T value; - - /** - * Creates a new name value pair. - * - * @param name The name. - * @param value The value. - */ - private NameValuePair(String name, T value) { - this.name = name; - this.value = value; - } + private String getFolder(String folder) { + File file = new File(System.getProperty(PROPERTY_BASE_DIRECTORY, DEFAULT_BASE_DIRECTORY), folder); + file.mkdirs(); + return file.getAbsolutePath(); } - - - + } diff --git a/service-war/src/main/java/com/mowesta/service/session/CacheSessionBean.java b/service-war/src/main/java/com/mowesta/service/session/CacheSessionBean.java index a6cf5847..676c4602 100644 --- a/service-war/src/main/java/com/mowesta/service/session/CacheSessionBean.java +++ b/service-war/src/main/java/com/mowesta/service/session/CacheSessionBean.java @@ -60,7 +60,7 @@ public class CacheSessionBean { /** * The name of the index. */ - private static final String CACHE_INDEX = "index"; + private static final String INDEX_FORECAST = "forecast"; /** * The logger for debug output. @@ -78,8 +78,8 @@ public class CacheSessionBean { * The folder containing the infinispan caches. */ @Inject - @Settings.InfinispanFolder - protected String infinispanFolder; + @Settings.ForecastFolder + protected String forecastFolder; /** * The folder containing the lucene indexes. @@ -150,7 +150,7 @@ public class CacheSessionBean { .make(); tempCache = temp.hashMap(CACHE_TEMP, Serializer.STRING, Serializer.DOUBLE_ARRAY).create(); try { - index = new ForecastIndex(getLocation(CACHE_INDEX)); + index = new ForecastIndex(getIndexBase(INDEX_FORECAST)); } catch (IOException e) { throw new RuntimeException("Failed to create forecast index.", e); } @@ -164,16 +164,17 @@ public class CacheSessionBean { * @return The file system location. */ protected String getLocation(String cacheName) { - return new File(infinispanFolder, cacheName).getAbsolutePath(); + return new File(forecastFolder, cacheName).getAbsolutePath(); } /** * Returns the base index location for lucene stores. * + * @param name The namee * @return The index base. */ - protected String getIndexBase() { - return new File(luceneFolder).getAbsolutePath(); + protected String getIndexBase(String name) { + return new File(luceneFolder, name).getAbsolutePath(); } /** diff --git a/service-war/src/main/java/com/mowesta/service/session/test/CacheTestBean.java b/service-war/src/main/java/com/mowesta/service/session/test/CacheTestBean.java deleted file mode 100644 index 9475b7f0..00000000 --- a/service-war/src/main/java/com/mowesta/service/session/test/CacheTestBean.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.mowesta.service.session.test; - -import com.mowesta.service.session.CacheSessionBean; - -import jakarta.ejb.Singleton; -import jakarta.enterprise.inject.Alternative; - -/** - * A bean that changes the file system location of - * the infinispan caches and lucene directories for testing. - * - * @author Marcus - */ -@Singleton -@Alternative -public class CacheTestBean extends CacheSessionBean { - - @Override - protected String getIndexBase() { - return "."; - } - - @Override - protected String getLocation(String cacheName) { - return cacheName; - } - -} diff --git a/service-war/src/main/resources/META-INF/persistence.xml b/service-war/src/main/resources/META-INF/persistence.xml index 4e765911..8fedc3bc 100644 --- a/service-war/src/main/resources/META-INF/persistence.xml +++ b/service-war/src/main/resources/META-INF/persistence.xml @@ -31,7 +31,7 @@ - + diff --git a/service-war/src/test/resources/META-INF/beans_rest.xml b/service-war/src/test/resources/META-INF/beans_rest.xml index a56c2f4e..9aa67a7a 100644 --- a/service-war/src/test/resources/META-INF/beans_rest.xml +++ b/service-war/src/test/resources/META-INF/beans_rest.xml @@ -6,7 +6,6 @@ com.mowesta.service.session.test.DataTestBean - com.mowesta.service.session.test.CacheTestBean com.mowesta.service.session.test.EmailTestBean com.mowesta.service.session.test.LocationSyncTestBean com.mowesta.service.session.test.PeriodicSyncTestBean diff --git a/service-war/src/test/resources/META-INF/beans_session.xml b/service-war/src/test/resources/META-INF/beans_session.xml index 4931a3d5..5ca6a9f5 100644 --- a/service-war/src/test/resources/META-INF/beans_session.xml +++ b/service-war/src/test/resources/META-INF/beans_session.xml @@ -6,7 +6,6 @@ com.mowesta.service.session.test.DataTestBean - com.mowesta.service.session.test.CacheTestBean com.mowesta.service.session.test.EmailTestBean com.mowesta.service.session.test.LocationSyncTestBean com.mowesta.service.session.test.PeriodicSyncTestBean diff --git a/service-war/src/test/resources/arquillian.xml b/service-war/src/test/resources/arquillian.xml index a0455bc9..f6d14eec 100644 --- a/service-war/src/test/resources/arquillian.xml +++ b/service-war/src/test/resources/arquillian.xml @@ -13,7 +13,7 @@ 10990 - -Djboss.socket.binding.port-offset=1000 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED + -Djboss.socket.binding.port-offset=1000 -DbaseDirectory=./build/test-workspace --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED ../service-wildfly/wildfly-31.0.1.Final wildfly.xml