Search in sources :

Example 71 with StringSubstitutor

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());
    }
}
Also used : HashMap(java.util.HashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor)

Aggregations

StringSubstitutor (org.apache.commons.text.StringSubstitutor)71 HashMap (java.util.HashMap)24 Test (org.junit.jupiter.api.Test)19 IOException (java.io.IOException)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 File (java.io.File)8 List (java.util.List)8 InputStream (java.io.InputStream)6 Collectors (java.util.stream.Collectors)6 StringLookup (org.apache.commons.text.lookup.StringLookup)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)5 SubstitutingSourceProvider (io.dropwizard.configuration.SubstitutingSourceProvider)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 JsonObject (com.google.gson.JsonObject)4 URL (java.net.URL)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Scanner (java.util.Scanner)4