This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new c1f5b0d  tidy name and visibility of policies
c1f5b0d is described below

commit c1f5b0d1bfa292c5d76fa567a6b7bb2529a72b3e
Author: Alex Heneveld <[email protected]>
AuthorDate: Wed Sep 29 16:25:41 2021 +0100

    tidy name and visibility of policies
---
 .../brooklyn/core/objs/AbstractEntityAdjunct.java      |  8 ++++----
 .../brooklyn/policy/failover/ElectPrimaryPolicy.java   | 18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java 
b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index 2562c46..62b40a6 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -115,13 +115,13 @@ public abstract class AbstractEntityAdjunct extends 
AbstractBrooklynObject imple
     private Map<String, HighlightTuple> highlights = new ConcurrentHashMap<>();
 
     /** Name of a highlight that indicates the last action taken by this 
adjunct. */
-    public static String HIGHLIGHT_NAME_LAST_ACTION = "lastAction";
+    public static final String HIGHLIGHT_NAME_LAST_ACTION = "lastAction";
     /** Name of a highlight that indicates the last confirmation detected by 
this adjunct. */
-    public static String HIGHLIGHT_NAME_LAST_CONFIRMATION= "lastConfirmation";
+    public static final String HIGHLIGHT_NAME_LAST_CONFIRMATION= 
"lastConfirmation";
     /** Name of a highlight that indicates the last violation detected by this 
adjunct. */
-    public static String HIGHLIGHT_NAME_LAST_VIOLATION= "lastViolation";
+    public static final String HIGHLIGHT_NAME_LAST_VIOLATION= "lastViolation";
     /** Name of a highlight that indicates the triggers for this adjunct. */
-    public static String HIGHLIGHT_NAME_TRIGGERS = "triggers";
+    public static final String HIGHLIGHT_NAME_TRIGGERS = "triggers";
 
     public AbstractEntityAdjunct() {
         this(Collections.emptyMap());
diff --git 
a/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
 
b/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
index 35adfbf..e34c9dd 100644
--- 
a/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
+++ 
b/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.Group;
 import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
@@ -254,7 +255,7 @@ public class ElectPrimaryPolicy extends AbstractPolicy 
implements ElectPrimaryCo
             if (result instanceof Map) code = Strings.toString( 
((Map<?,?>)result).get("code") );
             
             if 
(ElectPrimaryEffector.ResultCode.NEW_PRIMARY_ELECTED.name().equalsIgnoreCase(code))
 {
-                highlightAction("New primary elected: 
"+((Map<?,?>)result).get("primary"), null);
+                highlightAction("New primary elected: 
"+niceName(((Map<?,?>)result).get("primary")), null);
             }
             if 
(ElectPrimaryEffector.ResultCode.NO_PRIMARY_AVAILABLE.name().equalsIgnoreCase(code))
 {
                 highlightViolation("No primary available");
@@ -281,5 +282,18 @@ public class ElectPrimaryPolicy extends AbstractPolicy 
implements ElectPrimaryCo
             rescanInProgress = false;
         }
     }
-    
+
+    private String niceName(Object primary) {
+        if (primary instanceof BrooklynObject) {
+            if (Strings.isNonBlank( ((BrooklynObject)primary).getDisplayName() 
)) {
+                String name = ((BrooklynObject)primary).getDisplayName();
+                if (!name.contains( ((BrooklynObject)primary).getId() )) {
+                    name += " ("+((BrooklynObject)primary).getId()+")";
+                }
+                return name;
+            }
+        }
+        return ""+primary;
+    }
+
 }

Reply via email to