diff --git a/grails-app/controllers/io/xh/hoist/impl/HoistImplController.groovy b/grails-app/controllers/io/xh/hoist/impl/HoistImplController.groovy index 446f94a5..1092802d 100644 --- a/grails-app/controllers/io/xh/hoist/impl/HoistImplController.groovy +++ b/grails-app/controllers/io/xh/hoist/impl/HoistImplController.groovy @@ -125,9 +125,11 @@ class HoistImplController extends BaseController { //------------------------ def environment() { def ret = [ + appCode: Utils.appCode, + appName: Utils.appName, + appVersion: Utils.appVersion, appEnvironment: Utils.appEnvironment, supportedEnvironments: Utils.supportedEnvironments, - appVersion: Utils.appVersion, grailsVersion: GrailsUtil.grailsVersion, javaVersion: System.getProperty('java.version') ] diff --git a/grails-app/services/io/xh/hoist/clienterror/ClientErrorEmailService.groovy b/grails-app/services/io/xh/hoist/clienterror/ClientErrorEmailService.groovy index aef78724..5069b13b 100644 --- a/grails-app/services/io/xh/hoist/clienterror/ClientErrorEmailService.groovy +++ b/grails-app/services/io/xh/hoist/clienterror/ClientErrorEmailService.groovy @@ -25,7 +25,7 @@ class ClientErrorEmailService extends BaseService { //------------------------- private void emailClientException(ClientError ce) { def to = emailService.parseMailConfig('xhEmailSupport'), - subject = "${Utils.appName.capitalize()} feedback" + subject = "${Utils.appName} feedback" if (to) { emailService.sendEmail(async: true, to: to, subject: subject, html: formatHtml(ce)) } @@ -36,7 +36,7 @@ class ClientErrorEmailService extends BaseService { errorText = ce.error, metaText = [ "User: ${ce.username}", - "App: ${Utils.appName}", + "App: ${Utils.appName} (${Utils.appCode})", "Version: ${ce.appVersion}", "Environment: ${ce.appEnvironment}", "Browser: ${ce.browser}", diff --git a/grails-app/services/io/xh/hoist/feedback/FeedbackEmailService.groovy b/grails-app/services/io/xh/hoist/feedback/FeedbackEmailService.groovy index 7cfcbd95..8f655ec5 100644 --- a/grails-app/services/io/xh/hoist/feedback/FeedbackEmailService.groovy +++ b/grails-app/services/io/xh/hoist/feedback/FeedbackEmailService.groovy @@ -25,7 +25,7 @@ class FeedbackEmailService extends BaseService { //------------------------ private void emailFeedback(Feedback fb) { def to = emailService.parseMailConfig('xhEmailSupport'), - subject = "${Utils.appName.capitalize()} feedback" + subject = "${Utils.appName} feedback" if (to) { emailService.sendEmail(async: true, to: to, subject: subject, html: formatHtml(fb)) @@ -36,7 +36,7 @@ class FeedbackEmailService extends BaseService { def msgText = fb.msg, metaText = [ "User: ${fb.username}", - "App: ${Utils.appName}", + "App: ${Utils.appName} (${Utils.appCode})", "Version: ${fb.appVersion}", "Environment: ${fb.appEnvironment}", "Browser: ${fb.browser}", diff --git a/grails-app/services/io/xh/hoist/monitor/MonitoringEmailService.groovy b/grails-app/services/io/xh/hoist/monitor/MonitoringEmailService.groovy index 41b23ce6..957e8387 100644 --- a/grails-app/services/io/xh/hoist/monitor/MonitoringEmailService.groovy +++ b/grails-app/services/io/xh/hoist/monitor/MonitoringEmailService.groovy @@ -37,13 +37,12 @@ class MonitoringEmailService extends BaseService { } private String formatHtml(MonitorStatusReport report) { - def results = report.results, - appName = Utils.appDisplayName + def results = report.results results.sort{it.name} results.sort{it.status} - if (report.status < WARN) return "There are no alerting monitors for $appName." + if (report.status < WARN) return "There are no alerting monitors for ${Utils.appName}." return results.findAll{it.status >= WARN}.collect { "+ $it.name: $it.message. Minutes in [$it.status]: ${it.minsInStatus}" diff --git a/src/main/groovy/io/xh/hoist/AppEnvironment.groovy b/src/main/groovy/io/xh/hoist/AppEnvironment.groovy index 81366271..42f64ac1 100644 --- a/src/main/groovy/io/xh/hoist/AppEnvironment.groovy +++ b/src/main/groovy/io/xh/hoist/AppEnvironment.groovy @@ -12,8 +12,10 @@ import io.xh.hoist.json.JSONFormat /** * Enum describing available application deployment environments. - * Note this is distinct from the built-in Grails notion of Environments as there may be multiple non-production - * app instances (e.g., Development, Beta) that all run in Grails "production" mode on their respective servers. + * + * Note this is distinct from the built-in Grails notion of Environments as there may be multiple + * non-production app instances (e.g., Development, Beta) that all run in Grails "production" mode + * on their respective servers. */ @CompileStatic enum AppEnvironment implements JSONFormat { diff --git a/src/main/groovy/io/xh/hoist/log/LogUtils.groovy b/src/main/groovy/io/xh/hoist/log/LogUtils.groovy index 86b4d4cf..e28b834f 100644 --- a/src/main/groovy/io/xh/hoist/log/LogUtils.groovy +++ b/src/main/groovy/io/xh/hoist/log/LogUtils.groovy @@ -45,7 +45,7 @@ class LogUtils { def tomcatHomeDir = System.getProperty('catalina.base', ''), logSubDir = tomcatHomeDir ? 'logs' : '' - _logRootPath = Paths.get(tomcatHomeDir, logSubDir, "${Utils.appName}-logs").toString() + _logRootPath = Paths.get(tomcatHomeDir, logSubDir, "${Utils.appCode}-logs").toString() } } return _logRootPath @@ -84,7 +84,7 @@ class LogUtils { static void initConfig(Script script) { withDelegate(script) { - def appLogName = Utils.appName + def appLogName = Utils.appCode //---------------------------------- // Appenders diff --git a/src/main/groovy/io/xh/hoist/monitor/MonitorStatusReport.groovy b/src/main/groovy/io/xh/hoist/monitor/MonitorStatusReport.groovy index 8b2b1c2f..22fb43b4 100644 --- a/src/main/groovy/io/xh/hoist/monitor/MonitorStatusReport.groovy +++ b/src/main/groovy/io/xh/hoist/monitor/MonitorStatusReport.groovy @@ -20,11 +20,10 @@ class MonitorStatusReport { } String getTitle() { - def appName = Utils.appDisplayName, - failsCount = results.count{it.status == FAIL}, + def failsCount = results.count{it.status == FAIL}, warnsCount = results.count{it.status == WARN}, okCount = results.count{it.status == OK}, - title = "${appName}: ", + title = "${Utils.appName}: ", msgParts = [] if (!warnsCount && !failsCount) msgParts.push('All clear') diff --git a/src/main/groovy/io/xh/hoist/util/InstanceConfigUtils.groovy b/src/main/groovy/io/xh/hoist/util/InstanceConfigUtils.groovy index 63a7a2c6..47ec5d3e 100644 --- a/src/main/groovy/io/xh/hoist/util/InstanceConfigUtils.groovy +++ b/src/main/groovy/io/xh/hoist/util/InstanceConfigUtils.groovy @@ -53,7 +53,7 @@ class InstanceConfigUtils { // Attempt to load external config file - but do not require one. try { - def configFilename = System.getProperty('io.xh.hoist.instanceConfigFile') ?: "/etc/hoist/conf/${Utils.appName}.yml", + def configFilename = System.getProperty('io.xh.hoist.instanceConfigFile') ?: "/etc/hoist/conf/${Utils.appCode}.yml", configFile = new File(configFilename) if (configFile.exists()) { diff --git a/src/main/groovy/io/xh/hoist/util/Utils.groovy b/src/main/groovy/io/xh/hoist/util/Utils.groovy index 8fc6ee4f..0695204f 100644 --- a/src/main/groovy/io/xh/hoist/util/Utils.groovy +++ b/src/main/groovy/io/xh/hoist/util/Utils.groovy @@ -24,26 +24,38 @@ class Utils { static Properties buildInfo = readBuildInfo() - static AppEnvironment getAppEnvironment() { - return InstanceConfigUtils.appEnvironment + /** + * Internal short name of the application - lowercase, no spaces. + */ + static String getAppCode() { + return buildInfo.getProperty('info.xh.appCode') } - static Set getSupportedEnvironments() { - def ret = Holders.grailsApplication.config.hoist.supportedEnvironments as Set - ret.add('Production') - return ret + /** + * User-facing display name of the application - proper case, can include spaces. + */ + static String getAppName() { + return buildInfo.getProperty('info.xh.appName') } - static String getAppDisplayName() { - return Holders.grailsApplication.config.hoist.appDisplayName ?: appName + /** + * Current version, either SemVer x.y.z format or x.y-SNAPSHOT. + */ + static String getAppVersion() { + return buildInfo.getProperty('info.app.version') } - static String getAppName() { - return buildInfo.getProperty('info.app.name') + /** + * Hoist AppEnvironment of the current deployment, distinct from Grails environment. + */ + static AppEnvironment getAppEnvironment() { + return InstanceConfigUtils.appEnvironment } - static String getAppVersion() { - return buildInfo.getProperty('info.app.version') + static Set getSupportedEnvironments() { + def ret = Holders.grailsApplication.config.hoist.supportedEnvironments as Set + ret.add('Production') + return ret } static Boolean getIsProduction() { @@ -106,6 +118,7 @@ class Utils { // We *should* be able to draw this build info from grails.util.Metadata object. // But that object began returning nulls with grails 3.3.0. // For now, we just pulls values directly from the gradle artifact used by that file. + // Note that our standard build.gradle injects appCode/appName // See http://grailsblog.objectcomputing.com/posts/2017/04/02/add-build-info-to-your-project.html private static Properties readBuildInfo() { def ret = new Properties(),