[ONOS-7572] Show information that the which leader of cluster has the intent
Change-Id: Ic89ccb0121db2bf3a1e679e1fc76fbdde31c824d
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
index 595599d..20c8b34 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentsListCommand.java
@@ -28,6 +28,7 @@
import org.onlab.util.StringFilter;
import org.onlab.util.Tools;
import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cluster.NodeId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.TrafficSelector;
@@ -38,6 +39,7 @@
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.LinkCollectionIntent;
+import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
@@ -45,6 +47,7 @@
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
+import org.onosproject.net.intent.WorkPartitionService;
import static com.google.common.base.MoreObjects.firstNonNull;
import static java.lang.String.format;
@@ -71,6 +74,8 @@
// Messages and string formatter
private static final String APP_ID = BOLD + "Application Id:" + RESET + " %s";
+ private static final String LEADER_ID = BOLD + "Leader Id:" + RESET + " %s";
+
private static final String COMMON_SELECTOR = BOLD + "Common ingress " +
"selector:" + RESET + " %s";
@@ -98,6 +103,8 @@
private static final String KEY = BOLD + "Key:" + RESET + " %s";
+ private static final String NONE = "None";
+
private static final String RESOURCES = BOLD + "Resources:" + RESET + " %s";
private static final String SELECTOR = BOLD + "Selector:" + RESET + " %s";
@@ -171,10 +178,17 @@
private StringFilter contentFilter;
private IntentService service;
+ private WorkPartitionService workPartitionService;
@Override
protected void execute() {
service = get(IntentService.class);
+ workPartitionService = get(WorkPartitionService.class);
+
+ if (workPartitionService == null) {
+ return;
+ }
+
contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
Iterable<Intent> intents;
@@ -614,6 +628,8 @@
*/
private StringBuilder fullFormat(Intent intent, IntentState state) {
StringBuilder builder = new StringBuilder();
+ NodeId nodeId = workPartitionService.getLeader(intent.key(), Key::hash);
+
builder.append(format(ID, intent.id()));
if (state != null) {
builder.append('\n').append(format(STATE, state));
@@ -621,6 +637,7 @@
builder.append('\n').append(format(KEY, intent.key()));
builder.append('\n').append(format(TYPE, intent.getClass().getSimpleName()));
builder.append('\n').append(format(APP_ID, intent.appId().name()));
+ builder.append('\n').append(nodeId == null ? NONE : format(LEADER_ID, nodeId.id()));
return builder;
}