Fixed a number of CLI commands.
Refactored the StoreService/Manager stuff for common serializer pool.
diff --git a/cli/pom.xml b/cli/pom.xml
index 80e173d..cc1d9dd 100644
--- a/cli/pom.xml
+++ b/cli/pom.xml
@@ -23,6 +23,10 @@
<artifactId>onos-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
diff --git a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
index e4f87ee..8c41b7f 100644
--- a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
@@ -1,8 +1,8 @@
package org.onlab.onos.cli;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onlab.osgi.ServiceNotFoundException;
/**
* Base abstraction of Karaf shell commands.
@@ -17,8 +17,7 @@
* @return service implementation
*/
public static <T> T get(Class<T> serviceClass) {
- BundleContext bc = FrameworkUtil.getBundle(AbstractShellCommand.class).getBundleContext();
- return bc.getService(bc.getServiceReference(serviceClass));
+ return DefaultServiceDirectory.getService(serviceClass);
}
/**
@@ -41,4 +40,19 @@
System.err.println(String.format(format, args));
}
+ /**
+ * Executes this command.
+ */
+ protected abstract void execute();
+
+ @Override
+ protected Object doExecute() throws Exception {
+ try {
+ execute();
+ } catch (ServiceNotFoundException e) {
+ error(e.getMessage());
+ }
+ return null;
+ }
+
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java b/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
index 1057d6e..1e921b4 100644
--- a/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
@@ -29,8 +29,8 @@
};
@Override
- protected Object doExecute() throws Exception {
- ClusterService service = getService(ClusterService.class);
+ protected void execute() {
+ ClusterService service = get(ClusterService.class);
List<ControllerNode> nodes = newArrayList(service.getNodes());
Collections.sort(nodes, ID_COMPARATOR);
ControllerNode self = service.getLocalNode();
@@ -39,7 +39,6 @@
service.getState(node.id()),
node.equals(self) ? "*" : "");
}
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
index a6f3048..f0217de 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
@@ -31,7 +31,7 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
@@ -44,8 +44,6 @@
print("%s", deviceId);
}
}
-
- return null;
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
index be5105c..2bbfb46 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
@@ -20,7 +20,7 @@
String id = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
int cid = Integer.parseInt(id);
init();
TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
@@ -31,7 +31,6 @@
print(linkString(link));
}
}
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
index 6bd444a..fe67348 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
@@ -27,7 +27,7 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
init();
List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
Collections.sort(clusters, ID_COMPARATOR);
@@ -35,7 +35,6 @@
for (TopologyCluster cluster : clusters) {
print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
}
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
index 8750424..9d68fb8 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
@@ -35,7 +35,7 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
DeviceService service = getService(DeviceService.class);
if (uri == null) {
for (Device device : getSortedDevices(service)) {
@@ -49,7 +49,6 @@
printDevice(service, device);
}
}
- return null;
}
@Override
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
index b4f2385..7cc55e6 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
@@ -18,9 +18,8 @@
String uri = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri));
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
index 32da169..ddccdaf 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
@@ -23,11 +23,10 @@
String role = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri),
mastershipRole);
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
index 9a90ef2..357d005 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
@@ -29,12 +29,11 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
DeviceService service = getService(DeviceService.class);
for (Device device : getSortedDevices(service)) {
printDevice(service, device);
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
index 07d15e2..9e21642 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
@@ -34,14 +34,13 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
DeviceService deviceService = getService(DeviceService.class);
FlowRuleService service = getService(FlowRuleService.class);
Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service);
for (Device d : deviceService.getDevices()) {
printFlows(d, flows.get(d));
}
- return null;
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
index 47aa688..c45470c 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
@@ -29,12 +29,11 @@
};
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
HostService service = getService(HostService.class);
for (Host host : getSortedHosts(service)) {
printHost(host);
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
index d74f9e4..2519bdd 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
@@ -23,14 +23,13 @@
String uri = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
LinkService service = getService(LinkService.class);
Iterable<Link> links = uri != null ?
service.getDeviceLinks(deviceId(uri)) : service.getLinks();
for (Link link : links) {
print(linkString(link));
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java
index cdede0b..8bb808a 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/PathListCommand.java
@@ -29,13 +29,12 @@
String dst = null;
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
init();
Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst));
for (Path path : paths) {
print(pathString(path));
}
- return null;
}
/**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
index 6c141ae..a258205 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
@@ -28,11 +28,10 @@
}
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
init();
print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(),
topology.clusterCount(), topology.pathCount());
- return null;
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
index 51a0fce..d0e6a70 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
@@ -16,7 +16,7 @@
public class WipeOutCommand extends ClustersListCommand {
@Override
- protected Object doExecute() throws Exception {
+ protected void execute() {
DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
DeviceService deviceService = get(DeviceService.class);
for (Device device : deviceService.getDevices()) {
@@ -28,7 +28,6 @@
for (Host host : hostService.getHosts()) {
hostAdminService.removeHost(host.id());
}
- return null;
}