</feature>
<feature name='odl-netconf-tcp' version='${netconf.version}' description="OpenDaylight :: Netconf Connector :: TCP">
<feature version='${netconf.version}'>odl-netconf-impl</feature>
+ <feature version='${config.version}'>odl-config-netty</feature>
<bundle>mvn:org.opendaylight.controller/netconf-tcp/${netconf.version}</bundle>
</feature>
<properties>
- <akka.version>2.3.9</akka.version>
+ <akka.version>2.3.10</akka.version>
<appauth.version>0.5.0-SNAPSHOT</appauth.version>
<archetype-app-northbound>0.1.0-SNAPSHOT</archetype-app-northbound>
<arphandler.version>0.6.0-SNAPSHOT</arphandler.version>
private Set<YangInstanceIdentifier> toYangInstanceIdentifiers(final Set<InstanceIdentifier<?>> identifiers) {
final Set<YangInstanceIdentifier> ret = new HashSet<>();
for(final InstanceIdentifier<?> binding: identifiers) {
- ret.add(codec.toNormalized(binding));
+ ret.add(codec.toYangInstanceIdentifierCached(binding));
}
return ret;
}
*/
package org.opendaylight.controller.md.sal.binding.impl;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ClassToInstanceMap;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.lang.reflect.Method;
import java.util.Set;
import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory;
-import org.opendaylight.controller.md.sal.binding.impl.RpcServiceAdapter.InvocationDelegate;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.md.sal.dom.api.DOMService;
import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
-import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-public class BindingDOMRpcServiceAdapter implements RpcConsumerRegistry, InvocationDelegate {
+public class BindingDOMRpcServiceAdapter implements RpcConsumerRegistry {
protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = new Factory<RpcConsumerRegistry>() {
return proxy;
}
- @Override
- public ListenableFuture<RpcResult<?>> invoke(final SchemaPath rpc, final DataObject input) {
- final CheckedFuture<DOMRpcResult, DOMRpcException> domFuture = domService.invokeRpc(rpc, serialize(rpc,input));
- return transformFuture(rpc,domFuture,codec.getCodecRegistry());
- }
-
private RpcServiceAdapter createProxy(final Class<? extends RpcService> key) {
Preconditions.checkArgument(BindingReflections.isBindingClass(key));
Preconditions.checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
- final ImmutableMap<Method, SchemaPath> rpcNames = codec.getRpcMethodToSchemaPath(key);
- return new RpcServiceAdapter(key, rpcNames, this);
- }
-
- private NormalizedNode<?, ?> serialize(final SchemaPath rpc,final DataObject input) {
- if(input == null) {
- return null;
- }
- final QName rpcInputIdentifier = QName.create(rpc.getLastComponent(),"input");
- return new LazySerializedContainerNode(rpcInputIdentifier, input, codec.getCodecRegistry());
- }
-
- private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
- return Futures.transform(domFuture, new Function<DOMRpcResult, RpcResult<?>>() {
- @Override
- public RpcResult<?> apply(final DOMRpcResult input) {
- if(input instanceof LazySerializedDOMRpcResult) {
- return ((LazySerializedDOMRpcResult) input).bidningRpcResult();
- }
- final NormalizedNode<?, ?> domData = input.getResult();
- final DataObject bindingResult;
- if(domData != null) {
- final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(),"output"));
- bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
- } else {
- bindingResult = null;
- }
- return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
- }
- });
+ return new RpcServiceAdapter(key, codec, domService);
}
private static final class Builder extends BindingDOMAdapterBuilder<RpcConsumerRegistry> {
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableBiMap;
import java.lang.reflect.Method;
import java.util.AbstractMap.SimpleEntry;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory, BindingNormalizedNodeSerializer, SchemaContextListener, AutoCloseable {
+public final class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory, BindingNormalizedNodeSerializer, SchemaContextListener, AutoCloseable {
private final BindingNormalizedNodeCodecRegistry codecRegistry;
private DataNormalizer legacyToNormalized;
private final GeneratedClassLoadingStrategy classLoadingStrategy;
private BindingRuntimeContext runtimeContext;
+ private final LoadingCache<InstanceIdentifier<?>, YangInstanceIdentifier> iiCache = CacheBuilder.newBuilder()
+ .softValues().build(new CacheLoader<InstanceIdentifier<?>, YangInstanceIdentifier>() {
+
+ @Override
+ public YangInstanceIdentifier load(final InstanceIdentifier<?> key) throws Exception {
+ return toYangInstanceIdentifier(key);
+ }
+
+ });
public BindingToNormalizedNodeCodec(final GeneratedClassLoadingStrategy classLoadingStrategy,
final BindingNormalizedNodeCodecRegistry codecRegistry) {
- this.classLoadingStrategy = classLoadingStrategy;
- this.codecRegistry = codecRegistry;
+ this.classLoadingStrategy = Preconditions.checkNotNull(classLoadingStrategy,"classLoadingStrategy");
+ this.codecRegistry = Preconditions.checkNotNull(codecRegistry,"codecRegistry");
}
+ /**
+ * Translates supplied Binding Instance Identifier into NormalizedNode
+ * instance identifier.
+ *
+ * @param binding
+ * Binding Instance Identifier
+ * @return DOM Instance Identifier
+ * @throws IllegalArgumentException
+ * If supplied Instance Identifier is not valid.
+ */
public YangInstanceIdentifier toNormalized(final InstanceIdentifier<? extends DataObject> binding) {
return codecRegistry.toYangInstanceIdentifier(binding);
}
return codecRegistry.toYangInstanceIdentifier(binding);
}
+
+ YangInstanceIdentifier toYangInstanceIdentifierCached(final InstanceIdentifier<?> binding) {
+ return iiCache .getUnchecked(binding);
+ }
+
@Override
public <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
final InstanceIdentifier<T> path, final T data) {
return codecRegistry.toNormalizedNode(path, data);
}
+ /**
+ * Converts Binding Map.Entry to DOM Map.Entry
+ *
+ * Same as {@link #toNormalizedNode(InstanceIdentifier, DataObject)}.
+ *
+ * @param binding Map Entry with InstanceIdentifier as key and DataObject as value.
+ * @return DOM Map Entry with {@link YangInstanceIdentifier} as key and {@link NormalizedNode}
+ * as value.
+ */
@SuppressWarnings({"unchecked", "rawtypes"})
public Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
final Entry<InstanceIdentifier<? extends DataObject>, DataObject> binding) {
return ret.build();
}
+ protected ImmutableBiMap<Method, RpcDefinition> getRpcMethodToSchema(final Class<? extends RpcService> key) {
+ final QNameModule moduleName = BindingReflections.getQNameModule(key);
+ final Module module = runtimeContext.getSchemaContext().findModuleByNamespaceAndRevision(moduleName.getNamespace(), moduleName.getRevision());
+ final ImmutableBiMap.Builder<Method, RpcDefinition> ret = ImmutableBiMap.builder();
+ try {
+ for (final RpcDefinition rpcDef : module.getRpcs()) {
+ final Method method = findRpcMethod(key, rpcDef);
+ ret.put(method, rpcDef);
+ }
+ } catch (final NoSuchMethodException e) {
+ throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
+ }
+ return ret.build();
+ }
+
private Method findRpcMethod(final Class<? extends RpcService> key, final RpcDefinition rpcDef) throws NoSuchMethodException {
final String methodName = BindingMapping.getMethodName(rpcDef.getQName());
if(rpcDef.getInput() != null) {
return codecRegistry.create(context, bindingClasses);
}
- @Nonnull protected Map.Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>> getSubtreeCodec(
+ @Nonnull
+ protected Map.Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>> getSubtreeCodec(
final YangInstanceIdentifier domIdentifier) {
final BindingCodecTree currentCodecTree = codecRegistry.getCodecContext();
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.impl;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import java.lang.reflect.Method;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+abstract class ContextReferenceExtractor {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ContextReferenceExtractor.class);
+ private static final ContextReferenceExtractor NULL_EXTRACTOR = new ContextReferenceExtractor() {
+
+ @Override
+ InstanceIdentifier<?> extract(final DataObject obj) {
+ return null;
+ }
+ };
+
+
+ private static final LoadingCache<Class<?>, ContextReferenceExtractor> EXTRACTORS = CacheBuilder.newBuilder()
+ .weakKeys().build(new CacheLoader<Class<?>, ContextReferenceExtractor>() {
+
+ @Override
+ public ContextReferenceExtractor load(final Class<?> key) throws Exception {
+ return create(key);
+ }
+ });
+
+
+ private static final String GET_VALUE_NAME = "getValue";
+
+ static ContextReferenceExtractor from(final Class<?> obj) {
+ return EXTRACTORS.getUnchecked(obj);
+ }
+
+ /**
+ * Extract context-reference (Instance Identifier) from
+ * Binding DataObject.
+ *
+ * @param obj DataObject from which context reference
+ * should be extracted.
+ *
+ * @return Instance Identifier representing context reference
+ * or null, if data object does not contain context reference.
+ */
+ abstract @Nullable InstanceIdentifier<?> extract(DataObject obj);
+
+ private static @Nonnull ContextReferenceExtractor create(final Class<?> key) {
+ final Method contextGetter = getContextGetter(key);
+ if (contextGetter == null) {
+ return NULL_EXTRACTOR;
+ }
+ final Class<?> returnType = contextGetter.getReturnType();
+ try {
+ if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
+ return DirectGetterRouteContextExtractor.create(contextGetter);
+ }
+ final Method getValueMethod = findGetValueMethod(returnType,InstanceIdentifier.class);
+ if (getValueMethod != null) {
+ return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
+ } else {
+ LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",returnType);
+ }
+ } catch (final IllegalAccessException e) {
+ LOG.warn("Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR", e);
+ }
+ return NULL_EXTRACTOR;
+ }
+
+ private static @Nullable Method findGetValueMethod(final Class<?> type, final Class<?> returnType) {
+ try {
+ final Method method = type.getMethod(GET_VALUE_NAME);
+ if(returnType.equals(method.getReturnType())) {
+ return method;
+ }
+ } catch (final NoSuchMethodException e) {
+ LOG.warn("Value class {} does not comform to Binding Specification v1.", type, e);
+ }
+ return null;
+ }
+
+ private static Method getContextGetter(final Class<?> key) {
+ for (final Method method : key.getMethods()) {
+ if (method.getAnnotation(RoutingContext.class) != null) {
+ return method;
+ }
+ }
+ return null;
+ }
+
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.impl;
+
+import com.google.common.base.Throwables;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Method;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+final class DirectGetterRouteContextExtractor extends ContextReferenceExtractor {
+
+ private final static Lookup PUBLIC_LOOKUP = MethodHandles.publicLookup();
+ private final MethodHandle handle;
+
+ private DirectGetterRouteContextExtractor(final MethodHandle rawHandle) {
+ handle = rawHandle.asType(MethodType.methodType(InstanceIdentifier.class, DataObject.class));
+ }
+
+ static final ContextReferenceExtractor create(final Method getterMethod) throws IllegalAccessException {
+ final MethodHandle getterHandle = PUBLIC_LOOKUP.unreflect(getterMethod);
+ return new DirectGetterRouteContextExtractor(getterHandle);
+ }
+
+ @Override
+ InstanceIdentifier<?> extract(final DataObject obj) {
+ try {
+ return (InstanceIdentifier<?>) handle.invokeExact(obj);
+ } catch (final Throwable e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.impl;
+
+import com.google.common.base.Throwables;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Method;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+final class GetValueRouteContextExtractor extends ContextReferenceExtractor {
+
+ private final static Lookup PUBLIC_LOOKUP = MethodHandles.publicLookup();
+ private final MethodHandle contextHandle;
+ private final MethodHandle valueHandle;
+
+ private GetValueRouteContextExtractor(final MethodHandle rawContextHandle, final MethodHandle rawValueHandle) {
+ contextHandle = rawContextHandle.asType(MethodType.methodType(Object.class, DataObject.class));
+ valueHandle = rawValueHandle.asType(MethodType.methodType(InstanceIdentifier.class, Object.class));
+ }
+
+ public static ContextReferenceExtractor create(final Method contextGetter, final Method getValueMethod)
+ throws IllegalAccessException {
+ final MethodHandle rawContextHandle = PUBLIC_LOOKUP.unreflect(contextGetter);
+ final MethodHandle rawValueHandle = PUBLIC_LOOKUP.unreflect(getValueMethod);
+ return new GetValueRouteContextExtractor(rawContextHandle, rawValueHandle);
+ }
+
+ @Override
+ InstanceIdentifier<?> extract(final DataObject obj) {
+ try {
+ final Object ctx = contextHandle.invokeExact(obj);
+ if (ctx != null) {
+ return (InstanceIdentifier<?>) valueHandle.invokeExact(ctx);
+ }
+ return null;
+ } catch (final Throwable e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+
+}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.md.sal.binding.impl;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
/**
*
private BindingNormalizedNodeCodecRegistry registry;
private ContainerNode domData;
- LazySerializedContainerNode(QName identifier, DataObject binding,
- BindingNormalizedNodeCodecRegistry registry) {
+ private LazySerializedContainerNode(final QName identifier, final DataObject binding,
+ final BindingNormalizedNodeCodecRegistry registry) {
this.identifier = new NodeIdentifier(identifier);
this.bindingData = binding;
this.registry = registry;
this.domData = null;
}
+ static NormalizedNode<?, ?> create(final SchemaPath rpcName, final DataObject data,
+ final BindingNormalizedNodeCodecRegistry codec) {
+ return new LazySerializedContainerNode(rpcName.getLastComponent(), data, codec);
+ }
+
+ static NormalizedNode<?, ?> withContextRef(final SchemaPath rpcName, final DataObject data,
+ final LeafNode<?> contextRef, final BindingNormalizedNodeCodecRegistry codec) {
+ return new WithContextRef(rpcName.getLastComponent(), data, contextRef, codec);
+ }
+
@Override
public Map<QName, String> getAttributes() {
return delegate().getAttributes();
}
private ContainerNode delegate() {
- if(domData == null) {
+ if (domData == null) {
domData = registry.toNormalizedNodeRpcData(bindingData);
registry = null;
}
}
@Override
- public QName getNodeType() {
- return delegate().getNodeType();
+ public final QName getNodeType() {
+ return identifier.getNodeType();
}
@Override
- public Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
+ public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
return delegate().getValue();
}
@Override
- public NodeIdentifier getIdentifier() {
+ public final NodeIdentifier getIdentifier() {
return identifier;
}
@Override
- public Optional<DataContainerChild<? extends PathArgument, ?>> getChild(PathArgument child) {
+ public Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
return delegate().getChild(child);
}
@Override
- public Object getAttributeValue(QName name) {
+ public final Object getAttributeValue(final QName name) {
return delegate().getAttributeValue(name);
}
- public DataObject bindingData() {
+ final DataObject bindingData() {
return bindingData;
}
+ /**
+ * Lazy Serialized Node with pre-cached serialized leaf holding routing information.
+ *
+ */
+ private static final class WithContextRef extends LazySerializedContainerNode {
+
+ private final LeafNode<?> contextRef;
+
+ protected WithContextRef(final QName identifier, final DataObject binding, final LeafNode<?> contextRef,
+ final BindingNormalizedNodeCodecRegistry registry) {
+ super(identifier, binding, registry);
+ this.contextRef = contextRef;
+ }
+
+ @Override
+ public Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
+ /*
+ * Use precached value of routing field and do not run full serialization if we are
+ * accessing it.
+ */
+ if (contextRef.getIdentifier().equals(child)) {
+ return Optional.<DataContainerChild<? extends PathArgument, ?>>of(contextRef);
+ }
+ return super.getChild(child);
+ }
+ }
+
}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.md.sal.binding.impl;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.Map.Entry;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy;
+import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
class RpcServiceAdapter implements InvocationHandler {
- interface InvocationDelegate {
-
- ListenableFuture<RpcResult<?>> invoke(SchemaPath rpc, DataObject dataObject);
+ private final ImmutableMap<Method, RpcInvocationStrategy> rpcNames;
+ private final Class<? extends RpcService> type;
+ private final BindingToNormalizedNodeCodec codec;
+ private final DOMRpcService delegate;
+ private final RpcService proxy;
+ RpcServiceAdapter(final Class<? extends RpcService> type, final BindingToNormalizedNodeCodec codec,
+ final DOMRpcService domService) {
+ this.type = Preconditions.checkNotNull(type);
+ this.codec = Preconditions.checkNotNull(codec);
+ this.delegate = Preconditions.checkNotNull(domService);
+ final ImmutableMap.Builder<Method, RpcInvocationStrategy> rpcBuilder = ImmutableMap.builder();
+ for (final Entry<Method, RpcDefinition> rpc : codec.getRpcMethodToSchema(type).entrySet()) {
+ rpcBuilder.put(rpc.getKey(), createStrategy(rpc.getKey(), rpc.getValue()));
+ }
+ rpcNames = rpcBuilder.build();
+ proxy = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, this);
}
- private final RpcService proxy;
- private final ImmutableMap<Method,SchemaPath> rpcNames;
- private final Class<? extends RpcService> type;
- private final InvocationDelegate delegate;
+ private final ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
+ final CheckedFuture<DOMRpcResult, DOMRpcException> result = delegate.invokeRpc(schemaPath, input);
+ return transformFuture(schemaPath, result, codec.getCodecFactory());
+ }
- RpcServiceAdapter(Class<? extends RpcService> type, ImmutableMap<Method, SchemaPath> rpcNames, InvocationDelegate delegate) {
- this.rpcNames = rpcNames;
- this.type = type;
- this.delegate = delegate;
- this.proxy = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, this);
+ private RpcInvocationStrategy createStrategy(final Method method, final RpcDefinition schema) {
+ final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(schema);
+ if (strategy.isContextBasedRouted()) {
+ return new RoutedStrategy(schema.getPath(), method, strategy.getLeaf());
+ }
+ return new NonRoutedStrategy(schema.getPath());
}
RpcService getProxy() {
}
@Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- SchemaPath rpc = rpcNames.get(method);
- if(rpc != null) {
- if(method.getParameterTypes().length == 0) {
- return delegate.invoke(rpc, null);
+ final RpcInvocationStrategy rpc = rpcNames.get(method);
+ if (rpc != null) {
+ if (method.getParameterTypes().length == 0) {
+ return rpc.invokeEmpty();
}
- if(args.length != 1) {
+ if (args.length != 1) {
throw new IllegalArgumentException("Input must be provided.");
}
- return delegate.invoke(rpc,(DataObject) args[0]);
+ return rpc.invoke((DataObject) args[0]);
}
- if(isObjectMethod(method)) {
+ if (isObjectMethod(method)) {
return callObjectMethod(proxy, method, args);
}
throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported.");
}
- private static boolean isObjectMethod(Method m) {
+ private static boolean isObjectMethod(final Method m) {
switch (m.getName()) {
- case "toString":
- return (m.getReturnType() == String.class && m.getParameterTypes().length == 0);
- case "hashCode":
- return (m.getReturnType() == int.class && m.getParameterTypes().length == 0);
- case "equals":
- return (m.getReturnType() == boolean.class && m.getParameterTypes().length == 1 && m.getParameterTypes()[0] == Object.class);
+ case "toString":
+ return (m.getReturnType() == String.class && m.getParameterTypes().length == 0);
+ case "hashCode":
+ return (m.getReturnType() == int.class && m.getParameterTypes().length == 0);
+ case "equals":
+ return (m.getReturnType() == boolean.class && m.getParameterTypes().length == 1 && m
+ .getParameterTypes()[0] == Object.class);
}
return false;
}
- private Object callObjectMethod(Object self, Method m, Object[] args) {
+ private Object callObjectMethod(final Object self, final Method m, final Object[] args) {
switch (m.getName()) {
- case "toString":
- return type.getName() + "$Adapter{delegate=" + delegate.toString()+"}";
- case "hashCode":
- return System.identityHashCode(self);
- case "equals":
- return (self == args[0]);
+ case "toString":
+ return type.getName() + "$Adapter{delegate=" + delegate.toString() + "}";
+ case "hashCode":
+ return System.identityHashCode(self);
+ case "equals":
+ return (self == args[0]);
}
return null;
}
+
+ private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
+ final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
+ return Futures.transform(domFuture, new Function<DOMRpcResult, RpcResult<?>>() {
+ @Override
+ public RpcResult<?> apply(final DOMRpcResult input) {
+ if (input instanceof LazySerializedDOMRpcResult) {
+ return ((LazySerializedDOMRpcResult) input).bidningRpcResult();
+ }
+ final NormalizedNode<?, ?> domData = input.getResult();
+ final DataObject bindingResult;
+ if (domData != null) {
+ final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
+ bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
+ } else {
+ bindingResult = null;
+ }
+ return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
+ }
+ });
+ }
+
+ private abstract class RpcInvocationStrategy {
+
+ private final SchemaPath rpcName;
+
+ protected RpcInvocationStrategy(final SchemaPath path) {
+ rpcName = path;
+ }
+
+ final ListenableFuture<RpcResult<?>> invoke(final DataObject input) {
+ return invoke0(rpcName, serialize(input));
+ }
+
+ abstract NormalizedNode<?, ?> serialize(DataObject input);
+
+ final ListenableFuture<RpcResult<?>> invokeEmpty() {
+ return invoke0(rpcName, null);
+ }
+
+ final SchemaPath getRpcName() {
+ return rpcName;
+ }
+
+ }
+
+ private final class NonRoutedStrategy extends RpcInvocationStrategy {
+
+ protected NonRoutedStrategy(final SchemaPath path) {
+ super(path);
+ }
+
+ @Override
+ NormalizedNode<?, ?> serialize(final DataObject input) {
+ return LazySerializedContainerNode.create(getRpcName(), input, codec.getCodecRegistry());
+ }
+
+ }
+
+ private final class RoutedStrategy extends RpcInvocationStrategy {
+
+ private final ContextReferenceExtractor refExtractor;
+ private final NodeIdentifier contextName;
+
+ protected RoutedStrategy(final SchemaPath path, final Method rpcMethod, final QName leafName) {
+ super(path);
+ final Class<? extends DataContainer> inputType = BindingReflections.resolveRpcInputClass(rpcMethod).get();
+ refExtractor = ContextReferenceExtractor.from(inputType);
+ this.contextName = new NodeIdentifier(leafName);
+ }
+
+ @Override
+ NormalizedNode<?, ?> serialize(final DataObject input) {
+ final InstanceIdentifier<?> bindingII = refExtractor.extract(input);
+ if (bindingII != null) {
+ final YangInstanceIdentifier yangII = codec.toYangInstanceIdentifierCached(bindingII);
+ final LeafNode<?> contextRef = ImmutableNodes.leafNode(contextName, yangII);
+ return LazySerializedContainerNode.withContextRef(getRpcName(), input, contextRef,
+ codec.getCodecRegistry());
+ }
+ return LazySerializedContainerNode.create(getRpcName(), input, codec.getCodecRegistry());
+ }
+
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.impl;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.EncapsulatedRouteInGrouping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public final class ContextExtractorTest {
+
+ public interface Transitive extends EncapsulatedRouteInGrouping {
+
+ }
+
+ private static final InstanceIdentifier<?> TEST_ROUTE = InstanceIdentifier.create(Top.class);
+ private static final Transitive TEST_GROUPING = new Transitive() {
+
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return Transitive.class;
+ }
+
+ @Override
+ public EncapsulatedRoute getRoute() {
+ return new EncapsulatedRoute(TEST_ROUTE);
+ }
+ };
+
+ @Test
+ public void testNonRoutedExtraction() {
+ final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RockTheHouseInput.class);
+ final RockTheHouseInput input = new RockTheHouseInputBuilder().build();
+ final InstanceIdentifier<?> extractedValue = extractor.extract(input);
+ assertNull(extractedValue);
+ }
+
+ @Test
+ public void testRoutedSimpleExtraction() {
+ final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(RoutedSimpleRouteInput.class);
+ final RoutedSimpleRouteInput input = new RoutedSimpleRouteInputBuilder().setRoute(TEST_ROUTE).build();
+ final InstanceIdentifier<?> extractedValue = extractor.extract(input);
+ assertSame(TEST_ROUTE,extractedValue);
+ }
+
+ @Test
+ public void testRoutedEncapsulatedExtraction() {
+ final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(EncapsulatedRouteInGrouping.class);
+ final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
+ assertSame(TEST_ROUTE,extractedValue);
+
+ }
+
+ @Test
+ public void testRoutedEncapsulatedTransitiveExtraction() {
+ final ContextReferenceExtractor extractor = ContextReferenceExtractor.from(Transitive.class);
+ final InstanceIdentifier<?> extractedValue = extractor.extract(TEST_GROUPING);
+ assertSame(TEST_ROUTE,extractedValue);
+ }
+ }
import org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState;
import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
import org.opendaylight.controller.md.sal.common.util.jmx.QueuedNotificationManagerMXBeanImpl;
-import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStats;
import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
-import org.opendaylight.yangtools.util.concurrent.ListenerNotificationQueueStats;
import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return getOnDemandRaftState().getInMemoryJournalLogSize();
}
- @Override
- public ThreadExecutorStats getDataStoreExecutorStats() {
- // FIXME: this particular thing does not work, as it really is DS-specific
- return null;
- }
-
- @Override
- public ThreadExecutorStats getNotificationMgrExecutorStats() {
- return notificationExecutorStatsBean.toThreadExecutorStats();
- }
-
- @Override
- public List<ListenerNotificationQueueStats> getCurrentNotificationMgrListenerQueueStats() {
- return notificationManagerStatsBean.getCurrentListenerQueueStats();
- }
-
- @Override
- public int getMaxNotificationMgrListenerQueueSize() {
- return notificationManagerStatsBean.getMaxListenerQueueSize();
- }
-
/**
* resets the counters related to transactions
*/
import java.util.List;
import org.opendaylight.controller.cluster.raft.client.messages.FollowerInfo;
-import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStats;
-import org.opendaylight.yangtools.util.concurrent.ListenerNotificationQueueStats;
/**
* @author: syedbahm
boolean isSnapshotCaptureInitiated();
- ThreadExecutorStats getDataStoreExecutorStats();
-
- ThreadExecutorStats getNotificationMgrExecutorStats();
-
- List<ListenerNotificationQueueStats> getCurrentNotificationMgrListenerQueueStats();
-
- int getMaxNotificationMgrListenerQueueSize();
-
void resetTransactionCounters();
long getInMemoryJournalDataSize();
LOG.debug("Create rpc registry and broker actors");
rpcRegistry =
- getContext().actorOf(Props.create(RpcRegistry.class).
+ getContext().actorOf(RpcRegistry.props().
withMailbox(config.getMailBoxName()), config.getRpcRegistryName());
rpcBroker =
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+
import org.opendaylight.controller.remote.rpc.registry.gossip.Copier;
import org.opendaylight.controller.sal.connector.api.RpcRouter;
}
}
+ public Set<RpcRouter.RouteIdentifier<?, ?, ?>> getRoutes() {
+ return table.keySet();
+ }
+
public void addRoute(RpcRouter.RouteIdentifier<?,?,?> routeId){
table.put(routeId, System.currentTimeMillis());
}
package org.opendaylight.controller.remote.rpc.registry;
import akka.actor.ActorRef;
+import akka.actor.Props;
+import akka.japi.Creator;
import akka.japi.Option;
import akka.japi.Pair;
import com.google.common.base.Preconditions;
import org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.SetLocalRouter;
import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStore;
+import org.opendaylight.controller.remote.rpc.registry.mbeans.RemoteRpcRegistryMXBean;
+import org.opendaylight.controller.remote.rpc.registry.mbeans.RemoteRpcRegistryMXBeanImpl;
import org.opendaylight.controller.sal.connector.api.RpcRouter;
import org.opendaylight.controller.sal.connector.api.RpcRouter.RouteIdentifier;
getLocalBucket().setData(new RoutingTable());
}
+ public static Props props() {
+ return Props.create(new RpcRegistryCreator());
+ }
+
@Override
protected void handleReceive(Object message) throws Exception {
//TODO: if sender is remote, reject message
}
}
}
+
+ private static class RpcRegistryCreator implements Creator<RpcRegistry> {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public RpcRegistry create() throws Exception {
+ RpcRegistry registry = new RpcRegistry();
+ RemoteRpcRegistryMXBean mxBean = new RemoteRpcRegistryMXBeanImpl(registry);
+ return registry;
+ }
+ }
}
import akka.actor.Address;
import akka.actor.Props;
import akka.cluster.ClusterActorRefProvider;
-import com.google.common.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
}
}
- protected BucketImpl<T> getLocalBucket() {
+ public BucketImpl<T> getLocalBucket() {
return localBucket;
}
versions.put(selfAddress, localBucket.getVersion());
}
- protected Map<Address, Bucket<T>> getRemoteBuckets() {
+ public Map<Address, Bucket<T>> getRemoteBuckets() {
return remoteBuckets;
}
- @VisibleForTesting
- Map<Address, Long> getVersions() {
+ public Map<Address, Long> getVersions() {
return versions;
}
}
--- /dev/null
+package org.opendaylight.controller.remote.rpc.registry.mbeans;
+
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * JMX bean to check remote rpc registry
+ */
+
+public interface RemoteRpcRegistryMXBean {
+
+ Set<String> getGlobalRpc();
+
+ String getBucketVersions();
+
+ Set<String> getLocalRegisteredRoutedRpc();
+
+ Map<String,String> findRpcByName(String name);
+
+ Map<String,String> findRpcByRoute(String route);
+}
--- /dev/null
+package org.opendaylight.controller.remote.rpc.registry.mbeans;
+
+import akka.actor.Address;
+import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
+import org.opendaylight.controller.remote.rpc.registry.RoutingTable;
+import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
+import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
+import org.opendaylight.controller.sal.connector.api.RpcRouter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements RemoteRpcRegistryMXBean {
+
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ private final String NULL_CONSTANT = "null";
+
+ private final String LOCAL_CONSTANT = "local";
+
+ private final String ROUTE_CONSTANT = "route:";
+
+ private final String NAME_CONSTANT = " | name:";
+
+ private final RpcRegistry rpcRegistry;
+
+ public RemoteRpcRegistryMXBeanImpl(final RpcRegistry rpcRegistry) {
+ super("RemoteRpcRegistry", "RemoteRpcBroker", null);
+ this.rpcRegistry = rpcRegistry;
+ registerMBean();
+ }
+
+ @Override
+ public Set<String> getGlobalRpc() {
+ RoutingTable table = rpcRegistry.getLocalBucket().getData();
+ Set<String> globalRpc = new HashSet<>(table.getRoutes().size());
+ for(RpcRouter.RouteIdentifier<?, ?, ?> route : table.getRoutes()){
+ if(route.getRoute() == null) {
+ globalRpc.add(route.getType() != null ? route.getType().toString() : NULL_CONSTANT);
+ }
+ }
+ if(log.isDebugEnabled()) {
+ log.debug("Locally registered global RPCs {}", globalRpc);
+ }
+ return globalRpc;
+ }
+
+ @Override
+ public Set<String> getLocalRegisteredRoutedRpc() {
+ RoutingTable table = rpcRegistry.getLocalBucket().getData();
+ Set<String> routedRpc = new HashSet<>(table.getRoutes().size());
+ for(RpcRouter.RouteIdentifier<?, ?, ?> route : table.getRoutes()){
+ if(route.getRoute() != null) {
+ StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
+ builder.append(route.getRoute().toString()).append(NAME_CONSTANT).append(route.getType() != null ?
+ route.getType().toString() : NULL_CONSTANT);
+ routedRpc.add(builder.toString());
+ }
+ }
+ if(log.isDebugEnabled()) {
+ log.debug("Locally registered routed RPCs {}", routedRpc);
+ }
+ return routedRpc;
+ }
+
+ @Override
+ public Map<String, String> findRpcByName(final String name) {
+ RoutingTable localTable = rpcRegistry.getLocalBucket().getData();
+ // Get all RPCs from local bucket
+ Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT));
+
+ // Get all RPCs from remote bucket
+ Map<Address, Bucket<RoutingTable>> buckets = rpcRegistry.getRemoteBuckets();
+ for(Address address : buckets.keySet()) {
+ RoutingTable table = buckets.get(address).getData();
+ rpcMap.putAll(getRpcMemberMapByName(table, name, address.toString()));
+ }
+ if(log.isDebugEnabled()) {
+ log.debug("list of RPCs {} searched by name {}", rpcMap, name);
+ }
+ return rpcMap;
+ }
+
+ @Override
+ public Map<String, String> findRpcByRoute(String routeId) {
+ RoutingTable localTable = rpcRegistry.getLocalBucket().getData();
+ Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT));
+
+ Map<Address, Bucket<RoutingTable>> buckets = rpcRegistry.getRemoteBuckets();
+ for(Address address : buckets.keySet()) {
+ RoutingTable table = buckets.get(address).getData();
+ rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, address.toString()));
+
+ }
+ if(log.isDebugEnabled()) {
+ log.debug("list of RPCs {} searched by route {}", rpcMap, routeId);
+ }
+ return rpcMap;
+ }
+
+ /**
+ * Search if the routing table route String contains routeName
+ */
+
+ private Map<String,String> getRpcMemberMapByRoute(final RoutingTable table, final String routeName,
+ final String address) {
+ Set<RpcRouter.RouteIdentifier<?, ?, ?>> routes = table.getRoutes();
+ Map<String, String> rpcMap = new HashMap<>(routes.size());
+ for(RpcRouter.RouteIdentifier<?, ?, ?> route : table.getRoutes()){
+ if(route.getRoute() != null) {
+ String routeString = route.getRoute().toString();
+ if(routeString.contains(routeName)) {
+ StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
+ builder.append(routeString).append(NAME_CONSTANT).append(route.getType() != null ?
+ route.getType().toString() : NULL_CONSTANT);
+ rpcMap.put(builder.toString(), address);
+ }
+ }
+ }
+ return rpcMap;
+ }
+
+ /**
+ * Search if the routing table route type contains name
+ */
+ private Map<String, String> getRpcMemberMapByName(final RoutingTable table, final String name,
+ final String address) {
+ Set<RpcRouter.RouteIdentifier<?, ?, ?>> routes = table.getRoutes();
+ Map<String, String> rpcMap = new HashMap<>(routes.size());
+ for(RpcRouter.RouteIdentifier<?, ?, ?> route : routes){
+ if(route.getType() != null) {
+ String type = route.getType().toString();
+ if(type.contains(name)) {
+ StringBuilder builder = new StringBuilder(ROUTE_CONSTANT);
+ builder.append(route.getRoute() != null ? route.getRoute().toString(): NULL_CONSTANT)
+ .append(NAME_CONSTANT).append(type);
+ rpcMap.put(builder.toString(), address);
+ }
+ }
+ }
+ return rpcMap;
+ }
+
+
+
+ @Override
+ public String getBucketVersions() {
+ return rpcRegistry.getVersions().toString();
+ }
+
+}
\ No newline at end of file
result = partialResult;
}
return new NormalizedNodeContext(path,result);
+ } catch (final RestconfDocumentedException e) {
+ throw e;
} catch (final Exception e) {
LOG.debug("Error parsing json input", e);
final NormalizedNode<?, ?> result = parse(path,doc);
return new NormalizedNodeContext(path,result);
+ } catch (final RestconfDocumentedException e){
+ throw e;
} catch (final Exception e) {
LOG.debug("Error parsing xml input", e);
final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
final Module latestModule = globalSchema.findModuleByName(startModule, null);
+
+ if (latestModule == null) {
+ throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
+ }
+
final InstanceIdentifierContext<?> iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null,
toMountPointIdentifier);
}
public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
- final SoftReference<YangStoreSnapshot> yangStoreSnapshotSoftReference = ref.get();
- YangStoreContext ret = yangStoreSnapshotSoftReference != null ? yangStoreSnapshotSoftReference.get() : null;
- if(ret == null) {
- ret = getYangStoreSnapshot();
+ YangStoreContext context = ref.get().get();
+
+ if(context == null) {
+ context = getYangStoreSnapshot();
}
this.listeners.add(listener);
- listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(ret));
+ listener.onCapabilitiesAdded(NetconfOperationServiceFactoryImpl.setupCapabilities(context));
return new AutoCloseable() {
@Override
<password>admin</password>
</module>
+
+ <!--TCP endpoint for MD-SAL netconf server -->
+ <!--<module>-->
+ <!--<type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp">prefix:netconf-northbound-tcp</type>-->
+ <!--<name>netconf-mdsal-tcp-server</name>-->
+ <!--<dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp">-->
+ <!--<type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound">prefix:netconf-server-dispatcher</type>-->
+ <!--<name>netconf-mdsal-server-dispatcher</name>-->
+ <!--</dispatcher>-->
+ <!--</module>-->
+
</modules>
<services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<groupId>${project.groupId}</groupId>
<artifactId>netconf-util</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>threadpool-config-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>netty-config-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>config</id>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator</codeGeneratorClass>
+ <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+ <additionalConfiguration>
+ <namespaceToPackage1>urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang</namespaceToPackage1>
+ </additionalConfiguration>
+ </generator>
+ <generator>
+ <codeGeneratorClass>org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass>
+ <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-jmx-generator-plugin</artifactId>
+ <version>${config.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</build>
--- /dev/null
+package org.opendaylight.controller.config.yang.netconf.northbound.tcp;
+
+import io.netty.channel.ChannelFuture;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import org.opendaylight.controller.netconf.api.NetconfServerDispatcher;
+
+public class NetconfNorthboundTcpModule extends org.opendaylight.controller.config.yang.netconf.northbound.tcp.AbstractNetconfNorthboundTcpModule {
+ public NetconfNorthboundTcpModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public NetconfNorthboundTcpModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.netconf.northbound.tcp.NetconfNorthboundTcpModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void customValidation() {
+ // add custom validation form module attributes here.
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ final NetconfServerDispatcher dispatch = getDispatcherDependency();
+ final ChannelFuture tcpServer = dispatch.createServer(getInetAddress());
+ return new NetconfServerCloseable(tcpServer);
+ }
+
+ private InetSocketAddress getInetAddress() {
+ try {
+ final InetAddress inetAd = InetAddress.getByName(getBindingAddress().getIpv4Address() == null ? getBindingAddress().getIpv6Address().getValue() : getBindingAddress().getIpv4Address().getValue());
+ return new InetSocketAddress(inetAd, getPort().getValue());
+ } catch (final UnknownHostException e) {
+ throw new IllegalArgumentException("Unable to bind netconf endpoint to address " + getBindingAddress(), e);
+ }
+ }
+
+ private static final class NetconfServerCloseable implements AutoCloseable {
+ private final ChannelFuture localServer;
+
+ public NetconfServerCloseable(final ChannelFuture localServer) {
+ this.localServer = localServer;
+ }
+
+ @Override
+ public void close() throws Exception {
+ if(localServer.isDone()) {
+ localServer.channel().close();
+ } else {
+ localServer.cancel(true);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+* Generated file
+*
+* Generated from: yang module name: netconf-northbound-tcp yang module local name: netconf-northbound-tcp
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Thu Apr 23 16:34:55 CEST 2015
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.netconf.northbound.tcp;
+public class NetconfNorthboundTcpModuleFactory extends org.opendaylight.controller.config.yang.netconf.northbound.tcp.AbstractNetconfNorthboundTcpModuleFactory {
+
+}
--- /dev/null
+module netconf-northbound-tcp {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:tcp";
+ prefix "nni";
+
+ import netconf-northbound-mapper { prefix nnm; revision-date 2015-01-14; }
+ import netconf-northbound { prefix nn; revision-date 2015-01-14; }
+ import config { prefix config; revision-date 2013-04-05; }
+ import threadpool {prefix th;}
+ import netty {prefix netty;}
+ import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
+
+ organization "Cisco Systems, Inc.";
+
+ description
+ "This module contains the base YANG definitions for
+ a default implementation of netconf northbound tcp server";
+
+ revision "2015-04-23" {
+ description
+ "Initial revision.";
+ }
+
+ identity netconf-northbound-tcp {
+ base config:module-type;
+ config:java-name-prefix NetconfNorthboundTcp;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case netconf-northbound-tcp {
+ when "/config:modules/config:module/config:type = 'netconf-northbound-tcp'";
+
+ leaf port {
+ type inet:port-number;
+ default 2831;
+ }
+
+ leaf binding-address {
+ type inet:ip-address;
+ default "0.0.0.0";
+ }
+
+ container dispatcher {
+ uses config:service-ref {
+ refine type {
+ config:required-identity nn:netconf-server-dispatcher;
+ }
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file