mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 18:02:05 +02:00
intents --mini-summary
Example Output: onos> intents --mini-summary All (0) installed: 0 withdrawn: 0 failed: 0 compiling: 0 installing: 0 recompiling: 0 withdrawing: 0 installReq: 0 withdrawReq: 0 unknownState: 0 ... Change-Id: Ifc0686061660c08a1dd5bea2b442d6a5bc999639
This commit is contained in:
parent
8a438a0a55
commit
f0e09cd7fa
@ -26,6 +26,7 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.apache.karaf.shell.commands.Command;
|
import org.apache.karaf.shell.commands.Command;
|
||||||
import org.apache.karaf.shell.commands.Option;
|
import org.apache.karaf.shell.commands.Option;
|
||||||
import org.onlab.util.StringFilter;
|
import org.onlab.util.StringFilter;
|
||||||
|
import org.onlab.util.Tools;
|
||||||
import org.onosproject.cli.AbstractShellCommand;
|
import org.onosproject.cli.AbstractShellCommand;
|
||||||
import org.onosproject.net.ConnectPoint;
|
import org.onosproject.net.ConnectPoint;
|
||||||
import org.onosproject.net.FilteredConnectPoint;
|
import org.onosproject.net.FilteredConnectPoint;
|
||||||
@ -45,9 +46,16 @@ 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 static com.google.common.base.MoreObjects.firstNonNull;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import static org.apache.commons.lang3.text.WordUtils.uncapitalize;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,7 +103,7 @@ public class IntentsListCommand extends AbstractShellCommand {
|
|||||||
|
|
||||||
private static final String SELECTOR = BOLD + "Selector:" + RESET + " %s";
|
private static final String SELECTOR = BOLD + "Selector:" + RESET + " %s";
|
||||||
|
|
||||||
private static final String SEPARATOR = StringUtils.repeat("-", 172);;
|
private static final String SEPARATOR = StringUtils.repeat("-", 172);
|
||||||
|
|
||||||
private static final String SPACE = " ";
|
private static final String SPACE = " ";
|
||||||
|
|
||||||
@ -107,8 +115,11 @@ public class IntentsListCommand extends AbstractShellCommand {
|
|||||||
|
|
||||||
private static final String TYPE = BOLD + "Intent type:" + RESET + " %s";
|
private static final String TYPE = BOLD + "Intent type:" + RESET + " %s";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@value #SUMMARY_TITLES}.
|
||||||
|
*/
|
||||||
private static final String SUMMARY_TITLES =
|
private static final String SUMMARY_TITLES =
|
||||||
BOLD + String.format(
|
BOLD + format(
|
||||||
"\n%1s%21s%14s%14s%14s%14s%14s%14s%14s%14s%14s%14s",
|
"\n%1s%21s%14s%14s%14s%14s%14s%14s%14s%14s%14s%14s",
|
||||||
"Intent type",
|
"Intent type",
|
||||||
"Total",
|
"Total",
|
||||||
@ -134,6 +145,11 @@ public class IntentsListCommand extends AbstractShellCommand {
|
|||||||
required = false, multiValued = false)
|
required = false, multiValued = false)
|
||||||
private boolean intentsSummary = false;
|
private boolean intentsSummary = false;
|
||||||
|
|
||||||
|
@Option(name = "-m", aliases = "--mini-summary",
|
||||||
|
description = "Intents mini summary",
|
||||||
|
required = false, multiValued = false)
|
||||||
|
private boolean miniSummary = false;
|
||||||
|
|
||||||
@Option(name = "-p", aliases = "--pending",
|
@Option(name = "-p", aliases = "--pending",
|
||||||
description = "Show information about pending intents",
|
description = "Show information about pending intents",
|
||||||
required = false, multiValued = false)
|
required = false, multiValued = false)
|
||||||
@ -145,411 +161,382 @@ public class IntentsListCommand extends AbstractShellCommand {
|
|||||||
private List<String> filter = new ArrayList<>();
|
private List<String> filter = new ArrayList<>();
|
||||||
|
|
||||||
private StringFilter contentFilter;
|
private StringFilter contentFilter;
|
||||||
|
private IntentService service;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute() {
|
protected void execute() {
|
||||||
IntentService service = get(IntentService.class);
|
service = get(IntentService.class);
|
||||||
contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
|
contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
|
||||||
|
|
||||||
if (intentsSummary) {
|
Iterable<Intent> intents;
|
||||||
IntentSummaries intentSummaries = new IntentSummaries();
|
if (pending) {
|
||||||
intentSummaries.collectIntentSummary(service,
|
intents = service.getPending();
|
||||||
service.getIntents());
|
} else {
|
||||||
|
intents = service.getIntents();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intentsSummary || miniSummary) {
|
||||||
|
Map<String, IntentSummary> summarized = summarize(intents);
|
||||||
if (outputJson()) {
|
if (outputJson()) {
|
||||||
print("%s", intentSummaries.json());
|
ObjectNode summaries = mapper().createObjectNode();
|
||||||
|
summarized.forEach((n, s) -> summaries.set(uncapitalize(n), s.json(mapper())));
|
||||||
|
print("%s", summaries);
|
||||||
|
} else if (miniSummary) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(summarized.remove("All").miniSummary());
|
||||||
|
summarized.values().forEach(s -> builder.append(s.miniSummary()));
|
||||||
|
print("%s", builder.toString());
|
||||||
} else {
|
} else {
|
||||||
print(intentSummaries.summary());
|
StringBuilder builder = new StringBuilder();
|
||||||
}
|
builder.append(SUMMARY_TITLES);
|
||||||
return;
|
builder.append('\n').append(SEPARATOR);
|
||||||
} else if (pending) {
|
builder.append(summarized.remove("All").summary());
|
||||||
if (outputJson()) {
|
summarized.values().forEach(s -> builder.append(s.summary()));
|
||||||
print("%s", json(service.getPending()));
|
print("%s", builder.toString());
|
||||||
} else {
|
|
||||||
StreamSupport.stream(service.getPending().spliterator(), false)
|
|
||||||
.filter(intent -> contentFilter.filter(intent))
|
|
||||||
.forEach(intent -> print(fullFormat(intent)));
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputJson()) {
|
if (outputJson()) {
|
||||||
print("%s", json(service.getIntents()));
|
print("%s", json(intents));
|
||||||
} else {
|
} else {
|
||||||
printIntents(service);
|
for (Intent intent : intents) {
|
||||||
|
IntentState state = service.getIntentState(intent.key());
|
||||||
|
StringBuilder intentFormat = fullFormat(intent, state);
|
||||||
|
StringBuilder detailsIntentFormat = detailsFormat(intent, state);
|
||||||
|
String formatted = intentFormat.append(detailsIntentFormat).toString();
|
||||||
|
if (contentFilter.filter(formatted)) {
|
||||||
|
print("%s\n", formatted);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal local class to keep track of all intent summaries.
|
* Internal local class to keep track of a single type Intent summary.
|
||||||
*/
|
*/
|
||||||
private class IntentSummaries {
|
private class IntentSummary {
|
||||||
private IntentSummary summaryAll;
|
private final String intentType;
|
||||||
private IntentSummary summaryConnectivity;
|
private int total = 0;
|
||||||
private IntentSummary summaryHostToHost;
|
private int installReq = 0;
|
||||||
private IntentSummary summaryPointToPoint;
|
private int compiling = 0;
|
||||||
private IntentSummary summaryMultiPointToSinglePoint;
|
private int installing = 0;
|
||||||
private IntentSummary summarySinglePointToMultiPoint;
|
private int installed = 0;
|
||||||
private IntentSummary summaryPath;
|
private int recompiling = 0;
|
||||||
private IntentSummary summaryLinkCollection;
|
private int withdrawReq = 0;
|
||||||
private IntentSummary summaryOpticalCircuit;
|
private int withdrawing = 0;
|
||||||
private IntentSummary summaryOpticalConnectivity;
|
private int withdrawn = 0;
|
||||||
private IntentSummary summaryOpticalOdu;
|
private int failed = 0;
|
||||||
private IntentSummary summaryUnknownType;
|
private int unknownState = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the internal summary.
|
* Creates empty {@link IntentSummary} for specified {@code intentType}.
|
||||||
|
*
|
||||||
|
* @param intentType the string describing the Intent type
|
||||||
*/
|
*/
|
||||||
private void init() {
|
IntentSummary(String intentType) {
|
||||||
summaryAll = new IntentSummary("All");
|
this.intentType = intentType;
|
||||||
summaryConnectivity = new IntentSummary("Connectivity");
|
|
||||||
summaryHostToHost = new IntentSummary("HostToHost");
|
|
||||||
summaryPointToPoint = new IntentSummary("PointToPoint");
|
|
||||||
summaryMultiPointToSinglePoint =
|
|
||||||
new IntentSummary("MultiPointToSinglePoint");
|
|
||||||
summarySinglePointToMultiPoint =
|
|
||||||
new IntentSummary("SinglePointToMultiPoint");
|
|
||||||
summaryPath = new IntentSummary("Path");
|
|
||||||
summaryLinkCollection = new IntentSummary("LinkCollection");
|
|
||||||
summaryOpticalCircuit = new IntentSummary("OpticalCircuit");
|
|
||||||
summaryOpticalConnectivity = new IntentSummary("OpticalConnectivity");
|
|
||||||
summaryOpticalOdu = new IntentSummary("OpticalOdu");
|
|
||||||
summaryUnknownType = new IntentSummary("UnknownType");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects summary of all intents.
|
* Creates {@link IntentSummary} initialized with given {@code intent}.
|
||||||
*
|
*
|
||||||
* @param service the Intent Service to use
|
* @param intent to initialize with
|
||||||
* @param intents the intents
|
|
||||||
*/
|
*/
|
||||||
private void collectIntentSummary(IntentService service,
|
IntentSummary(Intent intent) {
|
||||||
Iterable<Intent> intents) {
|
// remove "Intent" from intentType label
|
||||||
init();
|
this(intentType(intent));
|
||||||
|
update(service.getIntentState(intent.key()));
|
||||||
|
}
|
||||||
|
|
||||||
// Collect the summary for each intent type intents
|
// for identity element, when reducing
|
||||||
for (Intent intent : intents) {
|
IntentSummary() {
|
||||||
IntentState intentState = service.getIntentState(intent.key());
|
this.intentType = null;
|
||||||
if (intentState == null) {
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!contentFilter.filter(intent)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the summary for all Intents
|
/**
|
||||||
summaryAll.update(intentState);
|
* Updates the Intent Summary.
|
||||||
|
*
|
||||||
if (intent instanceof ConnectivityIntent) {
|
* @param intentState the state of the intent
|
||||||
summaryConnectivity.update(intentState);
|
*/
|
||||||
// NOTE: ConnectivityIntent is a base type Intent
|
void update(IntentState intentState) {
|
||||||
// continue;
|
total++;
|
||||||
}
|
switch (intentState) {
|
||||||
if (intent instanceof HostToHostIntent) {
|
case INSTALL_REQ:
|
||||||
summaryHostToHost.update(intentState);
|
installReq++;
|
||||||
continue;
|
break;
|
||||||
}
|
case COMPILING:
|
||||||
if (intent instanceof PointToPointIntent) {
|
compiling++;
|
||||||
summaryPointToPoint.update(intentState);
|
break;
|
||||||
continue;
|
case INSTALLING:
|
||||||
}
|
installing++;
|
||||||
if (intent instanceof MultiPointToSinglePointIntent) {
|
break;
|
||||||
summaryMultiPointToSinglePoint.update(intentState);
|
case INSTALLED:
|
||||||
continue;
|
installed++;
|
||||||
}
|
break;
|
||||||
if (intent instanceof SinglePointToMultiPointIntent) {
|
case RECOMPILING:
|
||||||
summarySinglePointToMultiPoint.update(intentState);
|
recompiling++;
|
||||||
continue;
|
break;
|
||||||
}
|
case WITHDRAW_REQ:
|
||||||
if (intent instanceof PathIntent) {
|
withdrawReq++;
|
||||||
summaryPath.update(intentState);
|
break;
|
||||||
continue;
|
case WITHDRAWING:
|
||||||
}
|
withdrawing++;
|
||||||
if (intent instanceof LinkCollectionIntent) {
|
break;
|
||||||
summaryLinkCollection.update(intentState);
|
case WITHDRAWN:
|
||||||
continue;
|
withdrawn++;
|
||||||
}
|
break;
|
||||||
if (intent instanceof OpticalCircuitIntent) {
|
case FAILED:
|
||||||
summaryOpticalCircuit.update(intentState);
|
failed++;
|
||||||
continue;
|
break;
|
||||||
}
|
default:
|
||||||
if (intent instanceof OpticalConnectivityIntent) {
|
unknownState++;
|
||||||
summaryOpticalConnectivity.update(intentState);
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (intent instanceof OpticalOduIntent) {
|
|
||||||
summaryOpticalOdu.update(intentState);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
summaryUnknownType.update(intentState);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets JSON representation of all Intents summary.
|
* Prints the Intent Summary.
|
||||||
*
|
*
|
||||||
* @return JSON representation of all Intents summary
|
|
||||||
*/
|
*/
|
||||||
ObjectNode json() {
|
StringBuilder summary() {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
ObjectNode result = mapper.createObjectNode();
|
|
||||||
result.set("connectivity", summaryConnectivity.json(mapper));
|
|
||||||
result.set("hostToHost", summaryHostToHost.json(mapper));
|
|
||||||
result.set("pointToPoint", summaryPointToPoint.json(mapper));
|
|
||||||
result.set("multiPointToSinglePoint",
|
|
||||||
summaryMultiPointToSinglePoint.json(mapper));
|
|
||||||
result.set("singlePointToMultiPoint",
|
|
||||||
summarySinglePointToMultiPoint.json(mapper));
|
|
||||||
result.set("path", summaryPath.json(mapper));
|
|
||||||
result.set("linkCollection", summaryLinkCollection.json(mapper));
|
|
||||||
result.set("opticalCircuit", summaryOpticalCircuit.json(mapper));
|
|
||||||
result.set("opticalConnectivity", summaryOpticalConnectivity.json(mapper));
|
|
||||||
result.set("opticalOdu", summaryOpticalOdu.json(mapper));
|
|
||||||
result.set("unknownType", summaryUnknownType.json(mapper));
|
|
||||||
result.set("all", summaryAll.json(mapper));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints summary of the intents.
|
|
||||||
*/
|
|
||||||
private String summary() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(SUMMARY_TITLES);
|
|
||||||
builder.append("\n" + SEPARATOR);
|
|
||||||
builder.append(summaryAll.summary());
|
|
||||||
builder.append(summaryPointToPoint.summary());
|
|
||||||
builder.append(summarySinglePointToMultiPoint.summary());
|
|
||||||
builder.append(summaryMultiPointToSinglePoint.summary());
|
|
||||||
builder.append(summaryHostToHost.summary());
|
|
||||||
builder.append(summaryLinkCollection.summary());
|
|
||||||
builder.append(summaryConnectivity.summary());
|
|
||||||
builder.append(summaryPath.summary());
|
|
||||||
builder.append(summaryOpticalCircuit.summary());
|
|
||||||
builder.append(summaryOpticalConnectivity.summary());
|
|
||||||
builder.append(summaryOpticalOdu.summary());
|
|
||||||
builder.append(summaryUnknownType.summary());
|
|
||||||
|
|
||||||
return builder.toString();
|
builder.append(format(
|
||||||
|
"\n%1s%s%14d%14d%14d%14d%14d%14d%14d%14d%14d%14d",
|
||||||
|
BOLD + intentType + RESET,
|
||||||
|
Strings.padStart(String.valueOf(total),
|
||||||
|
(32 - intentType.length()),
|
||||||
|
' '),
|
||||||
|
installed,
|
||||||
|
withdrawn,
|
||||||
|
failed,
|
||||||
|
installReq,
|
||||||
|
compiling,
|
||||||
|
installing,
|
||||||
|
recompiling,
|
||||||
|
withdrawReq,
|
||||||
|
withdrawing,
|
||||||
|
unknownState));
|
||||||
|
builder.append('\n').append(SEPARATOR);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder miniSummary() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(BOLD).append(intentType).append(RESET)
|
||||||
|
.append(" (").append(total).append(')').append('\n');
|
||||||
|
builder.append('\t')
|
||||||
|
.append("installed: ").append(installed).append(' ')
|
||||||
|
.append("withdrawn: ").append(withdrawn).append(' ')
|
||||||
|
.append("failed: ").append(failed)
|
||||||
|
.append('\n');
|
||||||
|
builder.append('\t')
|
||||||
|
.append("compiling: ").append(compiling).append(' ')
|
||||||
|
.append("installing: ").append(installing).append(' ')
|
||||||
|
.append("recompiling: ").append(recompiling).append(' ')
|
||||||
|
.append("withdrawing: ").append(withdrawing)
|
||||||
|
.append('\n');
|
||||||
|
builder.append('\t')
|
||||||
|
.append("installReq: ").append(installReq).append(' ')
|
||||||
|
.append("withdrawReq: ").append(withdrawReq).append(' ')
|
||||||
|
.append("unknownState: ").append(unknownState)
|
||||||
|
.append('\n')
|
||||||
|
.append('\n');
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal local class to keep track of a single type Intent summary.
|
* Gets the JSON representation of the Intent Summary.
|
||||||
|
*
|
||||||
|
* @param mapper the object mapper
|
||||||
|
* @return the JSON representation of the Intent Summary
|
||||||
*/
|
*/
|
||||||
private class IntentSummary {
|
JsonNode json(ObjectMapper mapper) {
|
||||||
private final String intentType;
|
ObjectNode result = mapper.createObjectNode()
|
||||||
private int total = 0;
|
.put("total", total)
|
||||||
private int installReq = 0;
|
.put("installed", installed)
|
||||||
private int compiling = 0;
|
.put("failed", failed)
|
||||||
private int installing = 0;
|
.put("installReq", installReq)
|
||||||
private int installed = 0;
|
.put("installing", installing)
|
||||||
private int recompiling = 0;
|
.put("compiling", compiling)
|
||||||
private int withdrawReq = 0;
|
.put("recompiling", recompiling)
|
||||||
private int withdrawing = 0;
|
.put("withdrawReq", withdrawReq)
|
||||||
private int withdrawn = 0;
|
.put("withdrawing", withdrawing)
|
||||||
private int failed = 0;
|
.put("withdrawn", withdrawn)
|
||||||
private int unknownState = 0;
|
.put("unknownState", unknownState);
|
||||||
|
|
||||||
/**
|
return result;
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param intentType the scring describing the Intent type
|
|
||||||
*/
|
|
||||||
IntentSummary(String intentType) {
|
|
||||||
this.intentType = intentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the Intent Summary.
|
|
||||||
*
|
|
||||||
* @param intentState the state of the intent
|
|
||||||
*/
|
|
||||||
void update(IntentState intentState) {
|
|
||||||
total++;
|
|
||||||
switch (intentState) {
|
|
||||||
case INSTALL_REQ:
|
|
||||||
installReq++;
|
|
||||||
break;
|
|
||||||
case COMPILING:
|
|
||||||
compiling++;
|
|
||||||
break;
|
|
||||||
case INSTALLING:
|
|
||||||
installing++;
|
|
||||||
break;
|
|
||||||
case INSTALLED:
|
|
||||||
installed++;
|
|
||||||
break;
|
|
||||||
case RECOMPILING:
|
|
||||||
recompiling++;
|
|
||||||
break;
|
|
||||||
case WITHDRAW_REQ:
|
|
||||||
withdrawReq++;
|
|
||||||
break;
|
|
||||||
case WITHDRAWING:
|
|
||||||
withdrawing++;
|
|
||||||
break;
|
|
||||||
case WITHDRAWN:
|
|
||||||
withdrawn++;
|
|
||||||
break;
|
|
||||||
case FAILED:
|
|
||||||
failed++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
unknownState++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints the Intent Summary.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
String summary() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
builder.append(String.format(
|
|
||||||
"\n%1s%s%14d%14d%14d%14d%14d%14d%14d%14d%14d%14d",
|
|
||||||
BOLD + intentType + RESET,
|
|
||||||
Strings.padStart(String.valueOf(total),
|
|
||||||
(32 - intentType.length()),
|
|
||||||
' '),
|
|
||||||
installed,
|
|
||||||
withdrawn,
|
|
||||||
failed,
|
|
||||||
installReq,
|
|
||||||
compiling,
|
|
||||||
installing,
|
|
||||||
recompiling,
|
|
||||||
withdrawReq,
|
|
||||||
withdrawing,
|
|
||||||
unknownState));
|
|
||||||
builder.append("\n" + SEPARATOR);
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the JSON representation of the Intent Summary.
|
|
||||||
*
|
|
||||||
* @param mapper the object mapper
|
|
||||||
* @return the JSON representation of the Intent Summary
|
|
||||||
*/
|
|
||||||
JsonNode json(ObjectMapper mapper) {
|
|
||||||
ObjectNode result = mapper.createObjectNode()
|
|
||||||
.put("total", total)
|
|
||||||
.put("installed", installed)
|
|
||||||
.put("failed", failed)
|
|
||||||
.put("installReq", installReq)
|
|
||||||
.put("installing", installing)
|
|
||||||
.put("compiling", compiling)
|
|
||||||
.put("recompiling", recompiling)
|
|
||||||
.put("withdrawReq", withdrawReq)
|
|
||||||
.put("withdrawing", withdrawing)
|
|
||||||
.put("withdrawn", withdrawn)
|
|
||||||
.put("unknownState", unknownState);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Prints detailed information about a specific intent.
|
* Merges 2 {@link IntentSummary} together.
|
||||||
|
*
|
||||||
|
* @param a element to merge
|
||||||
|
* @param b element to merge
|
||||||
|
* @return merged {@link IntentSummary}
|
||||||
*/
|
*/
|
||||||
private String detailsFormat(IntentService service, Intent intent) {
|
IntentSummary merge(IntentSummary a, IntentSummary b) {
|
||||||
|
IntentSummary m = new IntentSummary(firstNonNull(a.intentType, b.intentType));
|
||||||
|
m.total = a.total + b.total;
|
||||||
|
m.installReq = a.installReq + b.installReq;
|
||||||
|
m.compiling = a.compiling + b.compiling;
|
||||||
|
m.installing = a.installing + b.installing;
|
||||||
|
m.installed = a.installed + b.installed;
|
||||||
|
m.recompiling = a.recompiling + b.recompiling;
|
||||||
|
m.withdrawing = a.withdrawing + b.withdrawing;
|
||||||
|
m.withdrawReq = a.withdrawReq + b.withdrawReq;
|
||||||
|
m.withdrawn = a.withdrawn + b.withdrawn;
|
||||||
|
m.failed = a.failed + b.failed;
|
||||||
|
m.unknownState = a.unknownState + b.unknownState;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns IntentType string.
|
||||||
|
*
|
||||||
|
* @param intent input
|
||||||
|
* @return IntentType string
|
||||||
|
*/
|
||||||
|
private static String intentType(Intent intent) {
|
||||||
|
return intent.getClass().getSimpleName().replace("Intent", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build summary of intents per intent type.
|
||||||
|
*
|
||||||
|
* @param intents to summarize
|
||||||
|
* @return summaries per Intent type
|
||||||
|
*/
|
||||||
|
private Map<String, IntentSummary> summarize(Iterable<Intent> intents) {
|
||||||
|
Map<String, List<Intent>> perIntent = Tools.stream(intents)
|
||||||
|
.collect(Collectors.groupingBy(i -> intentType(i)));
|
||||||
|
|
||||||
|
List<IntentSummary> collect = perIntent.values().stream()
|
||||||
|
.map(il ->
|
||||||
|
il.stream()
|
||||||
|
.map(IntentSummary::new)
|
||||||
|
.reduce(new IntentSummary(), this::merge)
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
|
||||||
|
Map<String, IntentSummary> summaries = new HashMap<>();
|
||||||
|
|
||||||
|
// individual
|
||||||
|
collect.forEach(is -> summaries.put(is.intentType, is));
|
||||||
|
|
||||||
|
// all summarised
|
||||||
|
summaries.put("All", collect.stream()
|
||||||
|
.reduce(new IntentSummary("All"), this::merge));
|
||||||
|
return summaries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns detailed information text about a specific intent.
|
||||||
|
*
|
||||||
|
* @param intent to print
|
||||||
|
* @param state of intent
|
||||||
|
* @return detailed information or "" if {@code state} was null
|
||||||
|
*/
|
||||||
|
private StringBuilder detailsFormat(Intent intent, IntentState state) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
if (state == null) {
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
if (!intent.resources().isEmpty()) {
|
if (!intent.resources().isEmpty()) {
|
||||||
builder.append("\n" + String.format(RESOURCES, intent.resources()));
|
builder.append('\n').append(format(RESOURCES, intent.resources()));
|
||||||
}
|
}
|
||||||
if (intent instanceof ConnectivityIntent) {
|
if (intent instanceof ConnectivityIntent) {
|
||||||
ConnectivityIntent ci = (ConnectivityIntent) intent;
|
ConnectivityIntent ci = (ConnectivityIntent) intent;
|
||||||
if (!ci.selector().criteria().isEmpty()) {
|
if (!ci.selector().criteria().isEmpty()) {
|
||||||
builder.append("\n" + String.format(COMMON_SELECTOR, formatSelector(ci.selector())));
|
builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
|
||||||
}
|
}
|
||||||
if (!ci.treatment().allInstructions().isEmpty()) {
|
if (!ci.treatment().allInstructions().isEmpty()) {
|
||||||
builder.append("\n" + String.format(TREATMENT, ci.treatment().allInstructions()));
|
builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
|
||||||
}
|
}
|
||||||
if (ci.constraints() != null && !ci.constraints().isEmpty()) {
|
if (ci.constraints() != null && !ci.constraints().isEmpty()) {
|
||||||
builder.append("\n" + String.format(CONSTRAINTS, ci.constraints()));
|
builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent instanceof HostToHostIntent) {
|
if (intent instanceof HostToHostIntent) {
|
||||||
HostToHostIntent pi = (HostToHostIntent) intent;
|
HostToHostIntent pi = (HostToHostIntent) intent;
|
||||||
builder.append("\n" + String.format(SRC + HOST, pi.one()));
|
builder.append('\n').append(format(SRC + HOST, pi.one()));
|
||||||
builder.append("\n" + String.format(DST + HOST, pi.two()));
|
builder.append('\n').append(format(DST + HOST, pi.two()));
|
||||||
} else if (intent instanceof PointToPointIntent) {
|
} else if (intent instanceof PointToPointIntent) {
|
||||||
PointToPointIntent pi = (PointToPointIntent) intent;
|
PointToPointIntent pi = (PointToPointIntent) intent;
|
||||||
builder.append("\n" + formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
|
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
|
||||||
builder.append("\n" + formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
|
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
|
||||||
} else if (intent instanceof MultiPointToSinglePointIntent) {
|
} else if (intent instanceof MultiPointToSinglePointIntent) {
|
||||||
MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
|
MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
|
||||||
builder.append("\n" + formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
|
builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
|
||||||
builder.append("\n" + formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
|
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
|
||||||
} else if (intent instanceof SinglePointToMultiPointIntent) {
|
} else if (intent instanceof SinglePointToMultiPointIntent) {
|
||||||
SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
|
SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
|
||||||
builder.append("\n" + formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
|
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
|
||||||
builder.append("\n" + formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
|
builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
|
||||||
} else if (intent instanceof PathIntent) {
|
} else if (intent instanceof PathIntent) {
|
||||||
PathIntent pi = (PathIntent) intent;
|
PathIntent pi = (PathIntent) intent;
|
||||||
builder.append(String.format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
|
builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
|
||||||
} else if (intent instanceof LinkCollectionIntent) {
|
} else if (intent instanceof LinkCollectionIntent) {
|
||||||
LinkCollectionIntent li = (LinkCollectionIntent) intent;
|
LinkCollectionIntent li = (LinkCollectionIntent) intent;
|
||||||
builder.append("\n" + String.format("links=%s", li.links()));
|
builder.append('\n').append(format("links=%s", li.links()));
|
||||||
builder.append("\n" + String.format(CP, li.egressPoints()));
|
builder.append('\n').append(format(CP, li.egressPoints()));
|
||||||
} else if (intent instanceof OpticalCircuitIntent) {
|
} else if (intent instanceof OpticalCircuitIntent) {
|
||||||
OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
|
OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
|
||||||
builder.append("\n" + String.format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
|
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
|
||||||
} else if (intent instanceof OpticalConnectivityIntent) {
|
} else if (intent instanceof OpticalConnectivityIntent) {
|
||||||
OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
|
OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
|
||||||
builder.append("\n" + String.format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
|
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
|
||||||
} else if (intent instanceof OpticalOduIntent) {
|
} else if (intent instanceof OpticalOduIntent) {
|
||||||
OpticalOduIntent ci = (OpticalOduIntent) intent;
|
OpticalOduIntent ci = (OpticalOduIntent) intent;
|
||||||
builder.append("\n" + String.format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
|
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Intent> installable = service.getInstallableIntents(intent.key());
|
List<Intent> installable = service.getInstallableIntents(intent.key());
|
||||||
installable.stream().filter(i -> contentFilter.filter(i));
|
installable.stream().filter(i -> contentFilter.filter(i));
|
||||||
if (showInstallable && installable != null && !installable.isEmpty()) {
|
if (showInstallable && installable != null && !installable.isEmpty()) {
|
||||||
builder.append("\n" + String.format(INSTALLABLE, installable));
|
builder.append('\n').append(format(INSTALLABLE, installable));
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints out a formatted string, given a list of connect points.
|
* Prints out a formatted string, given a list of connect points.
|
||||||
*/
|
*/
|
||||||
private String formatFilteredCps(Set<FilteredConnectPoint> fCps, String prefix) {
|
private StringBuilder formatFilteredCps(Set<FilteredConnectPoint> fCps, String prefix) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(prefix);
|
builder.append(prefix);
|
||||||
builder.append(FILTERED_CPS);
|
builder.append(FILTERED_CPS);
|
||||||
fCps.forEach(fCp -> builder.append("\n" + String.format(formatFilteredCp(fCp))));
|
fCps.forEach(fCp -> builder.append('\n').append(formatFilteredCp(fCp)));
|
||||||
|
|
||||||
return builder.toString();
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints out a formatted string, given a filtered connect point.
|
* Prints out a formatted string, given a filtered connect point.
|
||||||
*/
|
*/
|
||||||
private String formatFilteredCp(FilteredConnectPoint fCp) {
|
private StringBuilder formatFilteredCp(FilteredConnectPoint fCp) {
|
||||||
ConnectPoint connectPoint = fCp.connectPoint();
|
ConnectPoint connectPoint = fCp.connectPoint();
|
||||||
TrafficSelector selector = fCp.trafficSelector();
|
TrafficSelector selector = fCp.trafficSelector();
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(INDENTATION + String.format(CP, connectPoint));
|
builder.append(INDENTATION).append(format(CP, connectPoint));
|
||||||
builder.append(SPACE + String.format(SELECTOR, formatSelector(selector)));
|
builder.append(SPACE).append(format(SELECTOR, formatSelector(selector)));
|
||||||
|
|
||||||
return builder.toString();
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints out a formatted string, given a traffic selector
|
* Prints out a formatted string, given a traffic selector
|
||||||
*/
|
*/
|
||||||
private String formatSelector(TrafficSelector ts) {
|
private StringBuilder formatSelector(TrafficSelector ts) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
List<Criterion> criteria = Lists.newArrayList(ts.criteria());
|
List<Criterion> criteria = Lists.newArrayList(ts.criteria());
|
||||||
|
|
||||||
if (criteria == null || criteria.isEmpty()) {
|
if (criteria == null || criteria.isEmpty()) {
|
||||||
builder.append(INHERITED);
|
builder.append(INHERITED);
|
||||||
return builder.toString();
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria.forEach(c -> {
|
criteria.forEach(c -> {
|
||||||
@ -559,46 +546,23 @@ public class IntentsListCommand extends AbstractShellCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return builder.toString();
|
return builder;
|
||||||
}
|
|
||||||
|
|
||||||
private String fullFormat(Intent intent) {
|
|
||||||
return fullFormat(intent, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints information about the intent state, given an intent.
|
* Prints information about the intent state, given an intent.
|
||||||
*/
|
*/
|
||||||
private String fullFormat(Intent intent, String state) {
|
private StringBuilder fullFormat(Intent intent, IntentState state) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(String.format(ID, intent.id()));
|
builder.append(format(ID, intent.id()));
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
builder.append("\n" + String.format(STATE, state));
|
builder.append('\n').append(format(STATE, state));
|
||||||
}
|
}
|
||||||
builder.append("\n" + String.format(KEY, intent.key()));
|
builder.append('\n').append(format(KEY, intent.key()));
|
||||||
builder.append("\n" + String.format(TYPE, intent.getClass().getSimpleName()));
|
builder.append('\n').append(format(TYPE, intent.getClass().getSimpleName()));
|
||||||
builder.append("\n" + String.format(APP_ID, intent.appId().name()));
|
builder.append('\n').append(format(APP_ID, intent.appId().name()));
|
||||||
|
|
||||||
return builder.toString();
|
return builder;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Prints a detailed information about intents.
|
|
||||||
*/
|
|
||||||
private void printIntents(IntentService service) {
|
|
||||||
for (Intent intent : service.getIntents()) {
|
|
||||||
IntentState state = service.getIntentState(intent.key());
|
|
||||||
String intentFormat = fullFormat(intent, state.toString());
|
|
||||||
String detailsIntentFormat = detailsFormat(service, intent);
|
|
||||||
if (state != null && (contentFilter.filter(
|
|
||||||
intentFormat + detailsIntentFormat))) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(intentFormat)
|
|
||||||
.append(detailsIntentFormat)
|
|
||||||
.append("\n");
|
|
||||||
print(builder.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user