Log enhancements and cosmetic clean up
Change-Id: I2057eca256928c5ae554d2813047ad040d3ea116
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java
index 8930e28..b3f0e2b 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java
@@ -18,12 +18,14 @@
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.slf4j.Logger;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.findReferredNode;
+import static org.slf4j.LoggerFactory.getLogger;
/*
* Reference:RFC 6020.
@@ -74,6 +76,8 @@
private static final long serialVersionUID = 806201642L;
+ private static final Logger log = getLogger(YangImport.class);
+
/**
* Name of the module that is being imported.
*/
@@ -228,6 +232,7 @@
*/
if (importedModuleRevision != null) {
String importedModuleNameWithRevision = importedModuleName + "@" + importedModuleRevision;
+ log.trace("find {} in {}", importedModuleNameWithRevision, yangNodeSet);
moduleNode = findReferredNode(yangNodeSet, importedModuleNameWithRevision);
}
@@ -236,6 +241,7 @@
* revision if can't find with revision.
*/
if (moduleNode == null) {
+ log.trace("find {} in {}", importedModuleName, yangNodeSet);
moduleNode = findReferredNode(yangNodeSet, importedModuleName);
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
index 1347e76..8dd7821 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
@@ -890,6 +890,7 @@
*
* @return YANG schema node context info map
*/
+ @Override
public Map<YangSchemaNodeIdentifier,
YangSchemaNodeContextInfo> getYsnContextInfoMap() {
return ysnContextInfoMap;
@@ -1159,4 +1160,9 @@
throw new IllegalArgumentException("Schema can only be added for " +
"Anydata.");
}
+
+ @Override
+ public String toString() {
+ return yangSchemaNodeIdentifier.toString();
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
index 3867470..d09b6a3 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
@@ -18,8 +18,11 @@
import org.onosproject.yang.model.YangNamespace;
+import com.google.common.base.MoreObjects;
+
import java.io.Serializable;
import java.util.Objects;
+import java.util.Optional;
/**
* Represents YANG data node identifier which is a combination of name and namespace.
@@ -117,6 +120,20 @@
@Override
public int hashCode() {
- return 0;
+ // if one of moduleName or moduleNamespace is null,
+ // it is not used for comparison, even if the other one is non-null
+ return Objects.hash(name);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .omitNullValues()
+ .add("name", name)
+ .add("moduleName",
+ Optional.ofNullable(namespace).map(YangNamespace::getModuleName).orElse(null))
+ .add("moduleNamespace",
+ Optional.ofNullable(namespace).map(YangNamespace::getModuleNamespace).orElse(null))
+ .toString();
}
}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/DefaultYangCompilationParam.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/DefaultYangCompilationParam.java
index 7383e78..e392940 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/DefaultYangCompilationParam.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/DefaultYangCompilationParam.java
@@ -17,6 +17,7 @@
package org.onosproject.yang.compiler.tool;
import org.onosproject.yang.compiler.api.YangCompilationParam;
+import org.slf4j.Logger;
import java.nio.file.Path;
import java.util.LinkedHashSet;
@@ -25,12 +26,15 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Collections.unmodifiableSet;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Represents default YANG compilation parameter.
*/
public final class DefaultYangCompilationParam implements YangCompilationParam {
+ private static final Logger log = getLogger(DefaultYangCompilationParam.class);
+
private final Set<Path> yangFiles;
private final Set<Path> dependentSchemas;
private Path codeGenDir;
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
index 0e7faaf..8790df0 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
@@ -59,6 +59,7 @@
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import java.util.stream.Collectors;
import static java.nio.file.Files.copy;
import static java.nio.file.Paths.get;
@@ -167,7 +168,16 @@
processSerialization(resourceGenDir, param.getModelId());
// Resolve dependencies using linker.
- resolveDependenciesUsingLinker();
+ try {
+ resolveDependenciesUsingLinker();
+ } catch (Exception e) {
+ log.error("DependentSchemas: {}",
+ dependentSchema(param.getDependentSchemas())
+ .stream()
+ .map(YangNode::getName)
+ .collect(Collectors.toList()), e);
+ throw e;
+ }
// Perform translation to JAVA.
translateToJava(config);
@@ -221,9 +231,15 @@
private Set<YangNode> dependentSchema(Set<Path> dependentSchemaPath) {
Set<YangNode> depNodes = new LinkedHashSet<>();
for (Path path : dependentSchemaPath) {
+ log.trace("from file:{}", path.getParent());
try {
- depNodes.addAll(getYangNodes(
- deSerializeDataModel(path.toString())));
+ Set<YangNode> yangNodes = getYangNodes(deSerializeDataModel(path.toString()));
+ if (log.isTraceEnabled()) {
+ log.trace(" got: {}", yangNodes.stream()
+ .map(YangNode::getName)
+ .collect(Collectors.toList()));
+ }
+ depNodes.addAll(yangNodes);
} catch (IOException e) {
throw new YangCompilerException(
"Failed to fetch dependent schema from given " +
@@ -265,6 +281,7 @@
} catch (LinkerException e) {
printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
e.getMessage(), e.getLocalizedMessage());
+ log.error("Linking failed", e);
throw new YangCompilerException(e.getMessage(), e);
}
}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java
index 6b169fb..fea06ec 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java
@@ -20,6 +20,8 @@
import java.util.Objects;
import org.onosproject.yang.compiler.datamodel.YangNode;
+import com.google.common.base.MoreObjects;
+
/**
* Represents YANG file information.
*/
@@ -134,4 +136,12 @@
public int hashCode() {
return Objects.hashCode(yangFileName);
}
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("yangFileName", yangFileName)
+ .add("isInterJar", isInterJar)
+ .toString();
+ }
}
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
index 30f9bd0..31f0347 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
@@ -21,20 +21,22 @@
import org.onosproject.yang.compiler.api.YangCompilerService;
import org.onosproject.yang.compiler.tool.DefaultYangCompilationParam;
import org.onosproject.yang.compiler.tool.YangCompilerManager;
+import org.slf4j.Logger;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
-
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.parseDepSchemaPath;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_RESOURCES;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Generates Java sources from a Yang model.
*/
public class YangGenerator {
+ private static final Logger log = getLogger(YangGenerator.class);
private final List<File> models;
private final List<String> depJar;
@@ -64,6 +66,7 @@
*/
public void execute() throws YangParsingException {
synchronized (YangGenerator.class) {
+ log.info("modelId: {}", modelId);
//Yang compiler service.
YangCompilerService compiler = new YangCompilerManager();
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibrary.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibrary.java
index 36e917c..abeb582 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibrary.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibrary.java
@@ -73,8 +73,10 @@
@AddToRuleKey
private final String ruleVersion = pluginJarHash;
+ // src path to yang files
@AddToRuleKey
private final ImmutableSortedSet<SourcePath> srcs;
+
private final BuildRuleParams params;
private final Path genSrcsDirectory;
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java
index a048694..fe9b3d8 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangLibraryDescription.java
@@ -125,8 +125,10 @@
.add(yangLib)
// .addAll(deps)
//FIXME remove when we figure out compile time deps
- .addAll((args.deps.or(ImmutableSortedSet.<BuildTarget>of())).
- stream().map(resolver::getRule).collect(Collectors.toList()))
+ .addAll((args.deps.or(ImmutableSortedSet.<BuildTarget>of()))
+ .stream()
+ .map(resolver::getRule)
+ .collect(Collectors.toList()))
// .addAll(BuildRules.getExportedRules(deps))
.addAll(pathResolver.filterBuildRuleInputs(javacOptions.getInputs(pathResolver)))
.build()),
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangStep.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangStep.java
index 1a3bb7b..6c9874d 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangStep.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangStep.java
@@ -30,6 +30,8 @@
import java.util.List;
import java.util.stream.Collectors;
+import org.slf4j.Logger;
+
import static org.onosproject.yang.compiler.utils.UtilConstants.COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAR;
import static org.onosproject.yang.compiler.utils.UtilConstants.LIB;
@@ -37,15 +39,18 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.OUT;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Buck build step to trigger Yang Java source file generation.
*/
public class YangStep extends AbstractExecutionStep {
+ private static final Logger log = getLogger(YangStep.class);
private static final String DESCRIPTION = "yang-compile";
private final ImmutableSortedSet<BuildRule> deps;
private final ProjectFilesystem filesystem;
+ // .yang models
private final List<Path> srcs;
private final Path output;
private final String modelId;
@@ -66,6 +71,7 @@
throws IOException, InterruptedException {
synchronized (YangStep.class) {
+ log.debug("Step: {} {}", this.getShortName(), this.modelId);
List<File> sourceFiles = srcs.stream().map(Path::toFile)
.collect(Collectors.toList());
try {
@@ -87,6 +93,7 @@
if (deps != null) {
for (BuildRule rule : deps) {
String name = rule.getBuildTarget().getFullyQualifiedName();
+ log.debug("Processing dep name {}", name);
if (!name.contains(LIB_PATH)) {
builder = new StringBuilder();
if (name.contains(COLON)) {
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeHelper.java
index b7294c9..d8bf4f0 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/RuntimeHelper.java
@@ -32,6 +32,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.getDateInStringFormat;
import static org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil.translate;
import static org.onosproject.yang.runtime.helperutils.YangApacheUtils.getYangModel;
@@ -86,11 +87,13 @@
if (date != null) {
revName = name + "@" + date;
}
- node = (YangNode) yangSchemaStore.get(name).get(revName);
+ ConcurrentMap<String, YangSchemaNode> ss = yangSchemaStore.get(name);
+ checkNotNull(ss, "schema %s not found", name);
+ node = (YangNode) ss.get(revName);
} else {
- selfNodes.add((YangNode) node);
+ selfNodes.add(node);
}
- nodes.add((YangNode) node);
+ nodes.add(node);
}
//Target linking.
addLinkerAndJavaInfo(nodes);
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistry.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistry.java
index a586167..09cc1e0 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistry.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistry.java
@@ -61,7 +61,6 @@
import static org.onosproject.yang.runtime.RuntimeHelper.getSelfNodes;
import static org.onosproject.yang.runtime.RuntimeHelper.getServiceName;
import static org.onosproject.yang.runtime.impl.UtilsConstants.AT;
-import static org.onosproject.yang.runtime.impl.UtilsConstants.E_MEXIST;
import static org.onosproject.yang.runtime.impl.UtilsConstants.E_NEXIST;
import static org.onosproject.yang.runtime.impl.UtilsConstants.E_NOT_VAL;
import static org.onosproject.yang.runtime.impl.UtilsConstants.E_NULL;
@@ -151,11 +150,11 @@
if (!modelIdStore.containsKey(id)) {
updateRegClassStore(param);
modelIdStore.put(id, model);
- } else if ((info != null) && (!registerClassStore
- .containsValue(info.getModuleClass()))) {
+ } else if ((info != null) &&
+ (!registerClassStore.containsValue(info.getModuleClass()))) {
updateRegClassStore(param);
} else {
- throw new IllegalArgumentException(E_MEXIST);
+ throw new IllegalArgumentException("ModelId " + id + " already exist");
}
//Register all the YANG nodes, excluding nodes from dependent jar.
@@ -167,6 +166,7 @@
//update child context
updateChildContext(curNodes);
+ log.info("ModelId: {} registered!", id);
}
@Override
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/UtilsConstants.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/UtilsConstants.java
index 13a67b2..98a5931 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/UtilsConstants.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/UtilsConstants.java
@@ -20,8 +20,6 @@
static final String AT = "@";
static final String E_NEXIST = "node with {} namespace not found.";
- static final String E_MEXIST =
- "Model with given modelId already exist";
static final String E_NULL = "Model must not be null";
static final String E_NOT_VAL = "Model id is invalid";
static final String REV_REGEX =
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
index 786e911..59a3e93 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative2Test.java
@@ -57,8 +57,8 @@
addToResourceId(rIdBlr, "l1", LNS, valueSet);
} catch (IllegalArgumentException e) {
isExpOccurred = true;
- assertEquals(e.getMessage(), E_TOO_MANY);
+ assertEquals(E_TOO_MANY, e.getMessage());
}
- assertEquals(isExpOccurred, true);
+ assertEquals(true, isExpOccurred);
}
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
index 7e69df1..81593f3 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/ResourceIdNegative3Test.java
@@ -55,8 +55,8 @@
addToResourceId(rIdBlr, "l1", LNS, valueSet);
} catch (IllegalArgumentException e) {
isExpOccurred = true;
- assertEquals(e.getMessage(), E_TOO_FEW);
+ assertEquals(E_TOO_FEW, e.getMessage());
}
- assertEquals(isExpOccurred, true);
+ assertEquals(true, isExpOccurred);
}
}