[ONOS-5763] YSR changes to support decode without module name.
Change-Id: I662e52c2b3971e7a333ec9d887f8747733a0e87e
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistry.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistry.java
index 58d772c..0c4e22f 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistry.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistry.java
@@ -112,6 +112,11 @@
*/
private final ConcurrentMap<YangModuleIdentifier, String> yangFileStore;
+ /**
+ * Map for storing schema nodes with respect to namespace.
+ */
+ private final ConcurrentMap<String, YangSchemaNode> nameSpaceSchemaStore;
+
private final ConcurrentMap<Object, Boolean> ynhRegistrationStore;
private final ConcurrentMap<String, String> jarPathStore;
@@ -129,6 +134,7 @@
appNameKeyStore = new ConcurrentHashMap<>();
ynhRegistrationStore = new ConcurrentHashMap<>();
jarPathStore = new ConcurrentHashMap<>();
+ nameSpaceSchemaStore = new ConcurrentHashMap<>();
}
@@ -188,6 +194,8 @@
opParamNameKeyStore.remove(getOpParamClassName(curNode));
yangFileStore.remove(getModuleIdentifier(curNode));
appNameKeyStore.remove(serviceName);
+ nameSpaceSchemaStore.remove(curNode.getNameSpace()
+ .getModuleNamespace());
removeYsrGeneratedTemporaryResources(jarPathStore.get(serviceName),
serviceName);
log.info(" service {} is unregistered.",
@@ -267,6 +275,16 @@
}
@Override
+ public YangSchemaNode getSchemaWrtNameSpace(String nameSpace) {
+
+ YangSchemaNode node = nameSpaceSchemaStore.get(nameSpace);
+ if (node == null) {
+ log.error("node with {} namespace not found.", nameSpace);
+ }
+ return node;
+ }
+
+ @Override
public String getYangFile(YangModuleIdentifier moduleIdentifier) {
String file = yangFileStore.get(moduleIdentifier);
if (file == null) {
@@ -312,6 +330,7 @@
interfaceNameKeyStore.clear();
registerClassStore.clear();
yangFileStore.clear();
+ nameSpaceSchemaStore.clear();
}
@Override
@@ -494,6 +513,10 @@
//update op param store.
opParamNameKeyStore.put(getOpParamClassName(appNode), appNode);
+
+ //update namespaceSchema store.
+ nameSpaceSchemaStore.put(appNode.getNameSpace().getModuleNamespace(), appNode);
+
//Checks if notification is present then update notification store map.
String eventSubject = null;
try {
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/YangSchemaRegistry.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/YangSchemaRegistry.java
index ed5d95a..e283f57 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/YangSchemaRegistry.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ysr/YangSchemaRegistry.java
@@ -141,4 +141,19 @@
*/
void processModuleLibrary(String serviceName, YangModuleLibrary library);
+ /**
+ * Returns YANG schema node for a given namespace while xml decoding.
+ * <p>
+ * According to rfc 6020 Xml should not have module name in it but when
+ * decoder wants to convert xml to YANG object it will need module schema
+ * which it can get only by using module name from YSR. So if YCH sends
+ * namespace of a module we can given it the schema node of module. In
+ * this case namespace should be unique.
+ * </p>
+ *
+ * @param nameSpace name space of module
+ * @return module schema node
+ */
+ YangSchemaNode getSchemaWrtNameSpace(String nameSpace);
+
}
diff --git a/apps/yms/ut/pom.xml b/apps/yms/ut/pom.xml
index e7eb001..24ef5ab 100644
--- a/apps/yms/ut/pom.xml
+++ b/apps/yms/ut/pom.xml
@@ -78,7 +78,7 @@
<plugin>
<groupId>org.onosproject</groupId>
<artifactId>onos-yang-maven-plugin</artifactId>
- <version>1.10</version>
+ <version>1.11</version>
<configuration>
<yangFilesDir>src/test/resources/</yangFilesDir>
</configuration>
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/MockYangSchemaRegistry.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/MockYangSchemaRegistry.java
deleted file mode 100644
index 253332e..0000000
--- a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ydt/MockYangSchemaRegistry.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yms.app.ydt;
-
-import org.onosproject.yangutils.datamodel.YangSchemaNode;
-import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry;
-import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider;
-import org.onosproject.yms.app.ysr.YangSchemaRegistry;
-import org.onosproject.yms.ysr.YangModuleIdentifier;
-import org.onosproject.yms.ysr.YangModuleLibrary;
-
-import static org.junit.Assert.assertEquals;
-
-
-/**
- * Represent Yang schema registry. Yang schema registry provides
- * interface to an application to register its YANG
- * schema with YMS. It provides YANG schema nodes to YDT, YNB and YSB.
- */
-public class MockYangSchemaRegistry implements YangSchemaRegistry {
-
- @Override
- public void registerApplication(Object managerObject, Class<?> serviceClass) {
-
- }
-
- @Override
- public void unRegisterApplication(Object managerObject,
- Class<?> serviceClass) {
- }
-
- @Override
- public Object getRegisteredApplication(YangSchemaNode yangSchemaNode) {
- return null;
- }
-
- @Override
- public YangSchemaNode getYangSchemaNodeUsingAppName(String schemaName) {
- return null;
- }
-
- @Override
- public YangSchemaNode getYangSchemaNodeUsingSchemaName(String appName) {
-
- final String target = "target/TestYangSchemaNodeProvider";
- TestYangSchemaNodeProvider testYangSchemaNodeProvider =
- new TestYangSchemaNodeProvider();
-
- String searchDir = "src/test/resources/ydtTestYangFiles/";
-
- testYangSchemaNodeProvider.processSchemaRegistry(null);
-
- DefaultYangSchemaRegistry registry = testYangSchemaNodeProvider
- .getDefaultYangSchemaRegistry();
- YangSchemaNode yangNode = registry
- .getYangSchemaNodeUsingSchemaName(appName);
- assertEquals(appName, yangNode.getName());
- return yangNode;
- }
-
- @Override
- public YangSchemaNode
- getYangSchemaNodeUsingGeneratedRootNodeInterfaceFileName(
- String rootInterfaceFileName) {
- return null;
- }
-
- @Override
- public YangSchemaNode getYangSchemaNodeUsingGeneratedRootNodeOpPramFileName(
- String rootOpParamFileName) {
- return null;
- }
-
- @Override
- public YangSchemaNode getRootYangSchemaNodeForNotification(
- String eventSubject) {
- return null;
- }
-
- @Override
- public Class<?> getRegisteredClass(YangSchemaNode schemaNode) {
- return null;
- }
-
- @Override
- public boolean verifyNotificationObject(Object appObj, Class<?> service) {
- return false;
- }
-
- @Override
- public void flushYsrData() {
-
- }
-
- @Override
- public String getYangFile(YangModuleIdentifier moduleIdentifier) {
- return null;
- }
-
- @Override
- public void processModuleLibrary(String serviceName, YangModuleLibrary library) {
-
- }
-
-}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistryTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistryTest.java
index bf8d46a..1ae9efd 100644
--- a/apps/yms/ut/src/test/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistryTest.java
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/ysr/DefaultYangSchemaRegistryTest.java
@@ -21,8 +21,11 @@
import org.junit.rules.ExpectedException;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network1.rev20151208.IetfNetwork1Service;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network2.rev20151208.IetfNetwork2Service;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.TestService;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yms.app.yab.TestManager;
import java.io.IOException;
@@ -156,6 +159,10 @@
private static final String UN_REG_OP_PARAM_NAME = "IetfRoutingOpParam";
private static final String UN_REG_SERVICE_NAME = "IetfRoutingService";
private static final String UN_REG_EVENT_NAME = "IetfRoutingEvent";
+ private static final String CHECK = "check";
+ private static final String DATE_NAMESPACE = "2015-00-08";
+ private static final String NAMESPACE =
+ "urn:ietf:params:xml:ns:yang:ietf-network4:check:namespace";
private final TestYangSchemaNodeProvider testYangSchemaNodeProvider =
new TestYangSchemaNodeProvider();
@@ -668,10 +675,30 @@
.getDefaultYangSchemaRegistry()
.verifyNotificationObject(manager, IetfNetwork2Service.class);
assertThat(false, is(isRegWithNotification));
- //TODO fix with YAB
-// isRegWithNotification = testYangSchemaNodeProvider
-// .getDefaultYangSchemaRegistry()
-// .verifyNotificationObject(new TestManager(), TestService.class);
-// assertThat(false, is(isRegWithNotification));
+ isRegWithNotification = testYangSchemaNodeProvider
+ .getDefaultYangSchemaRegistry()
+ .verifyNotificationObject(new TestManager(), TestService.class);
+ assertThat(false, is(isRegWithNotification));
+ }
+
+ /**
+ * get schema for namespace in decode test.
+ */
+ @Test
+ public void testGetNodeWrtNamespace() {
+ MockIetfManager manager = new MockIetfManager();
+ testYangSchemaNodeProvider.processSchemaRegistry(manager);
+ DefaultYangSchemaRegistry registry =
+ testYangSchemaNodeProvider.getDefaultYangSchemaRegistry();
+
+ YangSchemaNode yangNode =
+ registry.getSchemaWrtNameSpace(NAMESPACE);
+ assertThat(true, is(CHECK.equals(yangNode.getName())));
+
+ YangRevision rev = ((YangNode) yangNode).getRevision();
+ assertThat(true, is(rev != null));
+
+ String date = registry.getDateInStringFormat(yangNode);
+ assertThat(true, is(DATE_NAMESPACE.equals(date)));
}
}
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ysrTestYangFiles/CheckWithNamespace.yang b/apps/yms/ut/src/test/resources/ysrTestYangFiles/CheckWithNamespace.yang
new file mode 100644
index 0000000..7e5726e
--- /dev/null
+++ b/apps/yms/ut/src/test/resources/ysrTestYangFiles/CheckWithNamespace.yang
@@ -0,0 +1,80 @@
+ module check {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-network4:check:namespace";
+ prefix nd;
+
+ organization
+ "IETF I2RS (Interface to the Routing System) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/i2rs/>
+ WG List: <mailto:i2rs@ietf.org>
+
+ WG Chair: Susan Hares
+ <mailto:shares@ndzh.com>
+
+ WG Chair: Jeffrey Haas
+ <mailto:jhaas@pfrc.org>
+
+ Editor: Alexander Clemm
+ <mailto:alex@cisco.com>
+
+ Editor: Jan Medved
+ <mailto:jmedved@cisco.com>
+
+ Editor: Robert Varga
+ <mailto:rovarga@cisco.com>
+
+ Editor: Tony Tkacik
+ <mailto:ttkacik@cisco.com>
+
+ Editor: Nitin Bahadur
+ <mailto:nitin_bahadur@yahoo.com>
+
+ Editor: Hariharan Ananthakrishnan
+ <mailto:hari@packetdesign.com>";
+
+ description
+ "This module defines a common base model for a collection
+ of nodes in a network. Node definitions are further used
+ in network topologies and inventories.
+
+ Copyright (c) 2015 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or
+ without modification, is permitted pursuant to, and subject
+ to the license terms contained in, the Simplified BSD License
+ set forth in Section 4.c of the IETF Trust's Legal Provisions
+ Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of
+ draft-ietf-i2rs-yang-network-topo-02;
+ see the RFC itself for full legal notices.
+
+ NOTE TO RFC EDITOR: Please replace above reference to
+ draft-ietf-i2rs-yang-network-topo-02 with RFC
+ number when published (i.e. RFC xxxx).";
+
+ revision 2015-12-08 {
+ description
+ "Initial revision.
+ NOTE TO RFC EDITOR: Please replace the following reference
+ to draft-ietf-i2rs-yang-network-topo-02 with
+ RFC number when published (i.e. RFC xxxx).";
+ reference
+ "draft-ietf-i2rs-yang-network-topo-02";
+ }
+
+ container networks {
+ leaf id {
+ type int32;
+ }
+ container network {
+ leaf ip-address {
+ type int32;
+ }
+ }
+ }
+}