Fixed a number of CLI commands.
Refactored the StoreService/Manager stuff for common serializer pool.
Showing
34 changed files
with
183 additions
and
66 deletions
... | @@ -23,6 +23,10 @@ | ... | @@ -23,6 +23,10 @@ |
23 | <artifactId>onos-api</artifactId> | 23 | <artifactId>onos-api</artifactId> |
24 | </dependency> | 24 | </dependency> |
25 | <dependency> | 25 | <dependency> |
26 | + <groupId>org.onlab.onos</groupId> | ||
27 | + <artifactId>onlab-osgi</artifactId> | ||
28 | + </dependency> | ||
29 | + <dependency> | ||
26 | <groupId>org.osgi</groupId> | 30 | <groupId>org.osgi</groupId> |
27 | <artifactId>org.osgi.core</artifactId> | 31 | <artifactId>org.osgi.core</artifactId> |
28 | </dependency> | 32 | </dependency> | ... | ... |
1 | package org.onlab.onos.cli; | 1 | package org.onlab.onos.cli; |
2 | 2 | ||
3 | import org.apache.karaf.shell.console.OsgiCommandSupport; | 3 | import org.apache.karaf.shell.console.OsgiCommandSupport; |
4 | -import org.osgi.framework.BundleContext; | 4 | +import org.onlab.osgi.DefaultServiceDirectory; |
5 | -import org.osgi.framework.FrameworkUtil; | 5 | +import org.onlab.osgi.ServiceNotFoundException; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Base abstraction of Karaf shell commands. | 8 | * Base abstraction of Karaf shell commands. |
... | @@ -17,8 +17,7 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { | ... | @@ -17,8 +17,7 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { |
17 | * @return service implementation | 17 | * @return service implementation |
18 | */ | 18 | */ |
19 | public static <T> T get(Class<T> serviceClass) { | 19 | public static <T> T get(Class<T> serviceClass) { |
20 | - BundleContext bc = FrameworkUtil.getBundle(AbstractShellCommand.class).getBundleContext(); | 20 | + return DefaultServiceDirectory.getService(serviceClass); |
21 | - return bc.getService(bc.getServiceReference(serviceClass)); | ||
22 | } | 21 | } |
23 | 22 | ||
24 | /** | 23 | /** |
... | @@ -41,4 +40,19 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { | ... | @@ -41,4 +40,19 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { |
41 | System.err.println(String.format(format, args)); | 40 | System.err.println(String.format(format, args)); |
42 | } | 41 | } |
43 | 42 | ||
43 | + /** | ||
44 | + * Executes this command. | ||
45 | + */ | ||
46 | + protected abstract void execute(); | ||
47 | + | ||
48 | + @Override | ||
49 | + protected Object doExecute() throws Exception { | ||
50 | + try { | ||
51 | + execute(); | ||
52 | + } catch (ServiceNotFoundException e) { | ||
53 | + error(e.getMessage()); | ||
54 | + } | ||
55 | + return null; | ||
56 | + } | ||
57 | + | ||
44 | } | 58 | } | ... | ... |
... | @@ -29,8 +29,8 @@ public class NodesListCommand extends AbstractShellCommand { | ... | @@ -29,8 +29,8 @@ public class NodesListCommand extends AbstractShellCommand { |
29 | }; | 29 | }; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | - ClusterService service = getService(ClusterService.class); | 33 | + ClusterService service = get(ClusterService.class); |
34 | List<ControllerNode> nodes = newArrayList(service.getNodes()); | 34 | List<ControllerNode> nodes = newArrayList(service.getNodes()); |
35 | Collections.sort(nodes, ID_COMPARATOR); | 35 | Collections.sort(nodes, ID_COMPARATOR); |
36 | ControllerNode self = service.getLocalNode(); | 36 | ControllerNode self = service.getLocalNode(); |
... | @@ -39,7 +39,6 @@ public class NodesListCommand extends AbstractShellCommand { | ... | @@ -39,7 +39,6 @@ public class NodesListCommand extends AbstractShellCommand { |
39 | service.getState(node.id()), | 39 | service.getState(node.id()), |
40 | node.equals(self) ? "*" : ""); | 40 | node.equals(self) ? "*" : ""); |
41 | } | 41 | } |
42 | - return null; | ||
43 | } | 42 | } |
44 | 43 | ||
45 | } | 44 | } | ... | ... |
... | @@ -31,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand { | ... | @@ -31,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand { |
31 | }; | 31 | }; |
32 | 32 | ||
33 | @Override | 33 | @Override |
34 | - protected Object doExecute() throws Exception { | 34 | + protected void execute() { |
35 | int cid = Integer.parseInt(id); | 35 | int cid = Integer.parseInt(id); |
36 | init(); | 36 | init(); |
37 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); | 37 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
... | @@ -44,8 +44,6 @@ public class ClusterDevicesCommand extends ClustersListCommand { | ... | @@ -44,8 +44,6 @@ public class ClusterDevicesCommand extends ClustersListCommand { |
44 | print("%s", deviceId); | 44 | print("%s", deviceId); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | - | ||
48 | - return null; | ||
49 | } | 47 | } |
50 | 48 | ||
51 | 49 | ... | ... |
... | @@ -20,7 +20,7 @@ public class ClusterLinksCommand extends ClustersListCommand { | ... | @@ -20,7 +20,7 @@ public class ClusterLinksCommand extends ClustersListCommand { |
20 | String id = null; | 20 | String id = null; |
21 | 21 | ||
22 | @Override | 22 | @Override |
23 | - protected Object doExecute() throws Exception { | 23 | + protected void execute() { |
24 | int cid = Integer.parseInt(id); | 24 | int cid = Integer.parseInt(id); |
25 | init(); | 25 | init(); |
26 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); | 26 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
... | @@ -31,7 +31,6 @@ public class ClusterLinksCommand extends ClustersListCommand { | ... | @@ -31,7 +31,6 @@ public class ClusterLinksCommand extends ClustersListCommand { |
31 | print(linkString(link)); | 31 | print(linkString(link)); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | - return null; | ||
35 | } | 34 | } |
36 | 35 | ||
37 | } | 36 | } | ... | ... |
... | @@ -27,7 +27,7 @@ public class ClustersListCommand extends TopologyCommand { | ... | @@ -27,7 +27,7 @@ public class ClustersListCommand extends TopologyCommand { |
27 | }; | 27 | }; |
28 | 28 | ||
29 | @Override | 29 | @Override |
30 | - protected Object doExecute() throws Exception { | 30 | + protected void execute() { |
31 | init(); | 31 | init(); |
32 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); | 32 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); |
33 | Collections.sort(clusters, ID_COMPARATOR); | 33 | Collections.sort(clusters, ID_COMPARATOR); |
... | @@ -35,7 +35,6 @@ public class ClustersListCommand extends TopologyCommand { | ... | @@ -35,7 +35,6 @@ public class ClustersListCommand extends TopologyCommand { |
35 | for (TopologyCluster cluster : clusters) { | 35 | for (TopologyCluster cluster : clusters) { |
36 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); | 36 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); |
37 | } | 37 | } |
38 | - return null; | ||
39 | } | 38 | } |
40 | 39 | ||
41 | } | 40 | } | ... | ... |
... | @@ -35,7 +35,7 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -35,7 +35,7 @@ public class DevicePortsListCommand extends DevicesListCommand { |
35 | }; | 35 | }; |
36 | 36 | ||
37 | @Override | 37 | @Override |
38 | - protected Object doExecute() throws Exception { | 38 | + protected void execute() { |
39 | DeviceService service = getService(DeviceService.class); | 39 | DeviceService service = getService(DeviceService.class); |
40 | if (uri == null) { | 40 | if (uri == null) { |
41 | for (Device device : getSortedDevices(service)) { | 41 | for (Device device : getSortedDevices(service)) { |
... | @@ -49,7 +49,6 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -49,7 +49,6 @@ public class DevicePortsListCommand extends DevicesListCommand { |
49 | printDevice(service, device); | 49 | printDevice(service, device); |
50 | } | 50 | } |
51 | } | 51 | } |
52 | - return null; | ||
53 | } | 52 | } |
54 | 53 | ||
55 | @Override | 54 | @Override | ... | ... |
... | @@ -18,9 +18,8 @@ public class DeviceRemoveCommand extends AbstractShellCommand { | ... | @@ -18,9 +18,8 @@ public class DeviceRemoveCommand extends AbstractShellCommand { |
18 | String uri = null; | 18 | String uri = null; |
19 | 19 | ||
20 | @Override | 20 | @Override |
21 | - protected Object doExecute() throws Exception { | 21 | + protected void execute() { |
22 | getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri)); | 22 | getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri)); |
23 | - return null; | ||
24 | } | 23 | } |
25 | 24 | ||
26 | } | 25 | } | ... | ... |
... | @@ -23,11 +23,10 @@ public class DeviceRoleCommand extends AbstractShellCommand { | ... | @@ -23,11 +23,10 @@ public class DeviceRoleCommand extends AbstractShellCommand { |
23 | String role = null; | 23 | String role = null; |
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | - protected Object doExecute() throws Exception { | 26 | + protected void execute() { |
27 | MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase()); | 27 | MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase()); |
28 | getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri), | 28 | getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri), |
29 | mastershipRole); | 29 | mastershipRole); |
30 | - return null; | ||
31 | } | 30 | } |
32 | 31 | ||
33 | } | 32 | } | ... | ... |
... | @@ -29,12 +29,11 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -29,12 +29,11 @@ public class DevicesListCommand extends AbstractShellCommand { |
29 | }; | 29 | }; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | DeviceService service = getService(DeviceService.class); | 33 | DeviceService service = getService(DeviceService.class); |
34 | for (Device device : getSortedDevices(service)) { | 34 | for (Device device : getSortedDevices(service)) { |
35 | printDevice(service, device); | 35 | printDevice(service, device); |
36 | } | 36 | } |
37 | - return null; | ||
38 | } | 37 | } |
39 | 38 | ||
40 | /** | 39 | /** | ... | ... |
... | @@ -34,14 +34,13 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -34,14 +34,13 @@ public class FlowsListCommand extends AbstractShellCommand { |
34 | }; | 34 | }; |
35 | 35 | ||
36 | @Override | 36 | @Override |
37 | - protected Object doExecute() throws Exception { | 37 | + protected void execute() { |
38 | DeviceService deviceService = getService(DeviceService.class); | 38 | DeviceService deviceService = getService(DeviceService.class); |
39 | FlowRuleService service = getService(FlowRuleService.class); | 39 | FlowRuleService service = getService(FlowRuleService.class); |
40 | Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service); | 40 | Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service); |
41 | for (Device d : deviceService.getDevices()) { | 41 | for (Device d : deviceService.getDevices()) { |
42 | printFlows(d, flows.get(d)); | 42 | printFlows(d, flows.get(d)); |
43 | } | 43 | } |
44 | - return null; | ||
45 | } | 44 | } |
46 | 45 | ||
47 | 46 | ... | ... |
... | @@ -29,12 +29,11 @@ public class HostsListCommand extends AbstractShellCommand { | ... | @@ -29,12 +29,11 @@ public class HostsListCommand extends AbstractShellCommand { |
29 | }; | 29 | }; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | HostService service = getService(HostService.class); | 33 | HostService service = getService(HostService.class); |
34 | for (Host host : getSortedHosts(service)) { | 34 | for (Host host : getSortedHosts(service)) { |
35 | printHost(host); | 35 | printHost(host); |
36 | } | 36 | } |
37 | - return null; | ||
38 | } | 37 | } |
39 | 38 | ||
40 | /** | 39 | /** | ... | ... |
... | @@ -23,14 +23,13 @@ public class LinksListCommand extends AbstractShellCommand { | ... | @@ -23,14 +23,13 @@ public class LinksListCommand extends AbstractShellCommand { |
23 | String uri = null; | 23 | String uri = null; |
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | - protected Object doExecute() throws Exception { | 26 | + protected void execute() { |
27 | LinkService service = getService(LinkService.class); | 27 | LinkService service = getService(LinkService.class); |
28 | Iterable<Link> links = uri != null ? | 28 | Iterable<Link> links = uri != null ? |
29 | service.getDeviceLinks(deviceId(uri)) : service.getLinks(); | 29 | service.getDeviceLinks(deviceId(uri)) : service.getLinks(); |
30 | for (Link link : links) { | 30 | for (Link link : links) { |
31 | print(linkString(link)); | 31 | print(linkString(link)); |
32 | } | 32 | } |
33 | - return null; | ||
34 | } | 33 | } |
35 | 34 | ||
36 | /** | 35 | /** | ... | ... |
... | @@ -29,13 +29,12 @@ public class PathListCommand extends TopologyCommand { | ... | @@ -29,13 +29,12 @@ public class PathListCommand extends TopologyCommand { |
29 | String dst = null; | 29 | String dst = null; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | init(); | 33 | init(); |
34 | Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst)); | 34 | Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst)); |
35 | for (Path path : paths) { | 35 | for (Path path : paths) { |
36 | print(pathString(path)); | 36 | print(pathString(path)); |
37 | } | 37 | } |
38 | - return null; | ||
39 | } | 38 | } |
40 | 39 | ||
41 | /** | 40 | /** | ... | ... |
... | @@ -28,11 +28,10 @@ public class TopologyCommand extends AbstractShellCommand { | ... | @@ -28,11 +28,10 @@ public class TopologyCommand extends AbstractShellCommand { |
28 | } | 28 | } |
29 | 29 | ||
30 | @Override | 30 | @Override |
31 | - protected Object doExecute() throws Exception { | 31 | + protected void execute() { |
32 | init(); | 32 | init(); |
33 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), | 33 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), |
34 | topology.clusterCount(), topology.pathCount()); | 34 | topology.clusterCount(), topology.pathCount()); |
35 | - return null; | ||
36 | } | 35 | } |
37 | 36 | ||
38 | } | 37 | } | ... | ... |
... | @@ -16,7 +16,7 @@ import org.onlab.onos.net.host.HostService; | ... | @@ -16,7 +16,7 @@ import org.onlab.onos.net.host.HostService; |
16 | public class WipeOutCommand extends ClustersListCommand { | 16 | public class WipeOutCommand extends ClustersListCommand { |
17 | 17 | ||
18 | @Override | 18 | @Override |
19 | - protected Object doExecute() throws Exception { | 19 | + protected void execute() { |
20 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); | 20 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); |
21 | DeviceService deviceService = get(DeviceService.class); | 21 | DeviceService deviceService = get(DeviceService.class); |
22 | for (Device device : deviceService.getDevices()) { | 22 | for (Device device : deviceService.getDevices()) { |
... | @@ -28,7 +28,6 @@ public class WipeOutCommand extends ClustersListCommand { | ... | @@ -28,7 +28,6 @@ public class WipeOutCommand extends ClustersListCommand { |
28 | for (Host host : hostService.getHosts()) { | 28 | for (Host host : hostService.getHosts()) { |
29 | hostAdminService.removeHost(host.id()); | 29 | hostAdminService.removeHost(host.id()); |
30 | } | 30 | } |
31 | - return null; | ||
32 | } | 31 | } |
33 | 32 | ||
34 | 33 | ... | ... |
... | @@ -37,6 +37,9 @@ public interface MastershipService { | ... | @@ -37,6 +37,9 @@ public interface MastershipService { |
37 | */ | 37 | */ |
38 | MastershipRole requestRoleFor(DeviceId deviceId); | 38 | MastershipRole requestRoleFor(DeviceId deviceId); |
39 | 39 | ||
40 | + // TODO: add facet for requesting a different master than the current one; | ||
41 | + // abandon mastership (due to loss of connection) | ||
42 | + | ||
40 | /** | 43 | /** |
41 | * Adds the specified mastership change listener. | 44 | * Adds the specified mastership change listener. |
42 | * | 45 | * | ... | ... |
... | @@ -15,7 +15,7 @@ public interface DeviceAdminService { | ... | @@ -15,7 +15,7 @@ public interface DeviceAdminService { |
15 | * @param role requested role | 15 | * @param role requested role |
16 | * @deprecated Will be removed in favor of MastershipAdminService.setRole() | 16 | * @deprecated Will be removed in favor of MastershipAdminService.setRole() |
17 | */ | 17 | */ |
18 | - @Deprecated | 18 | +// @Deprecated |
19 | void setRole(DeviceId deviceId, MastershipRole role); | 19 | void setRole(DeviceId deviceId, MastershipRole role); |
20 | 20 | ||
21 | /** | 21 | /** | ... | ... |
1 | package org.onlab.onos.net.device.impl; | 1 | package org.onlab.onos.net.device.impl; |
2 | 2 | ||
3 | +import com.google.common.collect.Iterables; | ||
4 | +import com.hazelcast.config.Config; | ||
5 | +import com.hazelcast.core.Hazelcast; | ||
3 | import com.hazelcast.core.HazelcastInstance; | 6 | import com.hazelcast.core.HazelcastInstance; |
4 | import org.junit.After; | 7 | import org.junit.After; |
5 | import org.junit.Before; | 8 | import org.junit.Before; |
6 | import org.junit.Test; | 9 | import org.junit.Test; |
7 | import org.onlab.onos.event.Event; | 10 | import org.onlab.onos.event.Event; |
11 | +import org.onlab.onos.event.impl.TestEventDispatcher; | ||
8 | import org.onlab.onos.net.Device; | 12 | import org.onlab.onos.net.Device; |
9 | import org.onlab.onos.net.DeviceId; | 13 | import org.onlab.onos.net.DeviceId; |
10 | import org.onlab.onos.net.MastershipRole; | 14 | import org.onlab.onos.net.MastershipRole; |
... | @@ -23,13 +27,9 @@ import org.onlab.onos.net.device.DeviceService; | ... | @@ -23,13 +27,9 @@ import org.onlab.onos.net.device.DeviceService; |
23 | import org.onlab.onos.net.device.PortDescription; | 27 | import org.onlab.onos.net.device.PortDescription; |
24 | import org.onlab.onos.net.provider.AbstractProvider; | 28 | import org.onlab.onos.net.provider.AbstractProvider; |
25 | import org.onlab.onos.net.provider.ProviderId; | 29 | import org.onlab.onos.net.provider.ProviderId; |
26 | -import org.onlab.onos.event.impl.TestEventDispatcher; | ||
27 | import org.onlab.onos.store.StoreService; | 30 | import org.onlab.onos.store.StoreService; |
28 | import org.onlab.onos.store.device.impl.DistributedDeviceStore; | 31 | import org.onlab.onos.store.device.impl.DistributedDeviceStore; |
29 | - | 32 | +import org.onlab.onos.store.impl.StoreManager; |
30 | -import com.google.common.collect.Iterables; | ||
31 | -import com.hazelcast.config.Config; | ||
32 | -import com.hazelcast.core.Hazelcast; | ||
33 | 33 | ||
34 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
35 | import java.util.Iterator; | 35 | import java.util.Iterator; |
... | @@ -64,6 +64,7 @@ public class DistributedDeviceManagerTest { | ... | @@ -64,6 +64,7 @@ public class DistributedDeviceManagerTest { |
64 | 64 | ||
65 | private DeviceManager mgr; | 65 | private DeviceManager mgr; |
66 | 66 | ||
67 | + protected StoreManager storeManager; | ||
67 | protected DeviceService service; | 68 | protected DeviceService service; |
68 | protected DeviceAdminService admin; | 69 | protected DeviceAdminService admin; |
69 | protected DeviceProviderRegistry registry; | 70 | protected DeviceProviderRegistry registry; |
... | @@ -89,7 +90,11 @@ public class DistributedDeviceManagerTest { | ... | @@ -89,7 +90,11 @@ public class DistributedDeviceManagerTest { |
89 | config.getNetworkConfig().getJoin() | 90 | config.getNetworkConfig().getJoin() |
90 | .getMulticastConfig() | 91 | .getMulticastConfig() |
91 | .setEnabled(false); | 92 | .setEnabled(false); |
92 | - dstore = new TestDistributedDeviceStore(Hazelcast.newHazelcastInstance(config)); | 93 | + |
94 | + storeManager = new TestStoreManager(Hazelcast.newHazelcastInstance(config)); | ||
95 | + storeManager.activate(); | ||
96 | + | ||
97 | + dstore = new TestDistributedDeviceStore(storeManager); | ||
93 | dstore.activate(); | 98 | dstore.activate(); |
94 | mgr.store = dstore; | 99 | mgr.store = dstore; |
95 | mgr.eventDispatcher = new TestEventDispatcher(); | 100 | mgr.eventDispatcher = new TestEventDispatcher(); |
... | @@ -112,7 +117,7 @@ public class DistributedDeviceManagerTest { | ... | @@ -112,7 +117,7 @@ public class DistributedDeviceManagerTest { |
112 | mgr.deactivate(); | 117 | mgr.deactivate(); |
113 | 118 | ||
114 | dstore.deactivate(); | 119 | dstore.deactivate(); |
115 | - ((TestDistributedDeviceStore) dstore).shutdownHz(); | 120 | + storeManager.deactivate(); |
116 | } | 121 | } |
117 | 122 | ||
118 | private void connectDevice(DeviceId deviceId, String swVersion) { | 123 | private void connectDevice(DeviceId deviceId, String swVersion) { |
... | @@ -282,20 +287,19 @@ public class DistributedDeviceManagerTest { | ... | @@ -282,20 +287,19 @@ public class DistributedDeviceManagerTest { |
282 | } | 287 | } |
283 | 288 | ||
284 | private class TestDistributedDeviceStore extends DistributedDeviceStore { | 289 | private class TestDistributedDeviceStore extends DistributedDeviceStore { |
285 | - public TestDistributedDeviceStore(final HazelcastInstance hazelcastInstance) { | 290 | + public TestDistributedDeviceStore(StoreService storeService) { |
286 | - storeService = new StoreService() { | 291 | + this.storeService = storeService; |
287 | - @Override | ||
288 | - public HazelcastInstance getHazelcastInstance() { | ||
289 | - return hazelcastInstance; | ||
290 | - } | ||
291 | - }; | ||
292 | } | 292 | } |
293 | + } | ||
293 | 294 | ||
294 | - /** | 295 | + private class TestStoreManager extends StoreManager { |
295 | - * Shutdowns the hazelcast instance. | 296 | + TestStoreManager(HazelcastInstance instance) { |
296 | - */ | 297 | + this.instance = instance; |
297 | - public void shutdownHz() { | 298 | + } |
298 | - theInstance.shutdown(); | 299 | + |
300 | + @Override | ||
301 | + public void activate() { | ||
302 | + setupKryoPool(); | ||
299 | } | 303 | } |
300 | } | 304 | } |
301 | } | 305 | } | ... | ... |
... | @@ -15,4 +15,22 @@ public interface StoreService { | ... | @@ -15,4 +15,22 @@ public interface StoreService { |
15 | */ | 15 | */ |
16 | HazelcastInstance getHazelcastInstance(); | 16 | HazelcastInstance getHazelcastInstance(); |
17 | 17 | ||
18 | + /** | ||
19 | + * Serializes the specified object into bytes using one of the | ||
20 | + * pre-registered serializers. | ||
21 | + * | ||
22 | + * @param obj object to be serialized | ||
23 | + * @return serialized bytes | ||
24 | + */ | ||
25 | + public byte[] serialize(final Object obj); | ||
26 | + | ||
27 | + /** | ||
28 | + * Deserializes the specified bytes into an object using one of the | ||
29 | + * pre-registered serializers. | ||
30 | + * | ||
31 | + * @param bytes bytes to be deserialized | ||
32 | + * @return deserialized object | ||
33 | + */ | ||
34 | + public <T> T deserialize(final byte[] bytes); | ||
35 | + | ||
18 | } | 36 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -2,14 +2,33 @@ package org.onlab.onos.store.impl; | ... | @@ -2,14 +2,33 @@ package org.onlab.onos.store.impl; |
2 | 2 | ||
3 | import com.hazelcast.core.Hazelcast; | 3 | import com.hazelcast.core.Hazelcast; |
4 | import com.hazelcast.core.HazelcastInstance; | 4 | import com.hazelcast.core.HazelcastInstance; |
5 | +import de.javakaffee.kryoserializers.URISerializer; | ||
5 | import org.apache.felix.scr.annotations.Activate; | 6 | import org.apache.felix.scr.annotations.Activate; |
6 | import org.apache.felix.scr.annotations.Component; | 7 | import org.apache.felix.scr.annotations.Component; |
7 | import org.apache.felix.scr.annotations.Deactivate; | 8 | import org.apache.felix.scr.annotations.Deactivate; |
8 | import org.apache.felix.scr.annotations.Service; | 9 | import org.apache.felix.scr.annotations.Service; |
10 | +import org.onlab.onos.net.DefaultDevice; | ||
11 | +import org.onlab.onos.net.DefaultPort; | ||
12 | +import org.onlab.onos.net.Device; | ||
13 | +import org.onlab.onos.net.DeviceId; | ||
14 | +import org.onlab.onos.net.Element; | ||
15 | +import org.onlab.onos.net.MastershipRole; | ||
16 | +import org.onlab.onos.net.Port; | ||
17 | +import org.onlab.onos.net.PortNumber; | ||
18 | +import org.onlab.onos.net.provider.ProviderId; | ||
9 | import org.onlab.onos.store.StoreService; | 19 | import org.onlab.onos.store.StoreService; |
20 | +import org.onlab.onos.store.serializers.DefaultPortSerializer; | ||
21 | +import org.onlab.onos.store.serializers.DeviceIdSerializer; | ||
22 | +import org.onlab.onos.store.serializers.PortNumberSerializer; | ||
23 | +import org.onlab.onos.store.serializers.ProviderIdSerializer; | ||
24 | +import org.onlab.util.KryoPool; | ||
10 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 26 | import org.slf4j.LoggerFactory; |
12 | 27 | ||
28 | +import java.net.URI; | ||
29 | +import java.util.ArrayList; | ||
30 | +import java.util.HashMap; | ||
31 | + | ||
13 | /** | 32 | /** |
14 | * Auxiliary bootstrap of distributed store. | 33 | * Auxiliary bootstrap of distributed store. |
15 | */ | 34 | */ |
... | @@ -20,15 +39,45 @@ public class StoreManager implements StoreService { | ... | @@ -20,15 +39,45 @@ public class StoreManager implements StoreService { |
20 | private final Logger log = LoggerFactory.getLogger(getClass()); | 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
21 | 40 | ||
22 | protected HazelcastInstance instance; | 41 | protected HazelcastInstance instance; |
42 | + private KryoPool serializerPool; | ||
43 | + | ||
23 | 44 | ||
24 | @Activate | 45 | @Activate |
25 | public void activate() { | 46 | public void activate() { |
26 | instance = Hazelcast.newHazelcastInstance(); | 47 | instance = Hazelcast.newHazelcastInstance(); |
48 | + setupKryoPool(); | ||
27 | log.info("Started"); | 49 | log.info("Started"); |
28 | } | 50 | } |
29 | 51 | ||
52 | + /** | ||
53 | + * Sets up the common serialzers pool. | ||
54 | + */ | ||
55 | + protected void setupKryoPool() { | ||
56 | + // FIXME Slice out types used in common to separate pool/namespace. | ||
57 | + serializerPool = KryoPool.newBuilder() | ||
58 | + .register( | ||
59 | + ArrayList.class, | ||
60 | + HashMap.class, | ||
61 | + | ||
62 | + Device.Type.class, | ||
63 | + | ||
64 | + DefaultDevice.class, | ||
65 | + MastershipRole.class, | ||
66 | + Port.class, | ||
67 | + Element.class | ||
68 | + ) | ||
69 | + .register(URI.class, new URISerializer()) | ||
70 | + .register(ProviderId.class, new ProviderIdSerializer()) | ||
71 | + .register(DeviceId.class, new DeviceIdSerializer()) | ||
72 | + .register(PortNumber.class, new PortNumberSerializer()) | ||
73 | + .register(DefaultPort.class, new DefaultPortSerializer()) | ||
74 | + .build() | ||
75 | + .populate(10); | ||
76 | + } | ||
77 | + | ||
30 | @Deactivate | 78 | @Deactivate |
31 | public void deactivate() { | 79 | public void deactivate() { |
80 | + instance.shutdown(); | ||
32 | log.info("Stopped"); | 81 | log.info("Stopped"); |
33 | } | 82 | } |
34 | 83 | ||
... | @@ -36,4 +85,19 @@ public class StoreManager implements StoreService { | ... | @@ -36,4 +85,19 @@ public class StoreManager implements StoreService { |
36 | public HazelcastInstance getHazelcastInstance() { | 85 | public HazelcastInstance getHazelcastInstance() { |
37 | return instance; | 86 | return instance; |
38 | } | 87 | } |
88 | + | ||
89 | + | ||
90 | + @Override | ||
91 | + public byte[] serialize(final Object obj) { | ||
92 | + return serializerPool.serialize(obj); | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public <T> T deserialize(final byte[] bytes) { | ||
97 | + if (bytes == null) { | ||
98 | + return null; | ||
99 | + } | ||
100 | + return serializerPool.deserialize(bytes); | ||
101 | + } | ||
102 | + | ||
39 | } | 103 | } | ... | ... |
... | @@ -172,6 +172,11 @@ | ... | @@ -172,6 +172,11 @@ |
172 | </dependency> | 172 | </dependency> |
173 | <dependency> | 173 | <dependency> |
174 | <groupId>org.onlab.onos</groupId> | 174 | <groupId>org.onlab.onos</groupId> |
175 | + <artifactId>onlab-osgi</artifactId> | ||
176 | + <version>${project.version}</version> | ||
177 | + </dependency> | ||
178 | + <dependency> | ||
179 | + <groupId>org.onlab.onos</groupId> | ||
175 | <artifactId>onlab-junit</artifactId> | 180 | <artifactId>onlab-junit</artifactId> |
176 | <version>1.0.0-SNAPSHOT</version> | 181 | <version>1.0.0-SNAPSHOT</version> |
177 | <scope>test</scope> | 182 | <scope>test</scope> | ... | ... |
... | @@ -46,7 +46,8 @@ alias gui='open http://localhost:8181/onos/tvue' | ... | @@ -46,7 +46,8 @@ alias gui='open http://localhost:8181/onos/tvue' |
46 | # Test related conveniences | 46 | # Test related conveniences |
47 | 47 | ||
48 | # SSH to a specified ONOS instance | 48 | # SSH to a specified ONOS instance |
49 | -alias sshctl=onos-ssh | 49 | +alias sshctl='onos-ssh' |
50 | +alias sshnet='onos-ssh $OCN' | ||
50 | 51 | ||
51 | # Applies the settings in the specified cell file or lists current cell definition | 52 | # Applies the settings in the specified cell file or lists current cell definition |
52 | # if no cell file is given. | 53 | # if no cell file is given. |
... | @@ -62,6 +63,7 @@ function cell { | ... | @@ -62,6 +63,7 @@ function cell { |
62 | env | egrep "ONOS_CELL" | 63 | env | egrep "ONOS_CELL" |
63 | env | egrep "OCI" | 64 | env | egrep "OCI" |
64 | env | egrep "OC[0-9]+" | sort | 65 | env | egrep "OC[0-9]+" | sort |
66 | + env | egrep "OCN" | ||
65 | fi | 67 | fi |
66 | } | 68 | } |
67 | 69 | ... | ... |
... | @@ -6,6 +6,6 @@ | ... | @@ -6,6 +6,6 @@ |
6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
7 | . $ONOS_ROOT/tools/build/envDefaults | 7 | . $ONOS_ROOT/tools/build/envDefaults |
8 | 8 | ||
9 | -for node in $(env | sort | egrep "OC[0-9]+" | cut -d= -f2); do | 9 | +for node in $(env | sort | egrep "OC[0-9N]+" | cut -d= -f2); do |
10 | printf "%s: " $node; ssh -n -o PasswordAuthentication=no $ONOS_USER@$node date | 10 | printf "%s: " $node; ssh -n -o PasswordAuthentication=no $ONOS_USER@$node date |
11 | done | 11 | done |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -# Default virtual box ONOS instances 1,2 & 3 | 1 | +# Default virtual box ONOS instances 1,2 & ONOS mininet box |
2 | 2 | ||
3 | export OC1="192.168.56.101" | 3 | export OC1="192.168.56.101" |
4 | export OC2="192.168.56.102" | 4 | export OC2="192.168.56.102" |
5 | -export OC3="192.168.56.103" | 5 | + |
6 | +export OCN="192.168.56.103" | ||
6 | 7 | ||
7 | 8 | ... | ... |
... | @@ -7,8 +7,15 @@ import org.osgi.framework.FrameworkUtil; | ... | @@ -7,8 +7,15 @@ import org.osgi.framework.FrameworkUtil; |
7 | * Default implementation of the service directory using OSGi framework utilities. | 7 | * Default implementation of the service directory using OSGi framework utilities. |
8 | */ | 8 | */ |
9 | public class DefaultServiceDirectory implements ServiceDirectory { | 9 | public class DefaultServiceDirectory implements ServiceDirectory { |
10 | - @Override | 10 | + |
11 | - public <T> T get(Class<T> serviceClass) { | 11 | + /** |
12 | + * Returns the reference to the implementation of the specified service. | ||
13 | + * | ||
14 | + * @param serviceClass service class | ||
15 | + * @param <T> type of service | ||
16 | + * @return service implementation | ||
17 | + */ | ||
18 | + public static <T> T getService(Class<T> serviceClass) { | ||
12 | BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext(); | 19 | BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext(); |
13 | T impl = bc.getService(bc.getServiceReference(serviceClass)); | 20 | T impl = bc.getService(bc.getServiceReference(serviceClass)); |
14 | if (impl == null) { | 21 | if (impl == null) { |
... | @@ -16,4 +23,10 @@ public class DefaultServiceDirectory implements ServiceDirectory { | ... | @@ -16,4 +23,10 @@ public class DefaultServiceDirectory implements ServiceDirectory { |
16 | } | 23 | } |
17 | return impl; | 24 | return impl; |
18 | } | 25 | } |
26 | + | ||
27 | + @Override | ||
28 | + public <T> T get(Class<T> serviceClass) { | ||
29 | + return getService(serviceClass); | ||
30 | + } | ||
31 | + | ||
19 | } | 32 | } | ... | ... |
-
Please register or login to post a comment