use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.
the class VirtualNetworkManagerTest method testServiceGetReturnsSavedInstance.
/**
* Tests that the get() method returns saved service instances.
*/
@Test
public void testServiceGetReturnsSavedInstance() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), DeviceService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), LinkService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), TopologyService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), HostService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), PathService.class);
// extra setup needed for FlowRuleService, PacketService, GroupService, and IntentService
VirtualProviderManager virtualProviderManager = new VirtualProviderManager();
virtualProviderManager.registerProvider(new DefaultVirtualFlowRuleProvider());
virtualProviderManager.registerProvider(new DefaultVirtualPacketProvider());
virtualProviderManager.registerProvider(new DefaultVirtualGroupProvider());
testDirectory.add(CoreService.class, coreService).add(VirtualProviderRegistryService.class, virtualProviderManager).add(EventDeliveryService.class, new TestEventDispatcher()).add(ClusterService.class, new ClusterServiceAdapter()).add(VirtualNetworkFlowRuleStore.class, new SimpleVirtualFlowRuleStore()).add(VirtualNetworkPacketStore.class, new SimpleVirtualPacketStore()).add(VirtualNetworkGroupStore.class, new SimpleVirtualGroupStore()).add(VirtualNetworkIntentStore.class, new SimpleVirtualIntentStore()).add(VirtualNetworkFlowObjectiveStore.class, new SimpleVirtualFlowObjectiveStore());
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), FlowRuleService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), FlowObjectiveService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), PacketService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), GroupService.class);
validateServiceGetReturnsSavedInstance(virtualNetwork.id(), IntentService.class);
}
use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.
the class VplsOperationManagerTest method setup.
@Before
public void setup() {
MockIdGenerator.cleanBind();
vplsOperationManager = new VplsOperationManager();
vplsOperationManager.coreService = new TestCoreService();
vplsOperationManager.intentService = new TestIntentService();
vplsOperationManager.leadershipService = new TestLeadershipService();
vplsOperationManager.clusterService = new ClusterServiceAdapter();
vplsOperationManager.hostService = new TestHostService();
vplsOperationManager.vplsStore = new TestVplsStore();
vplsOperationManager.isLeader = true;
vplsOperationManager.activate();
}
use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.
the class MastershipProxyManagerTest method testProxyManager.
@Test
public void testProxyManager() throws Exception {
TestClusterCommunicationServiceFactory clusterCommunicatorFactory = new TestClusterCommunicationServiceFactory();
NodeId a = NodeId.nodeId("a");
NodeId b = NodeId.nodeId("b");
DeviceId deviceId = DeviceId.deviceId("a");
Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
ProxyInterfaceImpl proxyInterface1 = new ProxyInterfaceImpl();
MastershipProxyManager proxyManager1 = new MastershipProxyManager();
proxyManager1.clusterService = new ClusterServiceAdapter() {
@Override
public ControllerNode getLocalNode() {
return new DefaultControllerNode(a, IpAddress.valueOf(0));
}
};
proxyManager1.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(a);
proxyManager1.mastershipService = new MastershipServiceAdapter() {
@Override
public NodeId getMasterFor(DeviceId deviceId) {
return b;
}
};
proxyManager1.activate();
proxyManager1.registerProxyService(ProxyInterface.class, proxyInterface1, serializer);
ProxyInterfaceImpl proxyInterface2 = new ProxyInterfaceImpl();
MastershipProxyManager proxyManager2 = new MastershipProxyManager();
proxyManager2.clusterService = new ClusterServiceAdapter() {
@Override
public ControllerNode getLocalNode() {
return new DefaultControllerNode(b, IpAddress.valueOf(0));
}
};
proxyManager2.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(b);
proxyManager2.mastershipService = new MastershipServiceAdapter() {
@Override
public NodeId getMasterFor(DeviceId deviceId) {
return b;
}
};
proxyManager2.activate();
proxyManager2.registerProxyService(ProxyInterface.class, proxyInterface2, serializer);
MastershipProxyFactory<ProxyInterface> proxyFactory1 = proxyManager1.getProxyFactory(ProxyInterface.class, serializer);
assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).sync("Hello world!"));
assertEquals(1, proxyInterface2.syncCalls.get());
assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).async("Hello world!").join());
assertEquals(1, proxyInterface2.asyncCalls.get());
MastershipProxyFactory<ProxyInterface> proxyFactory2 = proxyManager2.getProxyFactory(ProxyInterface.class, serializer);
assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).sync("Hello world!"));
assertEquals(2, proxyInterface2.syncCalls.get());
assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).async("Hello world!").join());
assertEquals(2, proxyInterface2.asyncCalls.get());
proxyManager1.deactivate();
proxyManager2.deactivate();
}
use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.
the class PacketManagerTest method setUp.
@Before
public void setUp() {
mgr = new PacketManager();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.store = new SimplePacketStore();
mgr.clusterService = new ClusterServiceAdapter();
mgr.deviceService = new TestDeviceService();
mgr.deviceService = new TestDeviceService();
mgr.coreService = new TestCoreService();
providerRegistry = mgr;
mgr.activate();
DriverRegistryManager driverRegistry = new DriverRegistryManager();
driverService = new TestDriverManager(driverRegistry);
driverRegistry.addDriver(new DefaultDriver("foo", ImmutableList.of(), "", "", "", ImmutableMap.of(PacketProgrammable.class, TestPacketProgrammable.class), ImmutableMap.of()));
}
use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.
the class UpgradeManagerTest method createUpgradeManager.
/**
* Creates a new upgrade manager to test.
*
* @param version the local node version
* @param state the initial upgrade state
* @param versions a list of controller node versions
* @return the activated upgrade manager
*/
@SuppressWarnings("unchecked")
private UpgradeManager createUpgradeManager(Version version, Upgrade state, List<Version> versions) {
UpgradeManager upgradeManager = new UpgradeManager();
injectEventDispatcher(upgradeManager, new TestEventDispatcher());
upgradeManager.membershipService = new MembershipServiceAdapter() {
@Override
public MembershipGroup getLocalGroup() {
return getGroups().stream().filter(group -> group.version().equals(version)).findFirst().get();
}
@Override
public Collection<MembershipGroup> getGroups() {
AtomicInteger nodeCounter = new AtomicInteger();
Map<Version, Set<Member>> groups = Maps.newHashMap();
versions.stream().forEach(version -> {
groups.computeIfAbsent(version, k -> Sets.newHashSet()).add(new Member(NodeId.nodeId(String.valueOf(nodeCounter.getAndIncrement())), version));
});
return Maps.transformEntries(groups, MembershipGroup::new).values();
}
};
upgradeManager.clusterService = new ClusterServiceAdapter() {
@Override
public Set<ControllerNode> getNodes() {
AtomicInteger nodeCounter = new AtomicInteger();
return versions.stream().map(v -> {
int nodeId = nodeCounter.getAndIncrement();
return new DefaultControllerNode(NodeId.nodeId(String.valueOf(nodeId)), IpAddress.valueOf("127.0.0.1"), nodeId);
}).collect(Collectors.toSet());
}
@Override
public ControllerNode getNode(NodeId nodeId) {
return getNodes().stream().filter(node -> node.id().equals(nodeId)).findFirst().orElse(null);
}
@Override
public Version getVersion(NodeId nodeId) {
return versions.get(Integer.parseInt(nodeId.id()));
}
};
upgradeManager.versionService = new VersionServiceAdapter() {
@Override
public Version version() {
return version;
}
};
upgradeManager.coordinationService = new CoordinationServiceAdapter() {
@Override
public <V> AtomicValueBuilder<V> atomicValueBuilder() {
return new AtomicValueBuilder<V>() {
@Override
public AsyncAtomicValue<V> build() {
return new AsyncAtomicValueAdapter() {
@Override
public AtomicValue asAtomicValue() {
return new AtomicValueAdapter() {
private Object value = state;
@Override
public void set(Object value) {
this.value = value;
}
@Override
public Object get() {
return value;
}
@Override
public boolean compareAndSet(Object expect, Object update) {
if ((value == null && expect == null) || (value != null && value.equals(expect))) {
value = update;
return true;
}
return false;
}
};
}
};
}
};
}
};
upgradeManager.activate();
return upgradeManager;
}
Aggregations