package org.opendaylight.controller.config.manager.impl.dependencyresolver;
import static com.google.common.base.Preconditions.checkState;
-
+import com.google.common.base.Preconditions;
import com.google.common.reflect.AbstractInvocationHandler;
import com.google.common.reflect.Reflection;
import java.lang.reflect.InvocationTargetException;
private final DeadlockMonitor deadlockMonitor;
private final MBeanServer mBeanServer;
- public DependencyResolverManager(TransactionIdentifier transactionIdentifier,
- TransactionStatus transactionStatus,
- ServiceReferenceReadableRegistry readableRegistry, CodecRegistry codecRegistry,
- MBeanServer mBeanServer) {
+ public DependencyResolverManager(final TransactionIdentifier transactionIdentifier,
+ final TransactionStatus transactionStatus,
+ final ServiceReferenceReadableRegistry readableRegistry, final CodecRegistry codecRegistry,
+ final MBeanServer mBeanServer) {
this.transactionIdentifier = transactionIdentifier;
this.modulesHolder = new ModulesHolder(transactionIdentifier);
this.transactionStatus = transactionStatus;
}
@Override
- public DependencyResolver createDependencyResolver(ModuleIdentifier moduleIdentifier) {
+ public DependencyResolver createDependencyResolver(final ModuleIdentifier moduleIdentifier) {
return getOrCreate(moduleIdentifier);
}
- public synchronized DependencyResolverImpl getOrCreate(ModuleIdentifier name) {
+ public synchronized DependencyResolverImpl getOrCreate(final ModuleIdentifier name) {
DependencyResolverImpl dependencyResolver = moduleIdentifiersToDependencyResolverMap.get(name);
if (dependencyResolver == null) {
transactionStatus.checkNotCommitted();
}
public ModuleInternalTransactionalInfo destroyModule(
- ModuleIdentifier moduleIdentifier) {
+ final ModuleIdentifier moduleIdentifier) {
transactionStatus.checkNotCommitted();
ModuleInternalTransactionalInfo found = modulesHolder
.destroyModule(moduleIdentifier);
// protect write access
+ private static final class ModuleInvocationHandler extends AbstractInvocationHandler {
+ private final DeadlockMonitor deadlockMonitor;
+ private final ModuleIdentifier moduleIdentifier;
+ private final Module module;
+
+ // optimization: subsequent calls to getInstance MUST return the same value during transaction,
+ // so it is safe to cache the response
+ private Object cachedInstance;
+
+ ModuleInvocationHandler(final DeadlockMonitor deadlockMonitor, final ModuleIdentifier moduleIdentifier, final Module module) {
+ this.deadlockMonitor = Preconditions.checkNotNull(deadlockMonitor);
+ this.moduleIdentifier = Preconditions.checkNotNull(moduleIdentifier);
+ this.module = Preconditions.checkNotNull(module);
+ }
+
+ @Override
+ protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
+ boolean isGetInstance = "getInstance".equals(method.getName());
+ if (isGetInstance) {
+ if (cachedInstance != null) {
+ return cachedInstance;
+ }
+
+ checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive");
+ deadlockMonitor.setCurrentlyInstantiatedModule(moduleIdentifier);
+ }
+ try {
+ Object response = method.invoke(module, args);
+ if (isGetInstance) {
+ cachedInstance = response;
+ }
+ return response;
+ } catch(InvocationTargetException e) {
+ throw e.getCause();
+ } finally {
+ if (isGetInstance) {
+ deadlockMonitor.setCurrentlyInstantiatedModule(null);
+ }
+ }
+ }
+ }
+
public void put(
final ModuleIdentifier moduleIdentifier,
final Module module,
- ModuleFactory moduleFactory,
- ModuleInternalInfo maybeOldInternalInfo,
- TransactionModuleJMXRegistration transactionModuleJMXRegistration,
- boolean isDefaultBean, BundleContext bundleContext) {
+ final ModuleFactory moduleFactory,
+ final ModuleInternalInfo maybeOldInternalInfo,
+ final TransactionModuleJMXRegistration transactionModuleJMXRegistration,
+ final boolean isDefaultBean, final BundleContext bundleContext) {
transactionStatus.checkNotCommitted();
Class<? extends Module> moduleClass = Module.class;
if (module instanceof RuntimeBeanRegistratorAwareModule) {
moduleClass = RuntimeBeanRegistratorAwareModule.class;
}
- Module proxiedModule = Reflection.newProxy(moduleClass, new AbstractInvocationHandler() {
- // optimization: subsequent calls to getInstance MUST return the same value during transaction,
- // so it is safe to cache the response
- private Object cachedInstance;
-
- @Override
- protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
- boolean isGetInstance = "getInstance".equals(method.getName());
- if (isGetInstance) {
- if (cachedInstance != null) {
- return cachedInstance;
- }
-
- checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive");
- deadlockMonitor.setCurrentlyInstantiatedModule(moduleIdentifier);
- }
- try {
- Object response = method.invoke(module, args);
- if (isGetInstance) {
- cachedInstance = response;
- }
- return response;
- } catch(InvocationTargetException e) {
- throw e.getCause();
- } finally {
- if (isGetInstance) {
- deadlockMonitor.setCurrentlyInstantiatedModule(null);
- }
- }
- }
- });
-
-
+ Module proxiedModule = Reflection.newProxy(moduleClass, new ModuleInvocationHandler(deadlockMonitor, moduleIdentifier, module));
ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = new ModuleInternalTransactionalInfo(
moduleIdentifier, proxiedModule, moduleFactory,
maybeOldInternalInfo, transactionModuleJMXRegistration, isDefaultBean, module, bundleContext);
return modulesHolder.toCommitInfo();
}
- public Module findModule(ModuleIdentifier moduleIdentifier,
- JmxAttribute jmxAttributeForReporting) {
+ public Module findModule(final ModuleIdentifier moduleIdentifier,
+ final JmxAttribute jmxAttributeForReporting) {
return modulesHolder.findModule(moduleIdentifier,
jmxAttributeForReporting);
}
- public ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(ModuleIdentifier moduleIdentifier) {
+ public ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(final ModuleIdentifier moduleIdentifier) {
return modulesHolder.findModuleInternalTransactionalInfo(moduleIdentifier);
}
- public ModuleFactory findModuleFactory(ModuleIdentifier moduleIdentifier,
- JmxAttribute jmxAttributeForReporting) {
+ public ModuleFactory findModuleFactory(final ModuleIdentifier moduleIdentifier,
+ final JmxAttribute jmxAttributeForReporting) {
return modulesHolder.findModuleFactory(moduleIdentifier,
jmxAttributeForReporting);
}
return modulesHolder.getAllModules();
}
- public void assertNotExists(ModuleIdentifier moduleIdentifier)
+ public void assertNotExists(final ModuleIdentifier moduleIdentifier)
throws InstanceAlreadyExistsException {
modulesHolder.assertNotExists(moduleIdentifier);
}
- public List<ModuleIdentifier> findAllByFactory(ModuleFactory factory) {
+ public List<ModuleIdentifier> findAllByFactory(final ModuleFactory factory) {
List<ModuleIdentifier> result = new ArrayList<>();
for (ModuleInternalTransactionalInfo info : modulesHolder.getAllInfos()) {
if (factory.equals(info.getModuleFactory())) {
return result;
}
+ @Override
public void close() {
deadlockMonitor.close();
}
*/
package org.opendaylight.controller.config.manager.impl.dynamicmbean;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.Description;
-import org.opendaylight.controller.config.api.annotations.RequireInterface;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper;
-import org.opendaylight.controller.config.spi.Module;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import static java.lang.String.format;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.ReflectionException;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static java.lang.String.format;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.config.api.annotations.Description;
+import org.opendaylight.controller.config.api.annotations.RequireInterface;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper;
+import org.opendaylight.controller.config.spi.Module;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Contains common code for readable/rw dynamic mbean wrappers. Routes all
* a read only wrapper.
*/
abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
- private static final Logger LOGGER = LoggerFactory
- .getLogger(AbstractDynamicWrapper.class);
+ private static final class ModuleNotificationListener implements NotificationListener {
+ private final ObjectName objectNameInternal;
+ private final MBeanServer internalServer;
+ private final ObjectName thisWrapperObjectName;
+ private final MBeanServer configMBeanServer;
+
+ private ModuleNotificationListener(final ObjectName objectNameInternal, final MBeanServer internalServer,
+ final ObjectName thisWrapperObjectName, final MBeanServer configMBeanServer) {
+ this.objectNameInternal = objectNameInternal;
+ this.internalServer = internalServer;
+ this.thisWrapperObjectName = thisWrapperObjectName;
+ this.configMBeanServer = configMBeanServer;
+ }
+
+ @Override
+ public void handleNotification(final Notification n, final Object handback) {
+ if (n instanceof MBeanServerNotification
+ && n.getType()
+ .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
+ if (((MBeanServerNotification) n).getMBeanName().equals(
+ thisWrapperObjectName)) {
+ try {
+ internalServer.unregisterMBean(objectNameInternal);
+ configMBeanServer.removeNotificationListener(
+ MBeanServerDelegate.DELEGATE_NAME, this);
+ } catch (MBeanRegistrationException
+ | ListenerNotFoundException
+ | InstanceNotFoundException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ }
+ }
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractDynamicWrapper.class);
protected final boolean writable;
protected final Module module;
protected final ModuleIdentifier moduleIdentifier;
protected final MBeanServer internalServer;
- public AbstractDynamicWrapper(Module module, boolean writable,
- ModuleIdentifier moduleIdentifier,
- ObjectName thisWrapperObjectName, MBeanOperationInfo[] dOperations,
- MBeanServer internalServer, MBeanServer configMBeanServer) {
+ public AbstractDynamicWrapper(final Module module, final boolean writable,
+ final ModuleIdentifier moduleIdentifier,
+ final ObjectName thisWrapperObjectName, final MBeanOperationInfo[] dOperations,
+ final MBeanServer internalServer, final MBeanServer configMBeanServer) {
this.writable = writable;
this.module = module;
* platform mbean server. Wait until this wrapper gets unregistered, in that
* case unregister the module and remove listener.
*/
- private final NotificationListener registerActualModule(Module module,
+ private final NotificationListener registerActualModule(final Module module,
final ObjectName thisWrapperObjectName,
final ObjectName objectNameInternal,
final MBeanServer internalServer,
"Error occured during mbean registration with name " + objectNameInternal, e);
}
- NotificationListener listener = new NotificationListener() {
- @Override
- public void handleNotification(Notification n, Object handback) {
- if (n instanceof MBeanServerNotification
- && n.getType()
- .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
- if (((MBeanServerNotification) n).getMBeanName().equals(
- thisWrapperObjectName)) {
- try {
- internalServer.unregisterMBean(objectNameInternal);
- configMBeanServer.removeNotificationListener(
- MBeanServerDelegate.DELEGATE_NAME, this);
- } catch (MBeanRegistrationException
- | ListenerNotFoundException
- | InstanceNotFoundException e) {
- throw new IllegalStateException(e);
- }
- }
- }
- }
- };
+ NotificationListener listener = new ModuleNotificationListener(objectNameInternal, internalServer, thisWrapperObjectName, configMBeanServer);
try {
configMBeanServer.addNotificationListener(
MBeanServerDelegate.DELEGATE_NAME, listener, null, null);
return listener;
}
- private static MBeanInfo generateMBeanInfo(String className, Module module,
- Map<String, AttributeHolder> attributeHolderMap,
- MBeanOperationInfo[] dOperations, Set<Class<?>> jmxInterfaces) {
+ private static MBeanInfo generateMBeanInfo(final String className, final Module module,
+ final Map<String, AttributeHolder> attributeHolderMap,
+ final MBeanOperationInfo[] dOperations, final Set<Class<?>> jmxInterfaces) {
String dDescription = findDescription(module.getClass(), jmxInterfaces);
MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[0];
dOperations, new MBeanNotificationInfo[0]);
}
- static String findDescription(Class<?> clazz, Set<Class<?>> jmxInterfaces) {
+ static String findDescription(final Class<?> clazz, final Set<Class<?>> jmxInterfaces) {
List<Description> descriptions = AnnotationsHelper
.findClassAnnotationInSuperClassesAndIfcs(clazz, Description.class, jmxInterfaces);
return AnnotationsHelper.aggregateDescriptions(descriptions);
// inspect all exported interfaces ending with MXBean, extract getters &
// setters into attribute holder
- private static Map<String, AttributeHolder> buildMBeanInfo(Module module,
- boolean writable, ModuleIdentifier moduleIdentifier,
- Set<Class<?>> jmxInterfaces, MBeanServer internalServer,
- ObjectName internalObjectName) {
+ private static Map<String, AttributeHolder> buildMBeanInfo(final Module module,
+ final boolean writable, final ModuleIdentifier moduleIdentifier,
+ final Set<Class<?>> jmxInterfaces, final MBeanServer internalServer,
+ final ObjectName internalObjectName) {
// internal variables for describing MBean elements
Set<Method> methods = new HashSet<>();
}
@Override
- public Object getAttribute(String attributeName)
+ public Object getAttribute(final String attributeName)
throws AttributeNotFoundException, MBeanException,
ReflectionException {
if ("MBeanInfo".equals(attributeName)) {
return obj;
}
- private Object fixDependencyListAttribute(Object attribute) {
+ private Object fixDependencyListAttribute(final Object attribute) {
if (attribute.getClass().isArray() == false) {
throw new IllegalArgumentException("Unexpected attribute type, should be an array, but was " + attribute.getClass());
}
return attribute;
}
- private boolean isDependencyListAttr(String attributeName, Object attribute) {
+ private boolean isDependencyListAttr(final String attributeName, final Object attribute) {
if (attributeHolderMap.containsKey(attributeName) == false) {
return false;
}
return isDepList;
}
- protected ObjectName fixObjectName(ObjectName on) {
+ protected ObjectName fixObjectName(final ObjectName on) {
if (!ObjectNameUtil.ON_DOMAIN.equals(on.getDomain())) {
throw new IllegalArgumentException("Wrong domain, expected "
+ ObjectNameUtil.ON_DOMAIN + " setter on " + on);
}
@Override
- public AttributeList getAttributes(String[] attributes) {
+ public AttributeList getAttributes(final String[] attributes) {
AttributeList result = new AttributeList();
for (String attributeName : attributes) {
try {
result.add(new Attribute(attributeName, value));
} catch (Exception e) {
- LOGGER.debug("Getting attribute {} failed", attributeName, e);
+ LOG.debug("Getting attribute {} failed", attributeName, e);
}
}
return result;
}
@Override
- public Object invoke(String actionName, Object[] params, String[] signature)
+ public Object invoke(final String actionName, final Object[] params, final String[] signature)
throws MBeanException, ReflectionException {
if ("getAttribute".equals(actionName) && params.length == 1
&& signature[0].equals(String.class.getName())) {
&& signature[0].equals(AttributeList.class.getName())) {
return setAttributes((AttributeList) params[0]);
} else {
- LOGGER.debug("Operation not found {} ", actionName);
+ LOG.debug("Operation not found {} ", actionName);
throw new UnsupportedOperationException(
format("Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) "
+ "method, got actionName %s, params %s, signature %s ",
}
@Override
- public final boolean equals(Object other) {
+ public final boolean equals(final Object other) {
return module.equals(other);
}
* Users of this interface can publish any YANG-modeled notification which will
* be delivered to all subscribed listeners.
* <p>
- * Prefered way of publishing of notifications is done by invoking {@link #publish(Object)}.
+ * Preferred way of publishing of notifications is done by invoking {@link #publish(Object)}.
*
* <p>You may consider using {@link #publish(Object, ExecutorService)} if and only if
* your use-case requires customized execution policy or run-to-completion
* Publishes a notification and notifies subscribed listeners. All listener
* notifications are done via the provided executor.
* <p>
- * <b>Note:</b> Use only if ineccessary. Consider using
+ * <b>Note:</b> Use only if necessary. Consider using
* {@link #publish(Object)} for most use-cases.
*
* <p>
package org.opendaylight.controller.md.sal.common.api.notify;
import java.util.EventListener;
-
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-public interface NotificationSubscriptionService<T,N,L extends EventListener> {
+public interface NotificationSubscriptionService<T, N, L extends EventListener> {
- ListenerRegistration<L> registerNotificationListener(T type,L listener);
+ ListenerRegistration<L> registerNotificationListener(T type, L listener);
}
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import javax.annotation.Nullable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-
public class BackwardsCompatibleMountPoint implements MountProvisionInstance, SchemaContextProvider, SchemaService {
private final DataProviderService dataReader;
class ReadWrapper implements DataReader<YangInstanceIdentifier, CompositeNode> {
private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) {
- YangInstanceIdentifier ret = null;
- if(mountPath.contains(path)) {
- final List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
- ret = YangInstanceIdentifier.create(newArgs);
+ if (!mountPath.contains(path)) {
+ return null;
}
- return ret;
+ return YangInstanceIdentifier.create(Iterables.skip(path.getPathArguments(), Iterables.size(mountPath.getPathArguments())));
}
@Override
return Futures.immediateCheckedFuture(normalizedNodeOptional);
}
- @Override public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store,
- YangInstanceIdentifier path) {
+ @Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
+ final YangInstanceIdentifier path) {
try {
return Futures.immediateCheckedFuture(read(store, path).get().isPresent());
return new BackwardsCompatibleReadTransaction(dataReader, dataNormalizer).read(store, path);
}
- @Override public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store,
- YangInstanceIdentifier path) {
+ @Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
+ final YangInstanceIdentifier path) {
try {
return Futures.immediateCheckedFuture(read(store, path).get().isPresent());
*/
package org.opendaylight.controller.sal.dom.broker;
-import java.util.List;
+import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.Set;
-
import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import com.google.common.util.concurrent.ListenableFuture;
-
@Deprecated
public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
class ReadWrapper implements DataReader<YangInstanceIdentifier, CompositeNode> {
private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) {
- YangInstanceIdentifier ret = null;
- if(mountPath.contains(path)) {
- List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
- ret = YangInstanceIdentifier.create(newArgs);
+ if (!mountPath.contains(path)) {
+ return null;
}
- return ret;
+
+ return YangInstanceIdentifier.create(Iterables.skip(path.getPathArguments(), Iterables.size(mountPath.getPathArguments())));
}
@Override
package org.opendaylight.controller.sal.dom.broker.impl;
import static com.google.common.base.Preconditions.checkState;
-
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Future;
-
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.DataModification;
import org.opendaylight.controller.md.sal.common.api.data.DataReader;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
public int compare(final Entry<YangInstanceIdentifier, CompositeNode> o1, final Entry<YangInstanceIdentifier, CompositeNode> o2) {
YangInstanceIdentifier o1Key = o1.getKey();
YangInstanceIdentifier o2Key = o2.getKey();
- return Integer.compare(o1Key.getPath().size(), o2Key.getPath().size());
+ return Integer.compare(Iterables.size(o1Key.getPathArguments()), Iterables.size(o2Key.getPathArguments()));
}
};
childNodes.addAll(original.getValue());
qname = original.getNodeType();
} else {
- qname = path.getPath().get(path.getPath().size() - 1).getNodeType();
+ qname = path.getLastPathArgument().getNodeType();
}
FluentIterable<YangInstanceIdentifier> directChildren = FluentIterable.from(getStoredConfigurationPaths())
@Override
public boolean apply(final YangInstanceIdentifier input) {
if (path.contains(input)) {
- int nesting = input.getPath().size() - path.getPath().size();
+ int nesting = Iterables.size(input.getPathArguments()) - Iterables.size(path.getPathArguments());
if (nesting == 1) {
return true;
}
childNodes.addAll(original.getValue());
qname = original.getNodeType();
} else {
- qname = path.getPath().get(path.getPath().size() - 1).getNodeType();
+ qname = path.getLastPathArgument().getNodeType();
}
FluentIterable<YangInstanceIdentifier> directChildren = FluentIterable.from(getStoredOperationalPaths())
@Override
public boolean apply(final YangInstanceIdentifier input) {
if (path.contains(input)) {
- int nesting = input.getPath().size() - path.getPath().size();
+ int nesting = Iterables.size(input.getPathArguments()) - Iterables.size(path.getPathArguments());
if (nesting == 1) {
return true;
}
import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TARGET_QNAME;
import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.ROLLBACK_ON_ERROR_OPTION;
-
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
final Optional<CompositeNode> lastChildOverride) {
Preconditions.checkArgument(Iterables.isEmpty(dataPath.getPathArguments()) == false, "Instance identifier with empty path %s", dataPath);
- List<YangInstanceIdentifier.PathArgument> reversedPath = Lists.reverse(dataPath.getPath());
-
// Create deepest edit element with expected edit operation
- CompositeNode previous = getDeepestEditElement(reversedPath.get(0), operation, lastChildOverride);
+ CompositeNode previous = getDeepestEditElement(dataPath.getLastPathArgument(), operation, lastChildOverride);
+ Iterator<PathArgument> it = dataPath.getReversePathArguments().iterator();
// Remove already processed deepest child
- reversedPath = Lists.newArrayList(reversedPath);
- reversedPath.remove(0);
+ it.next();
// Create edit structure in reversed order
- for (final YangInstanceIdentifier.PathArgument arg : reversedPath) {
+ while (it.hasNext()) {
+ final YangInstanceIdentifier.PathArgument arg = it.next();
final CompositeNodeBuilder<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
builder.setQName(arg.getNodeType());
*/
package org.opendaylight.controller.sal.connect.netconf.util;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.annotation.Nullable;
-
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.api.NetconfMessage;
import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
public class NetconfMessageTransformUtil {
public static final String MESSAGE_ID_ATTR = "message-id";
public static final QName IETF_NETCONF_MONITORING_SCHEMA_VERSION = QName.create(IETF_NETCONF_MONITORING, "version");
public static final QName IETF_NETCONF_MONITORING_SCHEMA_NAMESPACE = QName.create(IETF_NETCONF_MONITORING, "namespace");
- public static URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0");
- public static QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf");
- public static QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data");
- public static QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply");
- public static QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option");
- public static QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running");
- static List<Node<?>> RUNNING = Collections.<Node<?>> singletonList(new SimpleNodeTOImpl<>(NETCONF_RUNNING_QNAME, null, null));
- public static QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source");
- public static CompositeNode CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME, null, RUNNING);
- public static QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate");
- public static QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target");
- public static QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config");
- public static QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit");
- public static QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation");
- public static QName NETCONF_DEFAULT_OPERATION_QNAME = QName.create(NETCONF_OPERATION_QNAME, "default-operation");
- public static QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config");
- public static QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config");
- public static QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes");
- public static QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type");
- public static QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter");
- public static QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get");
- public static QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc");
-
- public static URI NETCONF_ROLLBACK_ON_ERROR_URI = URI
+ public static final URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0");
+ public static final QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf");
+ public static final QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data");
+ public static final QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply");
+ public static final QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option");
+ public static final QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running");
+ static final List<Node<?>> RUNNING = Collections.<Node<?>> singletonList(new SimpleNodeTOImpl<>(NETCONF_RUNNING_QNAME, null, null));
+ public static final QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source");
+ public static final CompositeNode CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME, null, RUNNING);
+ public static final QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate");
+ public static final QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target");
+ public static final QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config");
+ public static final QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit");
+ public static final QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation");
+ public static final QName NETCONF_DEFAULT_OPERATION_QNAME = QName.create(NETCONF_OPERATION_QNAME, "default-operation");
+ public static final QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config");
+ public static final QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config");
+ public static final QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes");
+ public static final QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type");
+ public static final QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter");
+ public static final QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get");
+ public static final QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc");
+
+ public static final URI NETCONF_ROLLBACK_ON_ERROR_URI = URI
.create("urn:ietf:params:netconf:capability:rollback-on-error:1.0");
- public static String ROLLBACK_ON_ERROR_OPTION = "rollback-on-error";
+ public static final String ROLLBACK_ON_ERROR_OPTION = "rollback-on-error";
- public static URI NETCONF_CANDIDATE_URI = URI
+ public static final URI NETCONF_CANDIDATE_URI = URI
.create("urn:ietf:params:netconf:capability:candidate:1.0");
// Discard changes message
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML;
-
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.io.IOException;
assertEquals(400, post(uri, MediaType.APPLICATION_JSON, ""));
}
- private void mockInvokeRpc(CompositeNode result, boolean sucessful, Collection<RpcError> errors) {
+ private void mockInvokeRpc(final CompositeNode result, final boolean sucessful, final Collection<RpcError> errors) {
DummyRpcResult.Builder<CompositeNode> builder = new DummyRpcResult.Builder<CompositeNode>().result(result)
.isSuccessful(sucessful);
Futures.<RpcResult<CompositeNode>> immediateFuture(rpcResult));
}
- private void mockInvokeRpc(CompositeNode result, boolean sucessful) {
+ private void mockInvokeRpc(final CompositeNode result, final boolean sucessful) {
mockInvokeRpc(result, sucessful, Collections.<RpcError> emptyList());
}
assertEquals(204, post(URI_1, Draft02.MediaTypes.DATA + XML, xmlTestInterface));
verify(brokerFacade).commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture());
String identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces]";
- assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString());
+ assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
String URI_2 = "/config/test-interface:interfaces";
assertEquals(204, post(URI_2, Draft02.MediaTypes.DATA + XML, xmlBlockData));
verify(brokerFacade, times(2))
.commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture());
identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces, (urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)block]";
- assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString());
+ assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
}
@Test
restconfImpl.setControllerContext(controllerContext);
}
- private int post(String uri, String mediaType, String data) {
+ private int post(final String uri, final String mediaType, final String data) {
return target(uri).request(mediaType).post(Entity.entity(data, mediaType)).getStatus();
}
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.io.FileNotFoundException;
import java.util.Set;
.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
assertEquals(
"[(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)class, (urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)student[{(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)name=name}]]",
- instanceIdentifier.getInstanceIdentifier().getPath().toString());
+ ImmutableList.copyOf(instanceIdentifier.getInstanceIdentifier().getPathArguments()).toString());
}
@Test
exception.expect(RestconfDocumentedException.class);
controllerContext.setMountService(null);
- InstanceIdentifierContext instanceIdentifier = controllerContext
- .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
+ controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
}
@Test
initMountService(false);
exception.expect(RestconfDocumentedException.class);
- InstanceIdentifierContext instanceIdentifier = controllerContext
- .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
+ controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
}
public void initMountService(final boolean withSchema) {
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.net.URISyntaxException;
-import java.util.List;
+import java.util.Iterator;
import java.util.Map;
import javax.ws.rs.WebApplicationException;
import org.junit.BeforeClass;
import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
verifyLeafListPredicate(cnSn);
}
- private void verifyLeafListPredicate(CompositeNode cnSn) throws URISyntaxException {
+ private void verifyLeafListPredicate(final CompositeNode cnSn) throws URISyntaxException {
SimpleNode<?> lf11 = getSnWithInstanceIdentifierWhenLeafList(cnSn);
Object value = lf11.getValue();
assertTrue(value instanceof YangInstanceIdentifier);
YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value;
- List<PathArgument> pathArguments = instanceIdentifier.getPath();
- assertEquals(3, pathArguments.size());
+ Iterator<PathArgument> it = instanceIdentifier.getPathArguments().iterator();
String revisionDate = "2014-01-17";
- assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
- .getNodeType());
- assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
- .getNodeType());
- assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), pathArguments.get(2)
- .getNodeType());
- assertTrue(pathArguments.get(2) instanceof NodeWithValue);
- assertEquals("lflst11_1", ((NodeWithValue) pathArguments.get(2)).getValue());
+ assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType());
+ assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType());
+
+ PathArgument arg = it.next();
+ assertFalse(it.hasNext());
+ assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), arg.getNodeType());
+
+ assertTrue(arg instanceof NodeWithValue);
+ assertEquals("lflst11_1", ((NodeWithValue) arg).getValue());
}
- private void verifyListPredicate(CompositeNode cnSn) throws URISyntaxException {
+ private void verifyListPredicate(final CompositeNode cnSn) throws URISyntaxException {
SimpleNode<?> lf111 = getSnWithInstanceIdentifierWhenList(cnSn);
Object value = lf111.getValue();
assertTrue(value instanceof YangInstanceIdentifier);
YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value;
- List<PathArgument> pathArguments = instanceIdentifier.getPath();
- assertEquals(4, pathArguments.size());
+ Iterator<PathArgument> it = instanceIdentifier.getPathArguments().iterator();
String revisionDate = "2014-01-17";
- assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
- .getNodeType());
- assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
- .getNodeType());
- assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), pathArguments.get(2).getNodeType());
- assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), pathArguments.get(3)
- .getNodeType());
-
- assertTrue(pathArguments.get(2) instanceof NodeIdentifierWithPredicates);
- Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArguments.get(2)).getKeyValues();
+ assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType());
+ assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType());
+
+ PathArgument arg = it.next();
+ assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), arg.getNodeType());
+ assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), it.next().getNodeType());
+ assertFalse(it.hasNext());
+
+ assertTrue(arg instanceof NodeIdentifierWithPredicates);
+ Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) arg).getKeyValues();
assertEquals(2, predicates.size());
assertEquals("value1", predicates.get(TestUtils.buildQName("keyvalue111", "augment:module", revisionDate)));
assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
}
- private SimpleNode<?> getSnWithInstanceIdentifierWhenList(CompositeNode cnSn) throws URISyntaxException {
+ private SimpleNode<?> getSnWithInstanceIdentifierWhenList(final CompositeNode cnSn) throws URISyntaxException {
CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
"2014-01-17"));
assertNotNull(cont1);
return lf111;
}
- private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(CompositeNode cnSn) throws URISyntaxException {
+ private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(final CompositeNode cnSn) throws URISyntaxException {
CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
"2014-01-17"));
assertNotNull(cont1);