This is an automated email from the git hooks/post-receive script. New commit to branch develop-1.0.x in repository coselmar. See http://git.codelutin.com/coselmar.git commit 968265128f2f57756e820bbe3f2bc9fafd1a8789 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 18 17:22:04 2015 +0100 fixes #7845 Add a health page to controle application status --- .../coselmar/config/CoselmarServicesConfig.java | 4 ++ .../config/CoselmarServicesConfigOption.java | 5 ++ .../java/fr/ifremer/coselmar/beans/HealthBean.java | 49 ++++++++++++++++++++ .../coselmar/services/v1/HealthService.java | 54 ++++++++++++++++++++++ coselmar-rest/src/main/resources/mapping | 5 +- coselmar-ui/src/main/webapp/health.html | 30 ++++++++++++ coselmar-ui/src/main/webapp/js/coselmar-health.js | 37 +++++++++++++++ 7 files changed, 183 insertions(+), 1 deletion(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfig.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfig.java index d3fa398..8e72e04 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfig.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfig.java @@ -158,4 +158,8 @@ public class CoselmarServicesConfig { public String getEncryptionAlgorithm() { return "SHA-256"; } + + public String getVersion() { + return applicationConfig.getOption(CoselmarServicesConfigOption.APPLICATION_VERSION.key); + } } diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfigOption.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfigOption.java index 8cd0a9f..97f6208 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfigOption.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/config/CoselmarServicesConfigOption.java @@ -80,6 +80,11 @@ public enum CoselmarServicesConfigOption implements ConfigOptionDef { "coselmar.web.security.key", "Clef de sécurity permettant d'encoder les token d'authentication", "iamageek,r3477y", String.class), + + APPLICATION_VERSION( + "coselmar.version", + "Version de l'application", + "", String.class), ; protected final String key; diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/HealthBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/HealthBean.java new file mode 100644 index 0000000..fa90591 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/HealthBean.java @@ -0,0 +1,49 @@ +package fr.ifremer.coselmar.beans; + +import java.io.Serializable; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class HealthBean implements Serializable { + + protected boolean dbUp; + + protected String version; + + protected boolean indexationUp; + + protected boolean devMode; + + public boolean isDbUp() { + return dbUp; + } + + public void setDbUp(boolean dbUp) { + this.dbUp = dbUp; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public boolean isIndexationUp() { + return indexationUp; + } + + public void setIndexationUp(boolean indexationUp) { + this.indexationUp = indexationUp; + } + + public boolean isDevMode() { + return devMode; + } + + public void setDevMode(boolean devMode) { + this.devMode = devMode; + } +} diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/HealthService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/HealthService.java new file mode 100644 index 0000000..8415042 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/HealthService.java @@ -0,0 +1,54 @@ +package fr.ifremer.coselmar.services.v1; + +import fr.ifremer.coselmar.beans.HealthBean; +import fr.ifremer.coselmar.beans.QuestionSearchBean; +import fr.ifremer.coselmar.persistence.entity.Privacy; +import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; +import fr.ifremer.coselmar.services.indexation.QuestionsIndexationService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class HealthService extends CoselmarWebServiceSupport { + + private static final Log log = LogFactory.getLog(HealthService.class); + + public HealthBean getHealth() { + String version = getCoselmarServicesConfig().getVersion(); + boolean devMode = getCoselmarServicesConfig().isDevMode(); + + boolean dbUp = false; + try { + getQuestionDao().count(); + dbUp = true; + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Error during QuestionDao call", e); + } + } + + boolean indexationUp = false; + QuestionsIndexationService questionsIndexationService = getServicesContext().newService(QuestionsIndexationService.class); + try { + QuestionSearchBean searchBean = new QuestionSearchBean(); + searchBean.setPrivacy(Privacy.PUBLIC.name()); + questionsIndexationService.searchQuestion(searchBean); + indexationUp = true; + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Error during Indexation service call", e); + } + } + + HealthBean healthBean = new HealthBean(); + healthBean.setVersion(version); + healthBean.setDbUp(dbUp); + healthBean.setIndexationUp(indexationUp); + healthBean.setDevMode(devMode); + return healthBean; + } + +} diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index ec66430..a85d118 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -64,4 +64,7 @@ POST /v1/questions QuestionsWebService.addQuestion DELETE /v1/questions/{questionId} QuestionsWebService.deleteQuestion # Admin API -POST /v1/admin/lucene/index AdminWebService.refreshLuceneIndex \ No newline at end of file +POST /v1/admin/lucene/index AdminWebService.refreshLuceneIndex +# Health + +GET /v1/health HealthService.getHealth \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/health.html b/coselmar-ui/src/main/webapp/health.html new file mode 100644 index 0000000..235d109 --- /dev/null +++ b/coselmar-ui/src/main/webapp/health.html @@ -0,0 +1,30 @@ +<html ng-app="coselmarApp" ng-controller="HealthCtrl"> + +<head> + <meta charset="utf-8" /> + <title>Coselmar Health Page</title> + <script src="webjars/angularjs/1.3.13/angular.js"></script> + <script> + var coselmarApp = angular.module("coselmarApp", []); + </script> + <script src="js/coselmar-constants.js"></script> + <script src="js/coselmar-health.js"></script> +</head> + +<body> + + <div id="main-container"> + <h1>Health Page</h1> + <div> + <ul> + <li>Version : {{health.version}}</li> + <li>Database connexion : {{health.dbUp}}</li> + <li>Indexation connexion : {{health.indexationUp}}</li> + <li>Dev Mode : {{health.devMode}}</li> + </ul> + </div> + </div> + + +</body> +</html> \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/js/coselmar-health.js b/coselmar-ui/src/main/webapp/js/coselmar-health.js new file mode 100644 index 0000000..38abd75 --- /dev/null +++ b/coselmar-ui/src/main/webapp/js/coselmar-health.js @@ -0,0 +1,37 @@ +/* + * #%L + * Coselmar :: UI + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2014 Ifremer, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +coselmarApp.controller("HealthCtrl", ['$scope', '$http', 'coselmar-config', function ($scope, $http, coselmarConfig) { + + $scope.health = {"dbUp": false, "version": "unknown", "indexationUp": false, "devMode": false}; + + var healthUrl = coselmarConfig.BASE_URL + "/health"; + + $http.get(healthUrl).then(function(result) { + console.log(result); + $scope.health = result.data; + }); + + +}]); \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.