diff --git a/README.md b/README.md index f2d7d5aaf6127c092136c9864f0bc68e7c1a720d..b3ed4d8119c3030431c2edd34ed1c324973de429 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,25 @@ Directories - `/src/ulo-rdf4j`: Script for generating `ULO.java` which contains constants for use with RDF4J. + +Configuration +------------- + +The `src/ulo-storage-applications` web interface listens on +`0.0.0.0:7400`. If you wish to change this, you can set the +environment variables + +* `ULOAPPS_LISTEN_HOST` for the host, e.g. `localhost` or some IP + address. + +* `ULOAPPS_LISTEN_PORT` for the port number, e.g. 7200 or 1234. + +`ulo-storage-applications` needs a reachable GraphDB instance to +connect to. Configure that instance with the following two environment +variables. + +* `ULOAPPS_REMOTE_SERVER` is the GraphDB server URL, + e.g. `http://graphdb:7300`. + +* `ULOAPPS_REMOTE_REPOSITORY` is the name of the GraphDB repository to + connect to. diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index b5a8b4509f8311293781fb0bc14ea3cbf6762dcd..d2b72380e21b6bead6dba451f89465c393493364 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -17,9 +17,7 @@ services: uloapps: image: "schaertl/uloapps:latest" environment: - - ULO_SERVER=http://ulographdb:7200 - # We use the "compose" repository for demo applications. - # Keep that in mind when importing into GraphDB. - - ULO_REPOSITORY=compose + - ULOAPPS_REMOTE_SERVER=http://ulographdb:7200 + - ULOAPPS_REMOTE_REPOSITORY=compose ports: - 7400:7400 diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/config/Config.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/config/Config.java index 32d585efe85c694a81801b83dcc059d357944ed8..b552966b4f1753675dd9f6eb910cbb24f11268d8 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/config/Config.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/config/Config.java @@ -11,12 +11,40 @@ public class Config { private Config() {}; - public static String serverUrl() { - return Config.get("ULO_SERVER", "info.mathhub.uloapi.config.serverurl"); + /** + * @return The URL of the remote GraphDB instance. + */ + public static String remoteServerUrl() { + return Config.get("ULOAPPS_REMOTE_SERVER", "info.mathhub.uloapi.config.serverurl"); + } + + /** + * @return The repository on the remote GraphDB instance to connect to. + */ + public static String remoteRepository() { + return Config.get("ULOAPPS_REMOTE_REPOSITORY", "info.mathhub.uloapi.config.repository"); + } + + /** + * @return The hostname our web interface should listen on. + */ + public static String getListenHostname() { + return Config.get("ULOAPPS_LISTEN_HOST", "info.mathhub.uloapi.config.listenhost"); } - public static String repository() { - return Config.get("ULO_REPOSITORY", "info.mathhub.uloapi.config.repository"); + /** + * @return The port our web interface should listen on. + */ + public static int getListenPort() { + final String port = Config.get("ULOAPPS_LISTEN_PORT", "info.mathhub.uloapi.config.listenport"); + + try { + return Integer.parseInt(port); + } catch (NumberFormatException e) { + log.error(e.getMessage()); + System.exit(1); + return -1; // never reached + } } /** @@ -41,7 +69,7 @@ public class Config { return environmentValue; } - log.info("could not read environment variable {}, falling back to configuration file", environmentKey); + log.info("could not read environment variable {}, falling back to hard coded configuration file", environmentKey); // try to read the configuration from the configuration file; // this is useful when debugging and running this application as diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Main.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Main.java index 0257e6783da17cb285d7663e521ec57f99572b10..7ac50a8bbdeb2d8ce66c429aa9ca5803b8655fd3 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Main.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Main.java @@ -1,5 +1,6 @@ package info.mathhub.uloapi.html; +import info.mathhub.uloapi.config.Config; import spark.template.freemarker.FreeMarkerEngine; import static spark.Spark.*; @@ -11,7 +12,8 @@ public class Main { private Main() {}; public static void main(String[] args) { - port(7400); + ipAddress(Config.getListenHostname()); + port(Config.getListenPort()); get("/", Routes.index, new FreeMarkerEngine()); get("/statistics", Routes.statistics, new FreeMarkerEngine()); diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java index c0c282f2b3552cf2a2891ac5a0b31bdda13cd8e2..2da8b760d0cc7ec01bc9f4319ee5217d075ae046 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/html/Routes.java @@ -107,10 +107,10 @@ public class Routes { model = new HashMap<>(); } - final String serverUrl = Config.serverUrl(); + final String serverUrl = Config.remoteServerUrl(); model.put("global_server_url", serverUrl); - final String repository = Config.repository(); + final String repository = Config.remoteRepository(); model.put("global_repository", repository); final String hostname = Routes.getHostname(); diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/GraphDB.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/GraphDB.java index 8ad8e4d60e400b2634ee72dc7c9d85de96e77f15..6e856b7092b344a906f6a38c0b41dfdf2ac84da0 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/GraphDB.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/GraphDB.java @@ -1,12 +1,6 @@ package info.mathhub.uloapi.query; import info.mathhub.uloapi.config.Config; -import org.apache.http.Header; -import org.apache.http.HttpHeaders; -import org.apache.http.HttpHost; -import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicHeader; import org.eclipse.rdf4j.repository.Repository; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryException; @@ -70,8 +64,8 @@ public class GraphDB { * @throws RepositoryException If communication with the remote database fails. */ public static <T> T execute(Operation<T> op) { - final String serverUrl = Config.serverUrl(); - final String repositoryName = Config.repository(); + final String serverUrl = Config.remoteServerUrl(); + final String repositoryName = Config.remoteRepository(); return GraphDB.execute(serverUrl, repositoryName, op); } diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java index 118db8b41510d7895f36720be4e99582e2f35d93..d949d0e0cd5ede76cbb8c3a7671d7365102ef24e 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Query.java @@ -40,7 +40,7 @@ public class Query { */ public static synchronized Query getSingleton() { if (Query.singleton == null) { - Query.singleton = new Query(Config.serverUrl(), Config.repository()); + Query.singleton = new Query(Config.remoteServerUrl(), Config.remoteRepository()); } return Query.singleton; diff --git a/src/ulo-storage-applications/src/main/resources/uloapi.properties b/src/ulo-storage-applications/src/main/resources/uloapi.properties index a7b5c951f4c44f08fa3e491681d2d143a75450f4..8925489a0836aeb9e9a50faea68baef2010bce69 100644 --- a/src/ulo-storage-applications/src/main/resources/uloapi.properties +++ b/src/ulo-storage-applications/src/main/resources/uloapi.properties @@ -1,2 +1,7 @@ +# Our Listen Address +info.mathhub.uloapi.config.listenhost=0.0.0.0 +info.mathhub.uloapi.config.listenport=7400 + +# Remote Server Configuration info.mathhub.uloapi.config.serverurl=http://rdf:7200 -info.mathhub.uloapi.config.repository=fckw \ No newline at end of file +info.mathhub.uloapi.config.repository=fckw diff --git a/src/ulo-storage-collect b/src/ulo-storage-collect deleted file mode 160000 index f4ba1ff678a074037cd0df5112079e2889ba525a..0000000000000000000000000000000000000000 --- a/src/ulo-storage-collect +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f4ba1ff678a074037cd0df5112079e2889ba525a