Search in sources :

Example 1 with Serializer

use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.

the class DistributedMappingStore method activate.

@Activate
public void activate() {
    Serializer serializer = Serializer.using(KryoNamespaces.API, Mapping.class, DefaultMapping.class, MappingId.class, MappingEvent.Type.class, MappingKey.class, MappingValue.class, MappingAddress.class, MappingAddress.Type.class, MappingAction.class, MappingAction.Type.class, MappingTreatment.class, MappingInstruction.class, MappingInstruction.Type.class);
    database = storageService.<MappingId, Mapping>consistentMapBuilder().withName("onos-mapping-database").withSerializer(serializer).build();
    cache = storageService.<MappingId, Mapping>consistentMapBuilder().withName("onos-mapping-cache").withSerializer(serializer).build();
    database.addListener(listener);
    cache.addListener(listener);
    databaseMap = database.asJavaMap();
    cacheMap = cache.asJavaMap();
    log.info("Started");
}
Also used : MappingId(org.onosproject.mapping.MappingId) MappingEvent(org.onosproject.mapping.MappingEvent) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) MappingAction(org.onosproject.mapping.actions.MappingAction) DefaultMapping(org.onosproject.mapping.DefaultMapping) Mapping(org.onosproject.mapping.Mapping) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction) Serializer(org.onosproject.store.service.Serializer) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with Serializer

use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.

the class WorkQueueTestCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
    queue = storageService.getWorkQueue(name, serializer);
    if ("add".equals(operation)) {
        if (value1 == null) {
            print("Usage: add <value1>");
        } else {
            get(queue.addOne(value1));
            print("Done");
        }
    } else if ("addMultiple".equals(operation)) {
        if (value1 == null || value2 == null) {
            print("Usage: addMultiple <value1> <value2>");
        } else {
            get(queue.addMultiple(Arrays.asList(value1, value2)));
            print("Done");
        }
    } else if ("takeAndComplete".equals(operation)) {
        int maxItems = value1 != null ? Integer.parseInt(value1) : 1;
        Collection<Task<String>> tasks = get(queue.take(maxItems));
        tasks.forEach(task -> get(queue.complete(task.taskId())));
        print("Done");
    } else if ("totalPending".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalPending());
    } else if ("totalInProgress".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalInProgress());
    } else if ("totalCompleted".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalCompleted());
    } else if ("destroy".equals(operation)) {
        get(queue.destroy());
    } else {
        print("Invalid operation name. Valid operations names are:" + " [add, addMultiple takeAndComplete, totalPending, totalInProgress, totalCompleted, destroy]");
    }
}
Also used : Task(org.onosproject.store.service.Task) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) StorageService(org.onosproject.store.service.StorageService) Serializer(org.onosproject.store.service.Serializer)

Example 3 with Serializer

use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.

the class ProxyManager 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) ProxyFactory(org.onosproject.cluster.ProxyFactory) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ProxyService(org.onosproject.cluster.ProxyService) 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) Method(java.lang.reflect.Method) ExecutorService(java.util.concurrent.ExecutorService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) Deactivate(org.osgi.service.component.annotations.Deactivate) CompletionException(java.util.concurrent.CompletionException) Maps(com.google.common.collect.Maps) Executors(java.util.concurrent.Executors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OrderedExecutor(org.onlab.util.OrderedExecutor) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Reference(org.osgi.service.component.annotations.Reference) Executor(java.util.concurrent.Executor) OrderedExecutor(org.onlab.util.OrderedExecutor) ProxyService(org.onosproject.cluster.ProxyService) OrderedExecutor(org.onlab.util.OrderedExecutor)

Example 4 with Serializer

use of org.onosproject.store.service.Serializer 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();
}
Also used : DeviceId(org.onosproject.net.DeviceId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Test(org.junit.Test)

Example 5 with Serializer

use of org.onosproject.store.service.Serializer in project onos by opennetworkinglab.

the class DistributedRegionStore method activate.

@Activate
protected void activate() {
    Serializer serializer = Serializer.using(Arrays.asList(KryoNamespaces.API), Identifier.class);
    regionsRepo = storageService.<RegionId, Region>consistentMapBuilder().withSerializer(serializer).withName("onos-regions").withRelaxedReadConsistency().build();
    regionsRepo.addListener(listener);
    regionsById = regionsRepo.asJavaMap();
    membershipRepo = storageService.<RegionId, Set<DeviceId>>consistentMapBuilder().withSerializer(serializer).withName("onos-region-devices").withRelaxedReadConsistency().build();
    membershipRepo.addListener(membershipListener);
    regionDevices = membershipRepo.asJavaMap();
    log.info("Started");
}
Also used : DeviceId(org.onosproject.net.DeviceId) Serializer(org.onosproject.store.service.Serializer) Activate(org.osgi.service.component.annotations.Activate)

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