[ONOS-7572] Show information that the which leader of cluster has the intent

Change-Id: Ic89ccb0121db2bf3a1e679e1fc76fbdde31c824d
This commit is contained in:
DongRyeol Cha 2018-04-02 17:22:47 +09:00 committed by Thomas Vachuska
parent 81929aa0cf
commit 4df4948418

View File

@ -28,6 +28,7 @@ import org.apache.karaf.shell.commands.Option;
import org.onlab.util.StringFilter; import org.onlab.util.StringFilter;
import org.onlab.util.Tools; import org.onlab.util.Tools;
import org.onosproject.cli.AbstractShellCommand; import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cluster.NodeId;
import org.onosproject.net.ConnectPoint; import org.onosproject.net.ConnectPoint;
import org.onosproject.net.FilteredConnectPoint; import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
@ -38,6 +39,7 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService; import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState; import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.LinkCollectionIntent; import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent; import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.OpticalCircuitIntent; import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent; import org.onosproject.net.intent.OpticalConnectivityIntent;
@ -45,6 +47,7 @@ import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.intent.PathIntent; import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent; import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent; import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import org.onosproject.net.intent.WorkPartitionService;
import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.firstNonNull;
import static java.lang.String.format; import static java.lang.String.format;
@ -71,6 +74,8 @@ public class IntentsListCommand extends AbstractShellCommand {
// Messages and string formatter // Messages and string formatter
private static final String APP_ID = BOLD + "Application Id:" + RESET + " %s"; 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 " + private static final String COMMON_SELECTOR = BOLD + "Common ingress " +
"selector:" + RESET + " %s"; "selector:" + RESET + " %s";
@ -98,6 +103,8 @@ public class IntentsListCommand extends AbstractShellCommand {
private static final String KEY = BOLD + "Key:" + RESET + " %s"; 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 RESOURCES = BOLD + "Resources:" + RESET + " %s";
private static final String SELECTOR = BOLD + "Selector:" + RESET + " %s"; private static final String SELECTOR = BOLD + "Selector:" + RESET + " %s";
@ -171,10 +178,17 @@ public class IntentsListCommand extends AbstractShellCommand {
private StringFilter contentFilter; private StringFilter contentFilter;
private IntentService service; private IntentService service;
private WorkPartitionService workPartitionService;
@Override @Override
protected void execute() { protected void execute() {
service = get(IntentService.class); service = get(IntentService.class);
workPartitionService = get(WorkPartitionService.class);
if (workPartitionService == null) {
return;
}
contentFilter = new StringFilter(filter, StringFilter.Strategy.AND); contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
Iterable<Intent> intents; Iterable<Intent> intents;
@ -614,6 +628,8 @@ public class IntentsListCommand extends AbstractShellCommand {
*/ */
private StringBuilder fullFormat(Intent intent, IntentState state) { private StringBuilder fullFormat(Intent intent, IntentState state) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
NodeId nodeId = workPartitionService.getLeader(intent.key(), Key::hash);
builder.append(format(ID, intent.id())); builder.append(format(ID, intent.id()));
if (state != null) { if (state != null) {
builder.append('\n').append(format(STATE, state)); builder.append('\n').append(format(STATE, state));
@ -621,6 +637,7 @@ public class IntentsListCommand extends AbstractShellCommand {
builder.append('\n').append(format(KEY, intent.key())); builder.append('\n').append(format(KEY, intent.key()));
builder.append('\n').append(format(TYPE, intent.getClass().getSimpleName())); builder.append('\n').append(format(TYPE, intent.getClass().getSimpleName()));
builder.append('\n').append(format(APP_ID, intent.appId().name())); builder.append('\n').append(format(APP_ID, intent.appId().name()));
builder.append('\n').append(nodeId == null ? NONE : format(LEADER_ID, nodeId.id()));
return builder; return builder;
} }