Search in sources :

Example 6 with Serializer

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();
}
Also used : NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Test(org.junit.Test)

Example 7 with Serializer

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()));
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) TestStorageService(org.onosproject.store.service.TestStorageService) Hashtable(java.util.Hashtable) DeviceService(org.onosproject.net.device.DeviceService) DistributedMeterStore(org.onosproject.store.meter.impl.DistributedMeterStore) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) DefaultDriver(org.onosproject.net.driver.DefaultDriver) KryoNamespace(org.onlab.util.KryoNamespace) NetworkConfigServiceAdapter(org.onosproject.net.config.NetworkConfigServiceAdapter) DriverManager(org.onosproject.net.driver.impl.DriverManager) DriverRegistryManager(org.onosproject.net.driver.impl.DriverRegistryManager) Serializer(org.onosproject.store.service.Serializer) Before(org.junit.Before)

Example 8 with Serializer

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");
}
Also used : KryoNamespace(org.onlab.util.KryoNamespace) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) Serializer(org.onosproject.store.service.Serializer) Activate(org.osgi.service.component.annotations.Activate)

Example 9 with Serializer

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)));
        }
    });
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) REMOVE_FLOW_ENTRY(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.REMOVE_FLOW_ENTRY) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) FlowRuleService(org.onosproject.net.flow.FlowRuleService) StorageService(org.onosproject.store.service.StorageService) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Executors(java.util.concurrent.Executors) RULE_REMOVED(org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowRuleOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry.FlowRuleOperation) OrderedExecutor(org.onlab.util.OrderedExecutor) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceId(org.onosproject.net.DeviceId) REMOTE_APPLY_COMPLETED(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.REMOTE_APPLY_COMPLETED) Dictionary(java.util.Dictionary) Tools(org.onlab.util.Tools) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) Component(org.osgi.service.component.annotations.Component) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSupport(java.util.stream.StreamSupport) FlowRuleStore(org.onosproject.net.flow.FlowRuleStore) GET_FLOW_ENTRY(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.GET_FLOW_ENTRY) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) DeviceListener(org.onosproject.net.device.DeviceListener) FLOW_TABLE_BACKUP(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.FLOW_TABLE_BACKUP) OsgiPropertyConstants(org.onosproject.store.OsgiPropertyConstants) APPLY_BATCH_FLOWS(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.APPLY_BATCH_FLOWS) ExecutionException(java.util.concurrent.ExecutionException) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) FlowRuleBatchEvent(org.onosproject.net.flow.oldbatch.FlowRuleBatchEvent) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) PersistenceService(org.onosproject.persistence.PersistenceService) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) TimeoutException(java.util.concurrent.TimeoutException) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) Type(org.onosproject.net.flow.FlowRuleEvent.Type) PURGE_FLOW_RULES(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.PURGE_FLOW_RULES) GET_DEVICE_FLOW_COUNT(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.GET_DEVICE_FLOW_COUNT) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest) AsyncConsistentMap(org.onosproject.store.service.AsyncConsistentMap) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) FlowRuleStoreDelegate(org.onosproject.net.flow.FlowRuleStoreDelegate) Tools.get(org.onlab.util.Tools.get) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) ReplicaInfoService(org.onosproject.store.flow.ReplicaInfoService) IdGenerator(org.onosproject.core.IdGenerator) Math.min(java.lang.Math.min) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Math.max(java.lang.Math.max) ClusterService(org.onosproject.cluster.ClusterService) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) ReplicaInfoEventListener(org.onosproject.store.flow.ReplicaInfoEventListener) Function(java.util.function.Function) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) ExecutorService(java.util.concurrent.ExecutorService) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReplicaInfo(org.onosproject.store.flow.ReplicaInfo) ClusterMessageHandler(org.onosproject.store.cluster.messaging.ClusterMessageHandler) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) ReplicaInfoEvent(org.onosproject.store.flow.ReplicaInfoEvent) Maps(com.google.common.collect.Maps) FlowRuleStoreException(org.onosproject.net.flow.FlowRuleStoreException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ClusterMessage(org.onosproject.store.cluster.messaging.ClusterMessage) TimeUnit(java.util.concurrent.TimeUnit) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Example 10 with Serializer

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)));
}
Also used : Proxy(java.lang.reflect.Proxy) Tools(org.onlab.util.Tools) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) MastershipProxyService(org.onosproject.mastership.MastershipProxyService) Component(org.osgi.service.component.annotations.Component) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) Method(java.lang.reflect.Method) ExecutorService(java.util.concurrent.ExecutorService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) MastershipProxyFactory(org.onosproject.mastership.MastershipProxyFactory) Maps(com.google.common.collect.Maps) Executors(java.util.concurrent.Executors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) OrderedExecutor(org.onlab.util.OrderedExecutor) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) Executor(java.util.concurrent.Executor) OrderedExecutor(org.onlab.util.OrderedExecutor) MastershipProxyService(org.onosproject.mastership.MastershipProxyService) OrderedExecutor(org.onlab.util.OrderedExecutor)

Aggregations

Serializer (org.onosproject.store.service.Serializer)12 Activate (org.osgi.service.component.annotations.Activate)7 NodeId (org.onosproject.cluster.NodeId)5 KryoNamespace (org.onlab.util.KryoNamespace)4 DeviceId (org.onosproject.net.DeviceId)4 Maps (com.google.common.collect.Maps)3 Map (java.util.Map)3 ExecutorService (java.util.concurrent.ExecutorService)3 Executors (java.util.concurrent.Executors)3 Function (java.util.function.Function)3 OrderedExecutor (org.onlab.util.OrderedExecutor)3 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)3 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)3 Component (org.osgi.service.component.annotations.Component)3 Deactivate (org.osgi.service.component.annotations.Deactivate)3 Reference (org.osgi.service.component.annotations.Reference)3 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)3 Logger (org.slf4j.Logger)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Method (java.lang.reflect.Method)2