|
| 1 | +package datadog.trace.api; |
| 2 | + |
| 3 | +import datadog.json.JsonMapper; |
| 4 | +import org.slf4j.Logger; |
| 5 | +import org.slf4j.LoggerFactory; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | +import java.io.InputStream; |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.HashMap; |
| 11 | +import java.util.List; |
| 12 | +import java.util.Map; |
| 13 | +import java.util.Scanner; |
| 14 | + |
| 15 | +public class ParseSupportedConfigurations { |
| 16 | + public final Map<String, Object> fileData; |
| 17 | + public static Map<String, String> aliasMapping; |
| 18 | + public static final List<String> supportedConfigurations; |
| 19 | + public static final Map<String, String> deprecatedConfigurations; |
| 20 | + private static final Logger log = LoggerFactory.getLogger(ParseSupportedConfigurations.class); |
| 21 | + |
| 22 | + public ParseSupportedConfigurations(String filename) { |
| 23 | + String jsonString; |
| 24 | + try { |
| 25 | + InputStream in = getClass().getClassLoader().getResourceAsStream(filename); |
| 26 | + jsonString = new Scanner(in, "UTF-8").useDelimiter("\\A").next(); |
| 27 | + fileData = JsonMapper.fromJsonToMap(jsonString); |
| 28 | + } catch (IOException e) { |
| 29 | + throw new RuntimeException("Failed to read " + filename, e); |
| 30 | + } |
| 31 | + supportedConfigurations = new ArrayList<>(((Map<String, List<String>>) fileData.get("supportedConfigurations")).keySet()); |
| 32 | + aliasToConfig(); |
| 33 | + deprecatedConfigurations = (Map<String, String>) fileData.get("deprecated"); |
| 34 | + } |
| 35 | + |
| 36 | + private void aliasToConfig(){ |
| 37 | + aliasMapping = new HashMap<>(); |
| 38 | + Map<String, List<String>> aliases = (Map<String, List<String>>) fileData.get("aliases"); |
| 39 | + for (String env : aliases.keySet()){ |
| 40 | + for (String alias : aliases.get(env)){ |
| 41 | + if (aliasMapping.containsKey(alias)){ |
| 42 | + log.info("{} is listed as an alias of {} when it already exists as an alias of {}", alias, env, aliasMapping.get(alias)); |
| 43 | + } else { |
| 44 | + aliasMapping.put(alias, env); |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +} |
0 commit comments