use of org.apache.commons.text.StringSubstitutor in project ahoy by lsdopen.
the class RouteHostnameResolver method resolve.
public String resolve(EnvironmentRelease environmentRelease, Application application, String routeHostname) {
if (routeHostname == null)
return null;
Objects.requireNonNull(environmentRelease, "environmentRelease is required");
Objects.requireNonNull(application, "application is required");
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("cluster_host", environmentRelease.getEnvironment().getCluster().getHost());
valuesMap.put("environment_name", environmentRelease.getEnvironment().getName());
valuesMap.put("release_name", environmentRelease.getRelease().getName());
valuesMap.put("application_name", application.getName());
StringSubstitutor stringSubstitutor = new StringSubstitutor(valuesMap);
stringSubstitutor.setEnableUndefinedVariableException(true);
try {
return stringSubstitutor.replace(routeHostname);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Failed to resolve route hostname for " + application.getName() + ": " + routeHostname + ", reason: " + e.getMessage());
}
}
Aggregations