|
@@ -25,14 +25,17 @@ import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.FileContext;
|
|
import org.apache.hadoop.fs.FileContext;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.nodelabels.NodeLabelTestBase;
|
|
import org.apache.hadoop.yarn.nodelabels.NodeLabelTestBase;
|
|
import org.junit.After;
|
|
import org.junit.After;
|
|
|
|
+import org.junit.AfterClass;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
|
|
+import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
public class TestConfigurationNodeLabelsProvider extends NodeLabelTestBase {
|
|
public class TestConfigurationNodeLabelsProvider extends NodeLabelTestBase {
|
|
@@ -48,13 +51,17 @@ public class TestConfigurationNodeLabelsProvider extends NodeLabelTestBase {
|
|
|
|
|
|
private ConfigurationNodeLabelsProvider nodeLabelsProvider;
|
|
private ConfigurationNodeLabelsProvider nodeLabelsProvider;
|
|
|
|
|
|
- @Before
|
|
|
|
- public void setup() {
|
|
|
|
|
|
+ @BeforeClass
|
|
|
|
+ public static void create() {
|
|
loader =
|
|
loader =
|
|
new XMLPathClassLoader(
|
|
new XMLPathClassLoader(
|
|
TestConfigurationNodeLabelsProvider.class.getClassLoader());
|
|
TestConfigurationNodeLabelsProvider.class.getClassLoader());
|
|
testRootDir.mkdirs();
|
|
testRootDir.mkdirs();
|
|
|
|
+ Thread.currentThread().setContextClassLoader(loader);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @Before
|
|
|
|
+ public void setup() {
|
|
nodeLabelsProvider = new ConfigurationNodeLabelsProvider();
|
|
nodeLabelsProvider = new ConfigurationNodeLabelsProvider();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -62,44 +69,43 @@ public class TestConfigurationNodeLabelsProvider extends NodeLabelTestBase {
|
|
public void tearDown() throws Exception {
|
|
public void tearDown() throws Exception {
|
|
if (nodeLabelsProvider != null) {
|
|
if (nodeLabelsProvider != null) {
|
|
nodeLabelsProvider.close();
|
|
nodeLabelsProvider.close();
|
|
|
|
+ nodeLabelsProvider.stop();
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @AfterClass
|
|
|
|
+ public static void remove() throws Exception {
|
|
if (testRootDir.exists()) {
|
|
if (testRootDir.exists()) {
|
|
FileContext.getLocalFSFileContext().delete(
|
|
FileContext.getLocalFSFileContext().delete(
|
|
new Path(testRootDir.getAbsolutePath()), true);
|
|
new Path(testRootDir.getAbsolutePath()), true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private Configuration getConfForNodeLabels() {
|
|
|
|
- Configuration conf = new Configuration();
|
|
|
|
- conf.set(YarnConfiguration.NM_PROVIDER_CONFIGURED_NODE_LABELS, "A,B,CX");
|
|
|
|
- return conf;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void testNodeLabelsFromConfig() throws IOException,
|
|
public void testNodeLabelsFromConfig() throws IOException,
|
|
InterruptedException {
|
|
InterruptedException {
|
|
- Configuration conf = getConfForNodeLabels();
|
|
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ modifyConf("A,B,CX");
|
|
nodeLabelsProvider.init(conf);
|
|
nodeLabelsProvider.init(conf);
|
|
// test for ensuring labels are set during initialization of the class
|
|
// test for ensuring labels are set during initialization of the class
|
|
nodeLabelsProvider.start();
|
|
nodeLabelsProvider.start();
|
|
- Thread.sleep(1000l); // sleep so that timer has run once during
|
|
|
|
- // initialization
|
|
|
|
assertNLCollectionEquals(toNodeLabelSet("A", "B", "CX"),
|
|
assertNLCollectionEquals(toNodeLabelSet("A", "B", "CX"),
|
|
nodeLabelsProvider.getNodeLabels());
|
|
nodeLabelsProvider.getNodeLabels());
|
|
|
|
|
|
// test for valid Modification
|
|
// test for valid Modification
|
|
TimerTask timerTask = nodeLabelsProvider.getTimerTask();
|
|
TimerTask timerTask = nodeLabelsProvider.getTimerTask();
|
|
- modifyConfAndCallTimer(timerTask, "X,y,Z");
|
|
|
|
|
|
+ modifyConf("X,y,Z");
|
|
|
|
+ timerTask.run();
|
|
assertNLCollectionEquals(toNodeLabelSet("X", "y", "Z"),
|
|
assertNLCollectionEquals(toNodeLabelSet("X", "y", "Z"),
|
|
nodeLabelsProvider.getNodeLabels());
|
|
nodeLabelsProvider.getNodeLabels());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testConfigForNoTimer() throws Exception {
|
|
public void testConfigForNoTimer() throws Exception {
|
|
- Configuration conf = getConfForNodeLabels();
|
|
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ modifyConf("A,B,CX");
|
|
conf.setLong(YarnConfiguration.NM_NODE_LABELS_PROVIDER_FETCH_INTERVAL_MS,
|
|
conf.setLong(YarnConfiguration.NM_NODE_LABELS_PROVIDER_FETCH_INTERVAL_MS,
|
|
AbstractNodeLabelsProvider.DISABLE_NODE_LABELS_PROVIDER_FETCH_TIMER);
|
|
AbstractNodeLabelsProvider.DISABLE_NODE_LABELS_PROVIDER_FETCH_TIMER);
|
|
-
|
|
|
|
nodeLabelsProvider.init(conf);
|
|
nodeLabelsProvider.init(conf);
|
|
nodeLabelsProvider.start();
|
|
nodeLabelsProvider.start();
|
|
Assert
|
|
Assert
|
|
@@ -112,18 +118,33 @@ public class TestConfigurationNodeLabelsProvider extends NodeLabelTestBase {
|
|
nodeLabelsProvider.getNodeLabels());
|
|
nodeLabelsProvider.getNodeLabels());
|
|
}
|
|
}
|
|
|
|
|
|
- private static void modifyConfAndCallTimer(TimerTask timerTask,
|
|
|
|
- String nodeLabels) throws FileNotFoundException, IOException {
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testConfigTimer() throws Exception {
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ modifyConf("A,B,CX");
|
|
|
|
+ conf.setLong(YarnConfiguration.NM_NODE_LABELS_PROVIDER_FETCH_INTERVAL_MS,
|
|
|
|
+ 1000);
|
|
|
|
+ nodeLabelsProvider.init(conf);
|
|
|
|
+ nodeLabelsProvider.start();
|
|
|
|
+ // Ensure that even though timer is not run, node labels are fetched at
|
|
|
|
+ // least once so
|
|
|
|
+ // that NM registers/updates Labels with RM
|
|
|
|
+ assertNLCollectionEquals(toNodeLabelSet("A", "B", "CX"),
|
|
|
|
+ nodeLabelsProvider.getNodeLabels());
|
|
|
|
+ modifyConf("X,y,Z");
|
|
|
|
+ Thread.sleep(1500);
|
|
|
|
+ assertNLCollectionEquals(toNodeLabelSet("X", "y", "Z"),
|
|
|
|
+ nodeLabelsProvider.getNodeLabels());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void modifyConf(String nodeLabels)
|
|
|
|
+ throws FileNotFoundException, IOException {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
conf.set(YarnConfiguration.NM_PROVIDER_CONFIGURED_NODE_LABELS, nodeLabels);
|
|
conf.set(YarnConfiguration.NM_PROVIDER_CONFIGURED_NODE_LABELS, nodeLabels);
|
|
- conf.writeXml(new FileOutputStream(nodeLabelsConfigFile));
|
|
|
|
- ClassLoader actualLoader = Thread.currentThread().getContextClassLoader();
|
|
|
|
- try {
|
|
|
|
- Thread.currentThread().setContextClassLoader(loader);
|
|
|
|
- timerTask.run();
|
|
|
|
- } finally {
|
|
|
|
- Thread.currentThread().setContextClassLoader(actualLoader);
|
|
|
|
- }
|
|
|
|
|
|
+ FileOutputStream confStream = new FileOutputStream(nodeLabelsConfigFile);
|
|
|
|
+ conf.writeXml(confStream);
|
|
|
|
+ IOUtils.closeQuietly(confStream);
|
|
}
|
|
}
|
|
|
|
|
|
private static class XMLPathClassLoader extends ClassLoader {
|
|
private static class XMLPathClassLoader extends ClassLoader {
|