use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.
the class ProxyManagerTest method testProxyManager.
@Test
public void testProxyManager() throws Exception {
TestClusterCommunicationServiceFactory clusterCommunicatorFactory = new TestClusterCommunicationServiceFactory();
NodeId a = NodeId.nodeId("a");
NodeId b = NodeId.nodeId("b");
Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
ProxyInterfaceImpl proxyInterface1 = new ProxyInterfaceImpl();
ProxyManager proxyManager1 = new ProxyManager();
proxyManager1.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(a);
proxyManager1.activate();
proxyManager1.registerProxyService(ProxyInterface.class, proxyInterface1, serializer);
ProxyInterfaceImpl proxyInterface2 = new ProxyInterfaceImpl();
ProxyManager proxyManager2 = new ProxyManager();
proxyManager2.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(b);
proxyManager2.activate();
proxyManager2.registerProxyService(ProxyInterface.class, proxyInterface2, serializer);
ProxyFactory<ProxyInterface> proxyFactory1 = proxyManager1.getProxyFactory(ProxyInterface.class, serializer);
assertEquals("Hello world!", proxyFactory1.getProxyFor(b).sync("Hello world!"));
assertEquals(1, proxyInterface2.syncCalls.get());
assertEquals("Hello world!", proxyFactory1.getProxyFor(b).async("Hello world!").join());
assertEquals(1, proxyInterface2.asyncCalls.get());
ProxyFactory<ProxyInterface> proxyFactory2 = proxyManager2.getProxyFactory(ProxyInterface.class, serializer);
assertEquals("Hello world!", proxyFactory2.getProxyFor(b).sync("Hello world!"));
assertEquals(2, proxyInterface2.syncCalls.get());
assertEquals("Hello world!", proxyFactory2.getProxyFor(b).async("Hello world!").join());
assertEquals(2, proxyInterface2.asyncCalls.get());
proxyManager1.deactivate();
proxyManager2.deactivate();
}
use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.
the class MeterManagerTest method setup.
@Before
public void setup() {
DeviceService deviceService = new TestDeviceService();
DriverRegistryManager driverRegistry = new DriverRegistryManager();
DriverManager driverService = new TestDriverManager(driverRegistry, deviceService, new NetworkConfigServiceAdapter());
driverRegistry.addDriver(new DefaultDriver("foo", ImmutableList.of(), "", "", "", ImmutableMap.of(MeterProgrammable.class, TestMeterProgrammable.class, MeterQuery.class, TestMeterQuery.class), ImmutableMap.of()));
meterStore = new DistributedMeterStore();
TestUtils.setField(meterStore, "storageService", new TestStorageService());
TestUtils.setField(meterStore, "driverService", driverService);
KryoNamespace.Builder testKryoBuilder = TestUtils.getField(meterStore, "APP_KRYO_BUILDER");
testKryoBuilder.register(TestApplicationId.class);
Serializer testSerializer = Serializer.using(Lists.newArrayList(testKryoBuilder.build()));
TestUtils.setField(meterStore, "serializer", testSerializer);
meterStore.activate();
manager = new MeterManager();
TestUtils.setField(manager, "store", meterStore);
injectEventDispatcher(manager, new TestEventDispatcher());
manager.deviceService = deviceService;
manager.mastershipService = new TestMastershipService();
manager.cfgService = new ComponentConfigAdapter();
manager.clusterService = new TestClusterService();
registry = manager;
manager.driverService = driverService;
Dictionary<String, Object> cfgDict = new Hashtable<>();
expect(componentContext.getProperties()).andReturn(cfgDict);
replay(componentContext);
manager.activate(componentContext);
provider = new TestProvider(PID);
providerService = registry.register(provider);
assertTrue("provider should be registered", registry.getProviders().contains(provider.id()));
}
use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.
the class DistributedGroupStore method activate.
@Activate
public void activate(ComponentContext context) {
cfgService.registerProperties(getClass());
modified(context);
KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder().register(KryoNamespaces.API).nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID).register(GroupStoreMessage.class, GroupStoreMessage.Type.class, UpdateType.class, GroupStoreMessageSubjects.class, MultiValuedTimestamp.class, GroupStoreKeyMapKey.class, GroupStoreIdMapKey.class, GroupStoreMapKey.class);
clusterMsgSerializer = kryoBuilder.build("GroupStore");
Serializer serializer = Serializer.using(clusterMsgSerializer);
messageHandlingExecutor = Executors.newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE, groupedThreads("onos/store/group", "message-handlers", log));
clusterCommunicator.addSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, clusterMsgSerializer::deserialize, this::process, messageHandlingExecutor);
log.debug("Creating Consistent map onos-group-store-keymap");
groupStoreEntriesByKey = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder().withName("onos-group-store-keymap").withSerializer(serializer).build();
groupStoreEntriesByKey.addListener(mapListener);
log.debug("Current size of groupstorekeymap:{}", groupStoreEntriesByKey.size());
synchronizeGroupStoreEntries();
log.debug("Creating GroupStoreId Map From GroupStoreKey Map");
matchGroupEntries();
executor = newSingleThreadScheduledExecutor(groupedThreads("onos/group", "store", log));
statusChangeListener = status -> {
if (status == Status.ACTIVE) {
executor.execute(this::matchGroupEntries);
}
};
groupStoreEntriesByKey.addStatusChangeListener(statusChangeListener);
log.debug("Creating Consistent map pendinggroupkeymap");
auditPendingReqQueue = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder().withName("onos-pending-group-keymap").withSerializer(serializer).build();
log.debug("Current size of pendinggroupkeymap:{}", auditPendingReqQueue.size());
groupTopic = getOrCreateGroupTopic(serializer);
groupTopic.subscribe(this::processGroupMessage);
local = clusterService.getLocalNode().id();
log.info("Started");
}
use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.
the class ECFlowRuleStore method storeBatch.
@Override
public void storeBatch(FlowRuleBatchOperation operation) {
if (operation.getOperations().isEmpty()) {
notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
return;
}
DeviceId deviceId = operation.deviceId();
NodeId master = mastershipService.getMasterFor(deviceId);
if (master == null) {
log.warn("Failed to storeBatch: No master for {}", deviceId);
Set<FlowRule> allFailures = operation.getOperations().stream().map(op -> op.target()).collect(Collectors.toSet());
notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
return;
}
if (Objects.equals(local, master)) {
storeBatchInternal(operation);
return;
}
log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}", master, deviceId);
clusterCommunicator.unicast(operation, APPLY_BATCH_FLOWS, serializer::encode, master).whenComplete((result, error) -> {
if (error != null) {
log.warn("Failed to storeBatch: {} to {}", operation, master, error);
Set<FlowRule> allFailures = operation.getOperations().stream().map(op -> op.target()).collect(Collectors.toSet());
notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
}
});
}
use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.
the class MastershipProxyManager method registerProxyService.
@Override
public <T> void registerProxyService(Class<? super T> type, T instance, Serializer serializer) {
checkArgument(type.isInterface(), "proxy type must be an interface");
Executor executor = new OrderedExecutor(proxyServiceExecutor);
services.computeIfAbsent(type, t -> new ProxyService(instance, t, MESSAGE_PREFIX, (i, m, o) -> new SyncOperationService(i, m, o, serializer, executor), (i, m, o) -> new AsyncOperationService(i, m, o, serializer)));
}
Aggregations