Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -30,7 +30,9 @@
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

/**
* Configuration for ozone.
Expand Down Expand Up @@ -161,4 +163,31 @@ public static void activate() {
Configuration.addDefaultResource("ozone-default.xml");
Configuration.addDefaultResource("ozone-site.xml");
}

/**
* The super class method getAllPropertiesByTag
Copy link
Member

Choose a reason for hiding this comment

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

Do we need an other (HADOOP) jira to fix it on the hadoop 3.3 line, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @elek

* does not override values of properties
* if there is no tag present in the configs of
* newly added resources
* @param tag
* @return Properties that belong to the tag
*/
@Override
public Properties getAllPropertiesByTag(String tag) {
// Call getProps first to load the newly added resources
// before calling super.getAllPropertiesByTag
Properties updatedProps = getProps();
Properties propertiesByTag = super.getAllPropertiesByTag(tag);
Properties props = new Properties();
Enumeration properties = propertiesByTag.propertyNames();
while (properties.hasMoreElements()) {
Object propertyName = properties.nextElement();
// get the current value of the property
Object value = updatedProps.getProperty(propertyName.toString());
if (value != null) {
props.put(propertyName, value);
}
}
return props;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.hadoop.hdds.conf;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class TestOzoneConfiguration {

private Configuration conf;
final static String CONFIG = new File("./test-config-TestConfiguration.xml").getAbsolutePath();
final static String CONFIG_CORE = new File("./core-site.xml").getAbsolutePath();

private BufferedWriter out;

@Before
public void setUp() throws Exception {
conf = new OzoneConfiguration();
}

@After
public void tearDown() throws Exception {
if(out != null) {
out.close();
}
new File(CONFIG).delete();
new File(CONFIG_CORE).delete();
}

private void startConfig() throws IOException {
out.write("<?xml version=\"1.0\"?>\n");
out.write("<configuration>\n");
}

private void endConfig() throws IOException{
out.write("</configuration>\n");
out.flush();
out.close();
}

@Test
public void testGetAllPropertiesByTags() throws Exception {

try{
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("hadoop.tags.system", "YARN,HDFS,NAMENODE");
appendProperty("hadoop.tags.custom", "MYCUSTOMTAG");
appendPropertyByTag("dfs.cblock.trace.io", "false", "YARN");
appendPropertyByTag("dfs.replication", "1", "HDFS");
appendPropertyByTag("dfs.namenode.logging.level", "INFO", "NAMENODE");
appendPropertyByTag("dfs.random.key", "XYZ", "MYCUSTOMTAG");
endConfig();

Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
assertEq(conf.getAllPropertiesByTag("MYCUSTOMTAG").getProperty("dfs.random.key"), "XYZ");
} finally {
out.close();
}
try {
out = new BufferedWriter(new FileWriter(CONFIG_CORE));
startConfig();
appendProperty("dfs.random.key", "ABC");
appendProperty("dfs.replication", "3");
appendProperty("dfs.cblock.trace.io", "true");
endConfig();

Path fileResource = new Path(CONFIG_CORE);
conf.addResource(fileResource);

} finally {
out.close();
}

// Test if values are getting overridden even without tags being present
assertEq("3", conf.getAllPropertiesByTag("HDFS").getProperty("dfs.replication"));
assertEq("ABC", conf.getAllPropertiesByTag("MYCUSTOMTAG").getProperty("dfs.random.key"));
assertEq("true", conf.getAllPropertiesByTag("YARN").getProperty("dfs.cblock.trace.io"));
}

private void appendProperty(String name, String val) throws IOException {
this.appendProperty(name, val, false, new String[0]);
}

private void appendProperty(String name, String val, boolean isFinal, String... sources) throws IOException {
this.out.write("<property>");
this.out.write("<name>");
this.out.write(name);
this.out.write("</name>");
this.out.write("<value>");
this.out.write(val);
this.out.write("</value>");
if(isFinal) {
this.out.write("<final>true</final>");
}

String[] var5 = sources;
int var6 = sources.length;

for(int var7 = 0; var7 < var6; ++var7) {
String s = var5[var7];
this.out.write("<source>");
this.out.write(s);
this.out.write("</source>");
}

this.out.write("</property>\n");
}

private void appendPropertyByTag(String name, String val, String tags, String... sources) throws IOException {
this.appendPropertyByTag(name, val, false, tags, sources);
}

private void appendPropertyByTag(String name, String val, boolean isFinal, String tag, String... sources) throws IOException {
this.out.write("<property>");
this.out.write("<name>");
this.out.write(name);
this.out.write("</name>");
this.out.write("<value>");
this.out.write(val);
this.out.write("</value>");
if(isFinal) {
this.out.write("<final>true</final>");
}

String[] var6 = sources;
int var7 = sources.length;

for(int var8 = 0; var8 < var7; ++var8) {
String s = var6[var8];
this.out.write("<source>");
this.out.write(s);
this.out.write("</source>");
}

this.out.write("<tag>");
this.out.write(tag);
this.out.write("</tag>");
this.out.write("</property>\n");
}

private static void assertEq(Object a, Object b) {
System.out.println("assertEq: " + a + ", " + b);
Assert.assertEquals(a, b);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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.
*/

/**
* This package contains the OzoneConfiguration related tests
*/
package org.apache.hadoop.hdds.conf;
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@
ctrl.convertToArray(response.data);
ctrl.configs = Object.values(ctrl.keyTagMap);
ctrl.component = 'All';
console.log("ajay -> " + JSON.stringify(ctrl.configs));
ctrl.sortBy('name');
});
};
Expand All @@ -326,7 +325,6 @@

if (ctrl.component != 'All' && (item['tag'].indexOf(ctrl
.component) < 0)) {
console.log(item['name'] + " false tag " + item['tag']);
return false;
}

Expand Down