Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import java.util.Map;

import org.apache.hadoop.hdds.scm.net.NodeSchema.LayerType;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

import static org.apache.commons.collections.EnumerationUtils.toList;

Expand Down Expand Up @@ -227,7 +229,7 @@ private NodeSchemaLoadResult loadSchemaFromYaml(InputStream schemaFile) {
NodeSchemaLoadResult finalSchema;

try {
Yaml yaml = new Yaml();
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this causes test failures:

 Tests run: 5, Failures: 4, Errors: 0, Skipped: 0, Time elapsed: 0.268 s <<< FAILURE! - in org.apache.hadoop.hdds.scm.net.TestYamlSchemaLoader

https://github.com/rohit-kb/ozone/actions/runs/3882072979/jobs/6621790406#step:6:584

Can you please check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review, looking into it

NodeSchema nodeTree;

nodeTree = yaml.loadAs(schemaFile, NodeSchema.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.representer.Representer;

/**
* Class for creating datanode.id file in yaml format.
Expand All @@ -56,7 +59,7 @@ public static void createDatanodeIdFile(DatanodeDetails datanodeDetails,
DumperOptions options = new DumperOptions();
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
Yaml yaml = new Yaml(options);
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()), new Representer(options), options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java
 62: Line is longer than 80 characters (found 102).

https://github.com/rohit-kb/ozone/actions/runs/3882072979/jobs/6621789972#step:6:427


try (Writer writer = new OutputStreamWriter(
new FileOutputStream(path), StandardCharsets.UTF_8)) {
Expand All @@ -71,7 +74,7 @@ public static DatanodeDetails readDatanodeIdFile(File path)
throws IOException {
DatanodeDetails datanodeDetails;
try (FileInputStream inputFileStream = new FileInputStream(path)) {
Yaml yaml = new Yaml();
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
DatanodeDetailsYaml datanodeDetailsYaml;
try {
datanodeDetailsYaml =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.AbstractConstruct;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.introspector.BeanAccess;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.introspector.PropertyUtils;
Expand Down Expand Up @@ -160,7 +160,7 @@ public static ContainerData readContainer(InputStream input)
KeyValueContainerData.getYamlFields());
representer.setPropertyUtils(propertyUtils);

Constructor containerDataConstructor = new ContainerDataConstructor();
SafeConstructor containerDataConstructor = new ContainerDataConstructor();

Yaml yaml = new Yaml(containerDataConstructor, representer);
yaml.setBeanAccess(BeanAccess.FIELD);
Expand Down Expand Up @@ -200,7 +200,7 @@ public static Yaml getYamlForContainerType(ContainerType containerType,
KeyValueContainerData.class,
KEYVALUE_YAML_TAG);

Constructor keyValueDataConstructor = new ContainerDataConstructor();
SafeConstructor keyValueDataConstructor = new ContainerDataConstructor();

return new Yaml(keyValueDataConstructor, representer);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ protected NodeTuple representJavaBeanProperty(
/**
* Constructor class for KeyValueData, which will be used by Yaml.
*/
private static class ContainerDataConstructor extends Constructor {
private static class ContainerDataConstructor extends SafeConstructor {
ContainerDataConstructor() {
//Adding our own specific constructors for tags.
// When a new Container type is added, we need to add yamlConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

/**
* Test cases for mini ozone cluster.
Expand Down Expand Up @@ -188,7 +190,7 @@ private static void assertWriteRead(DatanodeDetails details)
ContainerUtils.writeDatanodeDetailsTo(details, file);

// Validate using yaml parser
Yaml yaml = new Yaml();
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
try {
yaml.load(new InputStreamReader(new FileInputStream(file),
StandardCharsets.UTF_8));
Expand Down