From 32e32254cf269027359a786735f0b7fb580b39a4 Mon Sep 17 00:00:00 2001 From: Vaclav Demcak Date: Fri, 6 Mar 2015 14:36:50 +0100 Subject: [PATCH] Quickfix: Remove deprecated providers from Restconf Application Jersey 1.17 has problem with multiple Entity providers, which consumes same content-type and produces different Entity class. In wiring phase it does not report any problems, but in runtime it may select incorrect one, which will result in IllegalArgumentException, which is not reported. So in order to unblock most of functionality, legacy providers are disabled. This will fix data-store access, but without subsequent patches RPCs are not usable. Change-Id: I860e162232d887d13629504421076495a50a075b Signed-off-by: Vaclav Demcak --- .../sal/rest/impl/RestconfApplication.java | 8 +++--- .../sal/restconf/impl/ControllerContext.java | 11 ++++++-- .../sal/restconf/impl/RestconfImpl.java | 10 ++----- .../sal/restconf/impl/test/URITest.java | 27 ++++++++++--------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfApplication.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfApplication.java index 9ab8fa8401..52cd96b53a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfApplication.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfApplication.java @@ -47,10 +47,10 @@ public class RestconfApplication extends Application { singletons.add(brokerFacade); singletons.add(schemaRetrieval); singletons.add(new RestconfCompositeWrapper(StatisticsRestconfServiceWrapper.getInstance(), schemaRetrieval)); - singletons.add(StructuredDataToXmlProvider.INSTANCE); - singletons.add(StructuredDataToJsonProvider.INSTANCE); - singletons.add(JsonToCompositeNodeProvider.INSTANCE); - singletons.add(XmlToCompositeNodeProvider.INSTANCE); +// singletons.add(StructuredDataToXmlProvider.INSTANCE); +// singletons.add(StructuredDataToJsonProvider.INSTANCE); +// singletons.add(JsonToCompositeNodeProvider.INSTANCE); +// singletons.add(XmlToCompositeNodeProvider.INSTANCE); return singletons; } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index a0b05150a8..4f124f581f 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -501,7 +501,7 @@ public class ControllerContext implements SchemaContextListener { } if (strings.isEmpty()) { - return new InstanceIdentifierContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); + return createContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); } final String head = strings.iterator().next(); @@ -671,7 +671,14 @@ public class ControllerContext implements SchemaContextListener { returnJustMountPoint); } - return new InstanceIdentifierContext(builder.toInstance(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); + return createContext(builder.build(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema); + } + + private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode, + final DOMMountPoint mountPoint, final SchemaContext schemaContext) { + + final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance); + return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext); } public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name, diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java index 82ac862843..74c2d90d5c 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java @@ -872,13 +872,10 @@ public class RestconfImpl implements RestconfService { final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier); final DOMMountPoint mountPoint = iiWithData.getMountPoint(); NormalizedNode data = null; - YangInstanceIdentifier normalizedII; + final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier(); if (mountPoint != null) { - normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData - .getInstanceIdentifier()); data = broker.readConfigurationData(mountPoint, normalizedII); } else { - normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier()); data = broker.readConfigurationData(normalizedII); } return new NormalizedNodeContext(iiWithData, data); @@ -931,13 +928,10 @@ public class RestconfImpl implements RestconfService { final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier); final DOMMountPoint mountPoint = iiWithData.getMountPoint(); NormalizedNode data = null; - YangInstanceIdentifier normalizedII; + final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier(); if (mountPoint != null) { - normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData - .getInstanceIdentifier()); data = broker.readOperationalData(mountPoint, normalizedII); } else { - normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier()); data = broker.readOperationalData(normalizedII); } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java index efd5482bfe..fd099d334d 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue; 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; @@ -43,9 +44,9 @@ public class URITest { @BeforeClass public static void init() throws FileNotFoundException { - Set allModules = TestUtils.loadModulesFrom("/full-versions/yangs"); + final Set allModules = TestUtils.loadModulesFrom("/full-versions/yangs"); assertNotNull(allModules); - SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules); + final SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules); controllerContext.setSchemas(schemaContext); } @@ -80,7 +81,7 @@ public class URITest { @Test public void testToInstanceIdentifierContainer() throws FileNotFoundException { - InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users"); + final InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users"); assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "users"); assertTrue(instanceIdentifier.getSchemaNode() instanceof ContainerSchemaNode); assertEquals(2, ((ContainerSchemaNode) instanceIdentifier.getSchemaNode()).getChildNodes().size()); @@ -88,7 +89,7 @@ public class URITest { @Test public void testToInstanceIdentifierChoice() throws FileNotFoundException { - InstanceIdentifierContext instanceIdentifier = controllerContext + final InstanceIdentifierContext instanceIdentifier = controllerContext .toInstanceIdentifier("simple-nodes:food/nonalcoholic"); assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic"); } @@ -120,17 +121,17 @@ public class URITest { @Test public void testMountPointWithExternModul() throws FileNotFoundException { initMountService(true); - InstanceIdentifierContext instanceIdentifier = controllerContext + final InstanceIdentifierContext instanceIdentifier = controllerContext .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}]]", + "[(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)student[{(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)name=name}]]", ImmutableList.copyOf(instanceIdentifier.getInstanceIdentifier().getPathArguments()).toString()); } @Test public void testMountPointWithoutExternModul() throws FileNotFoundException { initMountService(true); - InstanceIdentifierContext instanceIdentifier = controllerContext + final InstanceIdentifierContext instanceIdentifier = controllerContext .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/"); assertTrue(Iterables.isEmpty(instanceIdentifier.getInstanceIdentifier().getPathArguments())); } @@ -152,16 +153,16 @@ public class URITest { } public void initMountService(final boolean withSchema) { - DOMMountPointService mountService = mock(DOMMountPointService.class); + final DOMMountPointService mountService = mock(DOMMountPointService.class); controllerContext.setMountService(mountService); - BrokerFacade brokerFacade = mock(BrokerFacade.class); - RestconfImpl restconfImpl = RestconfImpl.getInstance(); + final BrokerFacade brokerFacade = mock(BrokerFacade.class); + final RestconfImpl restconfImpl = RestconfImpl.getInstance(); restconfImpl.setBroker(brokerFacade); restconfImpl.setControllerContext(controllerContext); - Set modules2 = TestUtils.loadModulesFrom("/test-config-data/yang2"); - SchemaContext schemaContext2 = TestUtils.loadSchemaContext(modules2); - DOMMountPoint mountInstance = mock(DOMMountPoint.class); + final Set modules2 = TestUtils.loadModulesFrom("/test-config-data/yang2"); + final SchemaContext schemaContext2 = TestUtils.loadSchemaContext(modules2); + final DOMMountPoint mountInstance = mock(DOMMountPoint.class); if (withSchema) { when(mountInstance.getSchemaContext()).thenReturn(schemaContext2); } else { -- 2.36.6