[KARAF-6054] Reuse karafName, hostAddress and hostName if exist 67/head
authorJean-Baptiste Onofré <jbonofre@apache.org>
Tue, 18 Dec 2018 13:55:54 +0000 (14:55 +0100)
committerJean-Baptiste Onofré <jbonofre@apache.org>
Tue, 18 Dec 2018 13:55:54 +0000 (14:55 +0100)
collector/utils/src/main/java/org/apache/karaf/decanter/collector/utils/PropertiesPreparator.java

index 672afc7..6c24a3f 100644 (file)
@@ -39,15 +39,26 @@ public class PropertiesPreparator {
      * @param properties Custom properties included in the data.
      */
     public static void prepare(Map<String, Object> data, Dictionary<String, Object> properties) throws Exception {
-        // add the karaf instance name
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
+        // add the karaf instance name if it doesn't exist in the data
+        String karafName = (String) data.get("karafName");
+        if (karafName == null) {
+            karafName = System.getProperty("karaf.name");
+            if (karafName != null) {
+                data.put("karafName", karafName);
+            }
         }
 
         // add the network details
-        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-        data.put("hostName", InetAddress.getLocalHost().getHostName());
+        String hostAddress = (String) data.get("hostAddress");
+        if (hostAddress == null) {
+            hostAddress =  InetAddress.getLocalHost().getHostAddress();
+        }
+        data.put("hostAddress", hostAddress);
+        String hostName = (String) data.get("hostName");
+        if (hostName == null) {
+            hostName = InetAddress.getLocalHost().getHostName();
+        }
+        data.put("hostName", hostName);
 
         // custom fields
         Enumeration<String> keys = properties.keys();