summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-08-31 09:51:39 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-09-05 15:39:31 +0000
commit2c390365f13f5aa8d92672254cee6fae16ba823a (patch)
tree02dc033e610ae375c57c4c94e7462ebad86997a9
parentbb9141c63012d0305ac65da763af3fb0c427076f (diff)
HONEYCOMB-389 - Restconf whitelist
Change-Id: I4c60d0ea569e85b23a9d0127ef496545fc475a61 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
-rw-r--r--common/common-scripts/pom.xml5
-rw-r--r--common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy58
-rw-r--r--infra/northbound/restconf/pom.xml3
-rw-r--r--infra/northbound/restconf/src/main/resources/honeycomb-minimal-resources/config/restconf-whitelist.xml43
4 files changed, 89 insertions, 20 deletions
diff --git a/common/common-scripts/pom.xml b/common/common-scripts/pom.xml
index 5469efd69..78768741e 100644
--- a/common/common-scripts/pom.xml
+++ b/common/common-scripts/pom.xml
@@ -94,6 +94,11 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.fd.honeycomb.yang</groupId>
+ <artifactId>yang-whitelist-impl</artifactId>
+ <version>1.17.10-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy b/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy
index 8e4c38824..8061d5825 100644
--- a/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy
+++ b/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy
@@ -18,6 +18,7 @@ package io.fd.honeycomb.common.scripts
import com.google.common.base.Strings
import com.google.common.io.Files
+import io.fd.honeycomb.yang.YangModuleWhitelistReader
import org.apache.commons.io.FileUtils
import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider
@@ -56,32 +57,50 @@ class ModuleYangIndexGenerator {
return
}
- log.info "Checking module providers for project ${project.getName()}"
- // checks module provides from dependencies
- // folder with extracted libs
- def libsFolder = Paths.get(project.getBuild().getDirectory(), "lib")
- if (!libsFolder.toFile().exists()) {
- // Plugin for collecting dependencies is executed from parent project,
- // therefore it will run also for parent, that does not have any depedencies(just dep management)
- // so lib folder wont be created
- log.info "Folder ${libsFolder} does not exist - No dependencies to process"
- return
+ String whitelist = project.getProperties().get("yang.modules.whitelist")
+ String yangModules;
+ if (whitelist != null) {
+ log.info "Using whitelist configuration for project ${project.getName()}"
+ def whiteListPath = Paths.get(whitelist)
+ if (!whiteListPath.toFile().exists()) {
+ throw new IllegalStateException(format("Whitelist file on path %s does not exist", whitelist));
+ }
+
+ def reader = new YangModuleWhitelistReader()
+ def yangModuleWhitelist = reader.read(whiteListPath);
+ yangModules = yangModuleWhitelist.getModules().stream()
+ .map { module -> module.getBindingProviderName().trim()}
+ .collect()
+ .join(MODULES_DELIMITER)
+ } else {
+ log.info "Checking module providers for project ${project.getName()}"
+ // checks module provides from dependencies
+ // folder with extracted libs
+ def libsFolder = Paths.get(project.getBuild().getDirectory(), "lib")
+ if (!libsFolder.toFile().exists()) {
+ // Plugin for collecting dependencies is executed from parent project,
+ // therefore it will run also for parent, that does not have any depedencies(just dep management)
+ // so lib folder wont be created
+ log.info "Folder ${libsFolder} does not exist - No dependencies to process"
+ return
+ }
+
+ yangModules = java.nio.file.Files.walk(libsFolder)
+ .map { path -> path.toFile() }
+ .filter { file -> file.isFile() }
+ .filter { file -> file.getName().endsWith(".jar") }
+ .map { file -> getModuleProviderContentFromApiJar(new JarFile(file), log) }
+ .filter { content -> !Strings.isNullOrEmpty(content.trim()) }
+ .collect().join(MODULES_DELIMITER)
}
- String yangModules = java.nio.file.Files.walk(libsFolder)
- .map { path -> path.toFile() }
- .filter { file -> file.isFile() }
- .filter { file -> file.getName().endsWith(".jar") }
- .map { file -> getModuleProviderContentFromApiJar(new JarFile(file), log) }
- .filter { content -> !Strings.isNullOrEmpty(content.trim()) }
- .collect().join(MODULES_DELIMITER)
- log.info "Yang yangModules found : $yangModules"
+ log.info "Yang modules found : $yangModules"
def outputDir = Paths.get(project.getBuild().getOutputDirectory(), YANG_MODULES_FOLDER).toFile()
outputDir.mkdirs()
def outputFile = Paths.get(outputDir.getPath(), YANG_MODULES_FILE_NAME).toFile()
outputFile.createNewFile()
Files.write(yangModules, outputFile, StandardCharsets.UTF_8)
- log.info "Yang yangModules configuration successfully written to ${outputFile.getPath()}"
+ log.info "Yang modules configuration successfully written to ${outputFile.getPath()}"
}
/**
@@ -101,7 +120,6 @@ class ModuleYangIndexGenerator {
log.info "Pairing against dependencies"
// The rest of the modules is looked up in dependencies
pairAgainsDependencyArtifacts(project, modules, log, moduleToYangModulesIndex)
-
// for ex.: /target/honeycomb-minimal-resources/yang-mapping
def yangMappingFolder = Paths.get(project.getBuild().getOutputDirectory(), StartupScriptGenerator.MINIMAL_RESOURCES_FOLDER, YANG_MAPPING_FOLDER).toFile()
diff --git a/infra/northbound/restconf/pom.xml b/infra/northbound/restconf/pom.xml
index 1f3d2db13..49e5a9013 100644
--- a/infra/northbound/restconf/pom.xml
+++ b/infra/northbound/restconf/pom.xml
@@ -34,6 +34,9 @@
<jersey.version>1.19.1</jersey.version>
<servlet.version>3.1.0</servlet.version>
<jetty.version>9.3.11.v20160721</jetty.version>
+ <yang.modules.whitelist>
+ ${project.basedir}/src/main/resources/honeycomb-minimal-resources/config/restconf-whitelist.xml
+ </yang.modules.whitelist>
</properties>
<dependencies>
diff --git a/infra/northbound/restconf/src/main/resources/honeycomb-minimal-resources/config/restconf-whitelist.xml b/infra/northbound/restconf/src/main/resources/honeycomb-minimal-resources/config/restconf-whitelist.xml
new file mode 100644
index 000000000..5274cf4a7
--- /dev/null
+++ b/infra/northbound/restconf/src/main/resources/honeycomb-minimal-resources/config/restconf-whitelist.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<yangModuleWhitelist>
+ <modules>
+ <module>
+ <package>org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715</package>
+ <description>
+ This module contains a collection of generally useful derived
+ YANG data types for Internet addresses and related things.
+
+ Dependency for ietf-restconf-monitoring
+ </description>
+ </module>
+ <module>
+ <package>org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715</package>
+ <description>
+ This module contains a collection of generally useful derived
+ YANG data types.
+
+ Dependency for ietf-restconf-monitoring
+ </description>
+ </module>
+ <module>
+ <package>org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126
+ </package>
+ <description>
+ This module contains monitoring information for the
+ RESTCONF protocol.
+
+ Required for mounting of netconf devices
+ </description>
+ </module>
+ <module>
+ <package>org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621</package>
+ <description>
+ This module contains monitoring information about the YANG
+ modules and submodules that are used within a YANG-based
+ server.
+
+ Required for mounting of netconf devices
+ </description>
+ </module>
+ </modules>
+</yangModuleWhitelist>