Permalink
Browse files

Simple experimental mbean method to create a graph description

  • Loading branch information...
1 parent 3c02e4e commit 8216efb1926203c03e0336be0941eb6dd69b3780 @dmlloyd dmlloyd committed Mar 29, 2013
@@ -41,6 +41,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@@ -230,6 +231,48 @@ public String dumpServicesToString() {
}
}
+ public String dumpServicesToGraphDescription() {
+ final List<ServiceStatus> statuses = queryServiceStatuses();
+ final Map<String, String> aliases = new HashMap<String, String>();
+ final StringBuilder builder = new StringBuilder();
+ builder.append("digraph Services {\n node [shape=record];\n graph [rankdir=\"RL\"];\n");
+ for (ServiceStatus status : statuses) {
+ final String serviceName = status.getServiceName();
+ final String[] aliasesStrings = status.getAliases();
+ if (aliasesStrings != null) for (String alias : aliasesStrings) {
+ aliases.put(alias, serviceName);
+ aliases.put(serviceName, serviceName);
+ }
+ builder.append(" ");
+ final String quoted = serviceName.replace("\"", "\\\"");
+ builder.append('"').append(quoted).append('"');
+ builder.append(' ');
+ builder.append("[label=\"");
+ builder.append(quoted);
+ builder.append('|');
+ builder.append(status.getStateName()).append("\\ (").append(status.getSubstateName()).append(")");
+ builder.append("\"]");
+ builder.append(";\n");
+ }
+ builder.append('\n');
+ for (ServiceStatus status : statuses) {
+ final String serviceName = status.getServiceName();
+ final String[] dependencies = status.getDependencies();
+ final Set<String> filteredDependencies = new HashSet<String>(Arrays.asList(dependencies));
+ final String parentName = status.getParentName();
+ if (parentName != null) filteredDependencies.add(parentName);
+ for (String dependency : filteredDependencies) {
+ builder.append(" ").append('"').append(serviceName.replace("\"", "\\\"")).append('"');
+ String dep = aliases.get(dependency);
+ if (dep == null) dep = dependency;
+ builder.append(" -> \"").append(dep.replace("\"", "\\\"")).append('"');
+ builder.append(";\n");
+ }
+ }
+ builder.append("}\n");
+ return builder.toString();
+ }
+
public String dumpServiceDetails(final String serviceName) {
final ServiceRegistrationImpl registration = registry.get(ServiceName.parse(serviceName));
if (registration != null) {
@@ -75,6 +75,13 @@
String dumpServicesToString();
/**
+ * Dump the container state to a string suitable for rendering in GraphViz or compatible tools.
+ *
+ * @return the container state graph
+ */
+ String dumpServicesToGraphDescription();
+
+ /**
* Dump all details of a service.
*
* @param serviceName the name of the service to examine

0 comments on commit 8216efb

Please sign in to comment.