* dependencies are satisfied
*
*/
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings("unchecked")
public void init() {
log.debug("Routing init() is called");
this.topologyBWAware = new ConcurrentHashMap<Short, Graph<Node, Edge>>();
*/
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);
}
*/
public void markFollowerActive();
+ /**
+ * This will stop the timeout clock
+ */
+ public void markFollowerInActive();
+
}
}
stopwatch.start();
}
+
+ @Override
+ public void markFollowerInActive() {
+ if (stopwatch.isRunning()) {
+ stopwatch.stop();
+ }
+ }
}
void markFollowerActive(String followerId) {
followerToLog.get(followerId).markFollowerActive();
}
+
+ @VisibleForTesting
+ void markFollowerInActive(String followerId) {
+ followerToLog.get(followerId).markFollowerInActive();
+ }
}
import akka.actor.Terminated;
import akka.testkit.JavaTestKit;
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Uninterruptibles;
import com.google.protobuf.ByteString;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
final Terminated termMsg1 = probe.expectMsgClass(Terminated.class);
assertEquals(termMsg1.getActor(), followerActor1);
- //sleep enough for all the follower stopwatches to lapse
- Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().
- getElectionTimeOutInterval().toMillis(), TimeUnit.MILLISECONDS);
-
+ leader.markFollowerInActive("follower-1");
leader.markFollowerActive("follower-2");
behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
Assert.assertTrue("Behavior not instance of Leader when majority of followers are active",
final Terminated termMsg2 = probe.expectMsgClass(Terminated.class);
assertEquals(termMsg2.getActor(), followerActor2);
- //sleep enough for the remaining the follower stopwatches to lapse
- Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().
- getElectionTimeOutInterval().toMillis(), TimeUnit.MILLISECONDS);
-
+ leader.markFollowerInActive("follower-2");
behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
Assert.assertTrue("Behavior not instance of IsolatedLeader when majority followers are inactive",
behavior instanceof IsolatedLeader);
@Override public void onReceive(Object message) throws Exception {
if(message instanceof String){
if("get-all-messages".equals(message)){
- getSender().tell(messages, getSelf());
+ getSender().tell(new ArrayList(messages), getSelf());
}
} else {
messages.add(message);
Assert.assertEquals(mockListener, proxy.getInstance());
}
- @SuppressWarnings("unchecked")
@Test(timeout=10000)
public void testSuccessfulRegistration() {
new JavaTestKit(getSystem()) {{
}};
}
- @SuppressWarnings("unchecked")
@Test
public void testCloseBeforeRegistration() {
new JavaTestKit(getSystem()) {{
}
- @SuppressWarnings("unchecked")
@Test
public void testOnReceiveCloseTransaction() throws Exception {
new JavaTestKit(getSystem()) {{
}
}
- @SuppressWarnings("unchecked")
@Test
public void testReady() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
verifyCohortFutures(proxy, getSystem().actorSelection(actorRef.path()));
}
- @SuppressWarnings("unchecked")
@Test
public void testReadyForwardCompatibility() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE, 0);
eq(actorRef.path().toString()));
}
- @SuppressWarnings("unchecked")
@Test
public void testReadyWithRecordingOperationFailure() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
MergeDataReply.SERIALIZABLE_CLASS, TestException.class);
}
- @SuppressWarnings("unchecked")
@Test
public void testReadyWithReplyFailure() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
verifyCohortFutures(proxy, PrimaryNotFoundException.class);
}
- @SuppressWarnings("unchecked")
@Test
public void testReadyWithInvalidReplyMessageType() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
assertTrue("Invalid identifier: " + id, id.toString().startsWith(memberName));
}
- @SuppressWarnings("unchecked")
@Test
public void testClose() throws Exception{
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
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());
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);
assertEquals("getInventoryNodeRef", new NodeRef(invNodeID), augmentation.getInventoryNodeRef());
}
- @SuppressWarnings("rawtypes")
@Test
public void testOnNodeConnectorUpdated() {