Search in sources :

Example 1 with DOMRpcImplementation

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation in project controller by opendaylight.

the class AbstractDOMRpcRoutingTableEntry method add.

/**
 * Adds an entry to the DOM RPC routing table.
 *
 * @param implementation RPC implementation
 * @param newRpcs List of new RPCs, must be mutable
 */
final AbstractDOMRpcRoutingTableEntry add(final DOMRpcImplementation implementation, final List<YangInstanceIdentifier> newRpcs) {
    final Builder<YangInstanceIdentifier, List<DOMRpcImplementation>> vb = ImmutableMap.builder();
    for (final Entry<YangInstanceIdentifier, List<DOMRpcImplementation>> ve : implementations.entrySet()) {
        if (newRpcs.remove(ve.getKey())) {
            final List<DOMRpcImplementation> i = new ArrayList<>(ve.getValue().size() + 1);
            i.addAll(ve.getValue());
            i.add(implementation);
            // New implementation is at the end, this will move it to be the last among implementations
            // with equal cost -- relying on sort() being stable.
            i.sort(Comparator.comparingLong(DOMRpcImplementation::invocationCost));
            vb.put(ve.getKey(), i);
        } else {
            vb.put(ve);
        }
    }
    for (final YangInstanceIdentifier ii : newRpcs) {
        final List<DOMRpcImplementation> impl = new ArrayList<>(1);
        impl.add(implementation);
        vb.put(ii, impl);
    }
    return newInstance(vb.build());
}
Also used : DOMRpcImplementation(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 2 with DOMRpcImplementation

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation in project controller by opendaylight.

the class RoutedDOMRpcRoutingTableEntry method invokeRpc.

@Override
protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input) {
    final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId);
    // Routing key is present, attempt to deliver as a routed RPC
    if (maybeKey.isPresent()) {
        final NormalizedNode<?, ?> key = maybeKey.get();
        final Object value = key.getValue();
        if (value instanceof YangInstanceIdentifier) {
            final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;
            // Find a DOMRpcImplementation for a specific iid
            final List<DOMRpcImplementation> specificImpls = getImplementations(iid);
            if (specificImpls != null) {
                return specificImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
            }
            LOG.debug("No implementation for context {} found will now look for wildcard id", iid);
            // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
            // implementation this way
            final List<DOMRpcImplementation> mayBeRemoteImpls = getImplementations(YangInstanceIdentifier.EMPTY);
            if (mayBeRemoteImpls != null) {
                return mayBeRemoteImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
            }
        } else {
            LOG.warn("Ignoring wrong context value {}", value);
        }
    }
    final List<DOMRpcImplementation> impls = getImplementations(null);
    if (impls != null) {
        return impls.get(0).invokeRpc(globalRpcId, input);
    } else {
        return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", getSchemaPath()));
    }
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DOMRpcImplementation(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation) DOMRpcImplementationNotAvailableException(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 3 with DOMRpcImplementation

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation in project controller by opendaylight.

the class DOMRpcRoutingTable method add.

DOMRpcRoutingTable add(final DOMRpcImplementation implementation, final Set<DOMRpcIdentifier> rpcsToAdd) {
    if (rpcsToAdd.isEmpty()) {
        return this;
    }
    // First decompose the identifiers to a multimap
    final ListMultimap<SchemaPath, YangInstanceIdentifier> toAdd = decomposeIdentifiers(rpcsToAdd);
    // Now iterate over existing entries, modifying them as appropriate...
    final Builder<SchemaPath, AbstractDOMRpcRoutingTableEntry> mb = ImmutableMap.builder();
    for (Entry<SchemaPath, AbstractDOMRpcRoutingTableEntry> re : this.rpcs.entrySet()) {
        List<YangInstanceIdentifier> newRpcs = new ArrayList<>(toAdd.removeAll(re.getKey()));
        if (!newRpcs.isEmpty()) {
            final AbstractDOMRpcRoutingTableEntry ne = re.getValue().add(implementation, newRpcs);
            mb.put(re.getKey(), ne);
        } else {
            mb.put(re);
        }
    }
    // Finally add whatever is left in the decomposed multimap
    for (Entry<SchemaPath, Collection<YangInstanceIdentifier>> e : toAdd.asMap().entrySet()) {
        final Builder<YangInstanceIdentifier, List<DOMRpcImplementation>> vb = ImmutableMap.builder();
        final List<DOMRpcImplementation> v = Collections.singletonList(implementation);
        for (YangInstanceIdentifier i : e.getValue()) {
            vb.put(i, v);
        }
        mb.put(e.getKey(), createRpcEntry(schemaContext, e.getKey(), vb.build()));
    }
    return new DOMRpcRoutingTable(mb.build(), schemaContext);
}
Also used : ArrayList(java.util.ArrayList) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) DOMRpcImplementation(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DOMRpcImplementation (org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collection (java.util.Collection)1 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)1 DOMRpcImplementationNotAvailableException (org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException)1 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)1