diff --git a/README.md b/README.md index a0ea53708c824827a6e08752b3c1bae888836a23..32e3e6a7a128d86ee99cfe558b86c963f333a417 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,14 @@ This application was created by Eike Cochu for his master's degree thesis in com ## Installation -1. If MongoDB or ElasticSearch run on different servers that the JavaEE application server, then the configuration files need to be changed. Change `config.properties` file - 1. in `vipra.war`: Open `vipra.war` in an archive program, navigate to `/WEB-INF/classes` and edit `config.properties` file appropriately. - 2. in `vipra-cmd.jar`: Open `vipra-cmd.jar` and edit `config.properties` file appropriately. - 3. Test connection by running `./vipra -t` -2. Copy `vipra.war` to your JavaEE application server +1. Deploy vipra.war or exploded vipra directory to a Java application server. Deploy to ROOT (/) or a different context path (/vipra, ...) +2. Edit WEB-INF/classes/config.json if MongoDB or ElasticSearch do not run with default configuration (host/port) +3. Deploy vipra-ui to a static webserver +4. Create rewrite rules to rewrite all non-matching files to /index.html +5. If not deployed in root, change /index.html <base> tag to context path +6. Change /js/config.js if the backend was not deployed on the same server, not in root context or if the server has a different port than 8080 + +if everything is left default, application should be available under: http://someserver/ and backend: http://someserver:8080/rest/ ## Development diff --git a/build-config.sh b/build-config.sh new file mode 100755 index 0000000000000000000000000000000000000000..447cfd857988edc8bc2aeb2bb452e1f11be40a81 --- /dev/null +++ b/build-config.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +INCLUDE_FRONTEND_IN_WAR=1 + +# enable/disable (1/0) project building +BUILD_DTM=1 +BUILD_VIPRA_UTIL=1 +BUILD_VIPRA_CMD=1 +BUILD_VIPRA_UI=1 +BUILD_VIPRA_BACKEND=1 \ No newline at end of file diff --git a/build.sh b/build.sh index 110b7c5f3e6444753fea2ff1548ca14f6f617399..7bf4ddf41198fc838d8a9f297352a52ff223d91c 100755 --- a/build.sh +++ b/build.sh @@ -1,18 +1,6 @@ -#!/bin/sh +#!/bin/bash -# point this folder to the webapps dir of your tomcat server for auto deploy -TOMCAT_WEBAPPS="vm/webapps" - -# enable/disable (1/0) project building -BUILD_DTM=1 -BUILD_VIPRA_UTIL=1 -BUILD_VIPRA_CMD=1 -BUILD_VIPRA_UI=1 -BUILD_VIPRA_BACKEND=1 - -# enable to deploy frontend assets in vipra.war -# disable if you want to serve frontend assets from another server -INCLUDE_FRONTEND_IN_WAR=1 +source ./build-config.sh # ========================================================= # DO NOT EDIT AFTER THIS POINT @@ -139,18 +127,5 @@ else fi fi -# deploy backend war - -VIPRA_WAR="vipra-backend/target/vipra.war" - -echo "" >> $LOG -echo "-------------------------------" >> $LOG -if [ -d $TOMCAT_WEBAPPS ] && [ -f $VIPRA_WAR ]; then - echo "deploying vipra-backend" | tee -a $LOG - cp $VIPRA_WAR $TOMCAT_WEBAPPS -else - echo "deploying vipra-backend > skipped" | tee -a $LOG -fi - echo "complete" exit $? diff --git a/docker/Dockerfile b/docker/Dockerfile index b9c0fbfab68a424d85b60cb6bc158efa33fadf9b..cd360765e5ce64635d1f4b4a717be37376f07bd5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,11 +3,13 @@ MAINTAINER Eike Cochu <eike@cochu.com> ENV ES_VERSION 2.3.1 ENV TOMCAT_MAJOR 8 ENV TOMCAT_VERSION 8.0.33 -RUN apt-get update && \ - apt-get install -y wget nano openjdk-8-jdk mongodb supervisor && \ +RUN echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu wily main" >> /etc/apt/sources.list && \ + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C && \ + apt-get update && \ + apt-get install -y --no-install-recommends wget nano openjdk-8-jdk mongodb supervisor nginx && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ - mkdir -p /var/log/supervisor /data/db && \ + mkdir -p /webroot /var/log/supervisor /data/db && \ wget --no-check-certificate -O- https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$ES_VERSION/elasticsearch-$ES_VERSION.tar.gz | tar xvfz - && \ mv elasticsearch-$ES_VERSION elasticsearch && \ wget -O- http://apache.openmirror.de/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz | tar xvfz - && \ @@ -15,6 +17,6 @@ RUN apt-get update && \ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY tomcat-users.xml /tomcat/conf/tomcat-users.xml COPY elasticsearch.yml /elasticsearch/config/elasticsearch.yml -COPY vipra.war /tomcat/webapps/vipra.war -EXPOSE 8080 9200 9300 27017 +COPY nginx.conf /etc/nginx/nginx.conf +EXPOSE 80 8080 9200 9300 27017 CMD ["/usr/bin/supervisord"] \ No newline at end of file diff --git a/docker/docker-build.sh b/docker/docker-build.sh index fd1787c89ee9d3fee67ecf57e5df96734694214c..6b37c7c17e896e01110453930a2fff7a07fb863a 100755 --- a/docker/docker-build.sh +++ b/docker/docker-build.sh @@ -1,13 +1,4 @@ #!/bin/sh -VIPRA_WAR="../vipra-backend/target/vipra.war" - -if [ ! -f $VIPRA_WAR ]; then - echo "vipra.war not found. Did you run build.sh?" - exit 1 -fi - -cp $VIPRA_WAR . docker build -t eikecochu/vipra . -rm vipra.war exit 0 \ No newline at end of file diff --git a/docker/docker-run.sh b/docker/docker-run.sh index d7680269c28e136e79c14dfd07737114dafb5315..d241c7258fdf9129d74e80fb214aa3ffe6660240 100755 --- a/docker/docker-run.sh +++ b/docker/docker-run.sh @@ -1,8 +1,11 @@ #!/bin/sh +HOST_NGINX=80 HOST_TOMCAT=8080 HOST_ELASTICSEARCH_REST=9200 HOST_ELASTICSEARCH_API=9300 HOST_MONGODB=27017 -docker run -d -p $HOST_TOMCAT:8080 -p $HOST_ELASTICSEARCH_REST:9200 -p $HOST_ELASTICSEARCH_API:9300 -p $HOST_MONGODB:27017 eikecochu/vipra \ No newline at end of file +DIR="$(dirname "$(readlink -f "$0")")" + +docker run -d -p $HOST_NGINX:80 -p $HOST_TOMCAT:8080 -p $HOST_ELASTICSEARCH_REST:9200 -p $HOST_ELASTICSEARCH_API:9300 -p $HOST_MONGODB:27017 -v $DIR/webroot:/webroot -v $DIR/webapps:/tomcat/webapps eikecochu/vipra \ No newline at end of file diff --git a/docker/supervisord.conf b/docker/supervisord.conf index d2cc713bad9668bf0f1da9a922889ed5dead7c13..f46a37ab7e97f81ec30b27d3203a063cbd987f62 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -16,4 +16,9 @@ environment=CATALINA_HOME="/tomcat",CATALINA_BASE="/tomcat",CATALINA_TMPDIR="/to command=/tomcat/bin/catalina.sh run autostart=true autorestart=true -startsecs=10 \ No newline at end of file +startsecs=10 + +[program:nginx] +command=/usr/sbin/nginx +autostart=true +autorestart=true \ No newline at end of file diff --git a/docker/webapps/.gitkeep b/docker/webapps/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/docker/webroot/.gitkeep b/docker/webroot/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/vipra-backend/src/main/webapp/WEB-INF/web.xml b/vipra-backend/src/main/webapp/WEB-INF/web.xml index 90ba036b82b59a102580eca5ef485dd6858e74c4..da89b35de944060a099ff17a206f8e391abc82c3 100644 --- a/vipra-backend/src/main/webapp/WEB-INF/web.xml +++ b/vipra-backend/src/main/webapp/WEB-INF/web.xml @@ -3,9 +3,6 @@ xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> - <welcome-file-list> - <welcome-file>public/index.html</welcome-file> - </welcome-file-list> <servlet> <servlet-name>jersey</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> diff --git a/vipra-cmd/runcfg/CMD.launch b/vipra-cmd/runcfg/CMD.launch index 234953e3ee083855962a2fe7b1aef2f4b5162ba1..b86e653f24302a285881641370a4b79b898294ce 100644 --- a/vipra-cmd/runcfg/CMD.launch +++ b/vipra-cmd/runcfg/CMD.launch @@ -11,7 +11,7 @@ </listAttribute> <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.vipra.cmd.Main"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-S test -M"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-C yearly"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="vipra-cmd"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> diff --git a/vipra-cmd/src/main/java/de/vipra/cmd/option/EditModelCommand.java b/vipra-cmd/src/main/java/de/vipra/cmd/option/EditModelCommand.java index 44552463a7610c451ddde49d155a9795080c6c6e..11c2c87e98881a07246a9d4543575e2bc5cd87f5 100644 --- a/vipra-cmd/src/main/java/de/vipra/cmd/option/EditModelCommand.java +++ b/vipra-cmd/src/main/java/de/vipra/cmd/option/EditModelCommand.java @@ -1,9 +1,15 @@ package de.vipra.cmd.option; +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; + import de.vipra.util.Config; import de.vipra.util.ConsoleUtils; import de.vipra.util.Constants.ProcessorMode; import de.vipra.util.Constants.WindowResolution; +import de.vipra.util.ex.ConfigException; import de.vipra.util.ex.DatabaseException; import de.vipra.util.model.TopicModelConfig; import de.vipra.util.model.TopicModelFull; @@ -12,13 +18,15 @@ import de.vipra.util.service.MongoService; public class EditModelCommand implements Command { private final String[] names; + private Config config; private MongoService<TopicModelFull, String> dbTopicModels; public EditModelCommand(final String[] names) { this.names = names; } - private void editModel(final TopicModelConfig topicModelConfig) throws DatabaseException { + private void editModel(final TopicModelConfig topicModelConfig) + throws DatabaseException, JsonGenerationException, JsonMappingException, IOException, ConfigException { ConsoleUtils.info("editing model: " + topicModelConfig.getName()); topicModelConfig.setDescription(ConsoleUtils.readString("description (↲ to skip)", topicModelConfig.getDescription(), true)); topicModelConfig.setkTopics(ConsoleUtils.readInt("k topics", topicModelConfig.getkTopics(), 1, null, true)); @@ -50,11 +58,12 @@ public class EditModelCommand implements Command { final TopicModelFull topicModel = new TopicModelFull(topicModelConfig.getName()); topicModel.setModelConfig(topicModelConfig); dbTopicModels.updateSingle(topicModel, "modelConfig"); + topicModelConfig.saveToFile(topicModelConfig.getModelDir(config.getDataDirectory())); } @Override public void run() throws Exception { - final Config config = Config.getConfig(); + config = Config.getConfig(); dbTopicModels = MongoService.getDatabaseService(config, TopicModelFull.class); for (final String name : names) { diff --git a/vipra-ui/README.md b/vipra-ui/README.md index 762d63e339bdb66fc3a5a9a6bcfdeff222f71b6e..333bb4deb5ad6983ff75c476c58c9128e766552f 100644 --- a/vipra-ui/README.md +++ b/vipra-ui/README.md @@ -1,3 +1,42 @@ # Vipra UI -The frontend UI project. \ No newline at end of file +The frontend UI project. Built with AngularJS and many other Javascript and CSS frameworks and libraries: + +* [AngularJS](https://github.com/angular/angular.js) by Google (MIT) +* [Angular Hotkeys](https://github.com/chieffancypants/angular-hotkeys) by Wes Cruver (MIT) +* [AngularUI Router](https://github.com/angular-ui/ui-router) by The AngularUI Team, Karsten Sperling (MIT) +* [jQuery](https://github.com/jquery/jquery) by the jQuery Foundation and other contributors (MIT) +* [Bootstrap](https://github.com/twbs/bootstrap) by Twitter (MIT) +* [bootstrap-datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker) by Jonathan Peterson (MIT) +* [nya-bootstrap-select](https://github.com/lordfriend/nya-bootstrap-select) by Nyasoft (MIT) +* [Bootbox.js](https://github.com/makeusabrew/bootbox) by Nick Payne (MIT) +* [Highcharts](http://www.highcharts.com/) by Highsoft (CC-BY-NC) +* [vis.js](https://github.com/almende/vis) by Almende B.V. (MIT) +* [Moment.js](https://github.com/moment/moment) by Tim Wood, Iskren Chernev, Moment.js contributors (MIT) +* [randomColor](https://github.com/davidmerfield/randomColor) by David Merfield (CC0 1.0) +* [FontAwesome](https://github.com/FortAwesome/Font-Awesome) by Dave Gandy (SIL OFL 1.1/MIT) +* [Bower](https://github.com/bower/bower) by Twitter and other contributors (MIT) +* [Gulp](https://github.com/gulpjs/gulp) by Fractal (MIT) +* [gulp-less](https://github.com/plus3network/gulp-less) by Plus 3 Network (MIT) +* [gulp-concat](https://github.com/contra/gulp-concat) by Fractal (MIT) +* [gulp-uglify](https://github.com/terinjokes/gulp-uglify) by Terin Stock (MIT) +* [gulp-clean-css](https://github.com/scniro/gulp-clean-css) by scniro (MIT) +* [gulp-webserver](https://github.com/schickling/gulp-webserver) by Johannes Schickling (MIT) +* [gulp-ng-annotate](https://github.com/Kagami/gulp-ng-annotate) by Kagami Hiiragi and contributors (CC0 1.0) +* [gulp-templatecache](https://github.com/miickel/gulp-angular-templatecache) by Mickel (MIT) + +## Installation + +### Base path + +Simply put all files into a static web server document root. + +If the application is not deployed into a web root (/), change the base tag in the file `index.html` +```html +<base href="/somepath" /> +``` +the href value has to be the same under which the application should be available, e.g. http://someserver/somepath/index.html. + +### Backend connection + +The backend is expected to be deployed to a Java application server. To change the default REST URL, edit the file `js/config.js` \ No newline at end of file diff --git a/vipra-ui/app/index.html b/vipra-ui/app/index.html index 925f65b3f405b70c0fef95a297ccad5ee14bcdd6..caafc504d81922d028baab9c9f70763d6d0e6cf9 100644 --- a/vipra-ui/app/index.html +++ b/vipra-ui/app/index.html @@ -29,6 +29,7 @@ <link href="css/app.css" rel="stylesheet"> <!-- javascript --> <script src="js/vendor.js"></script> + <script src="js/config.js"></script> <script src="js/app.js"></script> <script src="js/templates.js"></script> </head> diff --git a/vipra-ui/app/js/config.js b/vipra-ui/app/js/config.js index f61fc16ea5ecffcd36fd019fc9c0f13511b3a98a..e3005dd5c29e24be9890a689abbd6d6d3086339c 100644 --- a/vipra-ui/app/js/config.js +++ b/vipra-ui/app/js/config.js @@ -10,7 +10,16 @@ window.Vipra = window.Vipra || {}; Vipra.config = { - restUrl: '/vipra/rest' + /* + * Point this URL to the backend REST servlet. The default is /rest, which expects the servlet + * to be deployed in the root context. If the servlet is deployed under another context, prepend + * it to this URL. Test the URL by entering this into a browser: + * + * http://yourserver[/rest]/application.wadl + * ^^^^^ + * this is the restUrl + */ + restUrl: '//' + location.hostname + ':8080/rest' }; })(); \ No newline at end of file diff --git a/vipra-ui/gulpfile.js b/vipra-ui/gulpfile.js index 1ab3e2c9014c7054d1b92378e6d668157e87aef4..9f8e6da50ca7f17b34422d683b204b313eeb77ed 100644 --- a/vipra-ui/gulpfile.js +++ b/vipra-ui/gulpfile.js @@ -52,18 +52,20 @@ gulp.task('less', function() { }); gulp.task('js', function() { - gulp.src('app/js/**/*.js') + gulp.src(['app/js/**/*.js', '!app/js/config.js']) .pipe(concat('app.js')) .pipe(ngannotate()) - //.pipe(uglify()) + .pipe(gulp.dest('public/js')); + gulp.src('app/js/config.js') .pipe(gulp.dest('public/js')); }); gulp.task('js-rel', function() { - gulp.src(['app/js/**/*.js', '!app/js/dev.js']) + gulp.src(['app/js/**/*.js', '!app/js/config.js', '!app/js/dev.js']) .pipe(concat('app.js')) .pipe(ngannotate()) - //.pipe(uglify()) + .pipe(gulp.dest('public/js')); + gulp.src('app/js/config.js') .pipe(gulp.dest('public/js')); }); diff --git a/vipra-util/src/main/java/de/vipra/util/model/TopicModelConfig.java b/vipra-util/src/main/java/de/vipra/util/model/TopicModelConfig.java index 1f116b4f3a199463055f77bc83831c2dc63a70ea..7e8424012bd4bde153fa8b6d69d7242ce65aecdc 100644 --- a/vipra-util/src/main/java/de/vipra/util/model/TopicModelConfig.java +++ b/vipra-util/src/main/java/de/vipra/util/model/TopicModelConfig.java @@ -1,7 +1,6 @@ package de.vipra.util.model; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; @@ -231,9 +230,9 @@ public class TopicModelConfig implements Serializable { public static TopicModelConfig readFromFile(final File modelDir) throws JsonParseException, JsonMappingException, IOException { final File file = new File(modelDir, FILE_NAME); - if (!file.exists()) - throw new FileNotFoundException(file.getAbsolutePath()); - return Config.mapper.readValue(file, TopicModelConfig.class); + if (file.exists()) + return Config.mapper.readValue(file, TopicModelConfig.class); + return new TopicModelConfig(); } @Override