This method has been deprecated, so stop using it.
Change-Id: Ibfaf7e40a3d119ed05ff5743c4869e345d18e298
Signed-off-by: Robert Varga <rovarga@cisco.com>
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);