Search in sources :

Example 11 with Versioned

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

the class DistributedDynamicConfigStore method readInner.

private void readInner(DataNode.Builder superBldr, String spath) {
    CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren(DocumentPath.from(spath));
    Map<String, Versioned<DataNode.Type>> entries = null;
    entries = complete(ret);
    log.trace(" keystore.getChildren({})", spath);
    log.trace("  entries keys:{}", entries.keySet());
    if (!entries.isEmpty()) {
        entries.forEach((k, v) -> {
            String[] names = k.split(ResourceIdParser.NM_CHK);
            String name = names[0];
            String nmSpc = ResourceIdParser.getNamespace(names[1]);
            String keyVal = ResourceIdParser.getKeyVal(names[1]);
            DataNode.Type type = v.value();
            String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc);
            if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
                LeafNode lfnode = readLeaf(tempPath);
                // FIXME there should be builder for copying
                superBldr.createChildBuilder(name, nmSpc, lfnode.value(), lfnode.valueNamespace()).type(type).leafType(lfnode.leafType()).exitNode();
            } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
                String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal);
                LeafNode lfnode = readLeaf(mlpath);
                // FIXME there should be builder for copying
                superBldr.createChildBuilder(name, nmSpc, lfnode.value(), lfnode.valueNamespace()).type(type).leafType(lfnode.leafType()).addLeafListValue(lfnode.value()).exitNode();
            // TODO this alone should be sufficient and take the nm, nmspc too
            } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
                DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc).type(type);
                readInner(tempBldr, tempPath);
            } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
                DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc).type(type);
                tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k);
                String[] keys = k.split(ResourceIdParser.KEY_CHK);
                for (int i = 1; i < keys.length; i++) {
                    // String curKey = ResourceIdParser.appendKeyLeaf(tempPath, keys[i]);
                    // LeafNode lfnd = readLeaf(curKey);
                    String[] keydata = keys[i].split(ResourceIdParser.NM_CHK);
                    tempBldr.addKeyLeaf(keydata[0], keydata[1], keydata[2]);
                }
                readInner(tempBldr, tempPath);
            } else {
                throw new FailedException("Invalid node type");
            }
        });
    }
    superBldr.exitNode();
}
Also used : Versioned(org.onosproject.store.service.Versioned) LeafType(org.onosproject.yang.model.LeafType) DataNode(org.onosproject.yang.model.DataNode) FailedException(org.onosproject.config.FailedException) LeafNode(org.onosproject.yang.model.LeafNode) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with Versioned

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

the class DistributedDhcpStore method listAssignedMapping.

@Override
public Map<HostId, IpAssignment> listAssignedMapping() {
    Map<HostId, IpAssignment> validMapping = new HashMap<>();
    IpAssignment assignment;
    for (Map.Entry<HostId, Versioned<IpAssignment>> entry : allocationMap.entrySet()) {
        assignment = entry.getValue().value();
        if (assignment.assignmentStatus() == Option_Assigned || assignment.assignmentStatus() == Option_RangeNotEnforced) {
            validMapping.put(entry.getKey(), assignment);
        }
    }
    return validMapping;
}
Also used : Versioned(org.onosproject.store.service.Versioned) HashMap(java.util.HashMap) IpAssignment(org.onosproject.dhcp.IpAssignment) HostId(org.onosproject.net.HostId) ConsistentMap(org.onosproject.store.service.ConsistentMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with Versioned

use of org.onosproject.store.service.Versioned in project fabric-tna by stratum.

the class MockConsistentMap method computeIfPresent.

@Override
public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
    AtomicBoolean updated = new AtomicBoolean(false);
    AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
    Versioned<V> result = map.compute(key, (k, v) -> {
        if (v != null) {
            updated.set(true);
            previousValue.set(serializer.decode(serializer.encode(v)));
            return version(remappingFunction.apply(k, v.value()));
        }
        return v;
    });
    if (updated.get()) {
        notifyListeners(mapName, key, result, previousValue.get());
    }
    return result;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Versioned(org.onosproject.store.service.Versioned) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 14 with Versioned

use of org.onosproject.store.service.Versioned in project fabric-tna by stratum.

the class MockConsistentMap method computeIf.

@Override
public Versioned<V> computeIf(K key, Predicate<? super V> condition, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
    AtomicBoolean updated = new AtomicBoolean(false);
    AtomicReference<Versioned<V>> previousValue = new AtomicReference<>();
    Versioned<V> result = map.compute(key, (k, v) -> {
        if (condition.test(Versioned.valueOrNull(v))) {
            previousValue.set(serializer.decode(serializer.encode(v)));
            updated.set(true);
            return version(remappingFunction.apply(k, Versioned.valueOrNull(v)));
        }
        return v;
    });
    if (updated.get()) {
        notifyListeners(mapName, key, result, previousValue.get());
    }
    return result;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Versioned(org.onosproject.store.service.Versioned) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

Versioned (org.onosproject.store.service.Versioned)14 Map (java.util.Map)7 ConsistentMap (org.onosproject.store.service.ConsistentMap)5 DocumentPath (org.onosproject.store.service.DocumentPath)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Collectors (java.util.stream.Collectors)3 FailedException (org.onosproject.config.FailedException)3 DataNode (org.onosproject.yang.model.DataNode)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2 TimeUnit (java.util.concurrent.TimeUnit)2 MapEvent (org.onosproject.store.service.MapEvent)2 MapEventListener (org.onosproject.store.service.MapEventListener)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1