Skip to content

Commit

Permalink
Standardize use of appCode / appName
Browse files Browse the repository at this point in the history
+ Server-side usage of these two core identifiers now matches that on the client.
+ appCode is an internal shortname, appName is a user-facing display name.
+ Both sourced from build - requires applications to enhance grails.build.info file provided by Grails within their build.gradle.
+ Review uses of Utils.appName - switch to appCode where appropriate, or leave as is when we really wanted a display name anyway.
+ Fixes #33
  • Loading branch information
amcclain committed May 30, 2018
1 parent d9823e1 commit fcf18cf
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
6 changes: 4 additions & 2 deletions src/main/groovy/io/xh/hoist/AppEnvironment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/io/xh/hoist/log/LogUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +84,7 @@ class LogUtils {
static void initConfig(Script script) {
withDelegate(script) {

def appLogName = Utils.appName
def appLogName = Utils.appCode

//----------------------------------
// Appenders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
37 changes: 25 additions & 12 deletions src/main/groovy/io/xh/hoist/util/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit fcf18cf

Please sign in to comment.