Search in sources :

Example 1 with StorageService

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

the class RouteManager method activate.

@Activate
protected void activate() {
    routeMonitor = new RouteMonitor(this, clusterService, storageService);
    routeResolver = new RouteResolver(this, hostService);
    threadFactory = groupedThreads("onos/route", "listener-%d", log);
    hostEventExecutors = new PredictableExecutor(DEFAULT_BUCKETS, groupedThreads("onos/route-manager", "event-host-%d", log));
    resolvedRouteStore = new DefaultResolvedRouteStore();
    routeStore.setDelegate(delegate);
    hostService.addListener(hostListener);
    routeStore.getRouteTables().stream().flatMap(id -> routeStore.getRoutes(id).stream()).forEach(routeSet -> routeResolver.resolve(routeSet));
}
Also used : Route(org.onosproject.routeservice.Route) Host(org.onosproject.net.Host) RouteStore(org.onosproject.routeservice.RouteStore) PredictableExecutor(org.onlab.util.PredictableExecutor) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) RouteEvent(org.onosproject.routeservice.RouteEvent) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) RouteStoreDelegate(org.onosproject.routeservice.RouteStoreDelegate) Component(org.osgi.service.component.annotations.Component) StorageService(org.onosproject.store.service.StorageService) ImmutableList(com.google.common.collect.ImmutableList) RouteAdminService(org.onosproject.routeservice.RouteAdminService) Map(java.util.Map) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) RouteService(org.onosproject.routeservice.RouteService) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) RouteListener(org.onosproject.routeservice.RouteListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) InternalRouteEvent(org.onosproject.routeservice.InternalRouteEvent) RouteInfo(org.onosproject.routeservice.RouteInfo) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RouteTableId(org.onosproject.routeservice.RouteTableId) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Reference(org.osgi.service.component.annotations.Reference) IpPrefix(org.onlab.packet.IpPrefix) PredictableExecutor(org.onlab.util.PredictableExecutor) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with StorageService

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

the class CounterTestCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    atomicCounter = storageService.getAsyncAtomicCounter(counter).asAtomicCounter();
    if ("get".equals(operation)) {
        print("%d", atomicCounter.get());
    } else if ("set".equals(operation)) {
        atomicCounter.set(value1);
    } else if ("incrementAndGet".equals(operation)) {
        print("%d", atomicCounter.incrementAndGet());
    } else if ("getAndIncrement".equals(operation)) {
        print("%d", atomicCounter.getAndIncrement());
    } else if ("getAndAdd".equals(operation)) {
        print("%d", atomicCounter.getAndAdd(value1));
    } else if ("addAndGet".equals(operation)) {
        print("%d", atomicCounter.addAndGet(value1));
    } else if ("compareAndSet".equals(operation)) {
        print("%b", atomicCounter.compareAndSet(value1, value2));
    } else if ("destroy".equals(operation)) {
        atomicCounter.destroy();
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Example 3 with StorageService

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

the class CounterTestIncrementCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    atomicCounter = storageService.getAsyncAtomicCounter(counter);
    CompletableFuture<Long> result;
    if (delta != null) {
        if (getFirst) {
            result = atomicCounter.getAndAdd(delta);
        } else {
            result = atomicCounter.addAndGet(delta);
        }
    } else {
        if (getFirst) {
            result = atomicCounter.getAndIncrement();
        } else {
            result = atomicCounter.incrementAndGet();
        }
    }
    try {
        print("%s was updated to %d", counter, result.get(3, TimeUnit.SECONDS));
    } catch (InterruptedException e) {
        return;
    } catch (ExecutionException | TimeoutException e) {
        print("Error executing command");
        log.error("Error executing command counter-test-increment", e);
    }
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) StorageService(org.onosproject.store.service.StorageService) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with StorageService

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

the class SetTestGetCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
    // Print the set size
    if (size) {
        print("There are %d items in set %s:", set.size(), setName);
    } else {
        print("Items in set %s:", setName);
    }
    // Print the set
    if (set.isEmpty()) {
        print("[]");
    } else {
        for (String e : set.toArray(new String[set.size()])) {
            if (output.isEmpty()) {
                output += e;
            } else {
                output += ", " + e;
            }
        }
        print("[%s]", output);
    }
    // Check if given values are in the set
    if (values == null) {
        return;
    } else if (values.length == 1) {
        // contains
        if (set.contains(values[0])) {
            print("Set %s contains the value %s", setName, values[0]);
        } else {
            print("Set %s did not contain the value %s", setName, values[0]);
        }
    } else if (values.length > 1) {
        // containsAll
        if (set.containsAll(Arrays.asList(values))) {
            print("Set %s contains the the subset %s", setName, Arrays.asList(values));
        } else {
            print("Set %s did not contain the the subset %s", setName, Arrays.asList(values));
        }
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Example 5 with StorageService

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

the class SetTestRemoveCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
    if (clear) {
        set.clear();
        print("Set %s cleared", setName);
        return;
    }
    if (values == null) {
        print("Error executing command: No value given");
        return;
    }
    if (retain) {
        // Keep only the given values
        if (set.retainAll(Arrays.asList(values))) {
            print("%s was pruned to contain only elements of set %s", setName, Arrays.asList(values));
        } else {
            print("%s was not changed by retaining only elements of the set %s", setName, Arrays.asList(values));
        }
    } else if (values.length == 1) {
        // Remove a single element from the set
        if (set.remove(values[0])) {
            print("[%s] was removed from the set %s", values[0], setName);
        } else {
            print("[%s] was not in set %s", values[0], setName);
        }
    } else if (values.length > 1) {
        // Remove multiple elements from a set
        if (set.removeAll(Arrays.asList(values))) {
            print("%s was removed from the set %s", Arrays.asList(values), setName);
        } else {
            print("No element of %s was in set %s", Arrays.asList(values), setName);
        }
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Aggregations

StorageService (org.onosproject.store.service.StorageService)16 Activate (org.osgi.service.component.annotations.Activate)4 Component (org.osgi.service.component.annotations.Component)4 Deactivate (org.osgi.service.component.annotations.Deactivate)4 Reference (org.osgi.service.component.annotations.Reference)4 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)4 Logger (org.slf4j.Logger)4 Collection (java.util.Collection)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 KryoNamespace (org.onlab.util.KryoNamespace)3 ClusterService (org.onosproject.cluster.ClusterService)3 KryoNamespaces (org.onosproject.store.serializers.KryoNamespaces)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 Dictionary (java.util.Dictionary)2 Map (java.util.Map)2 Objects (java.util.Objects)2 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)2 NodeId (org.onosproject.cluster.NodeId)2