use of org.apache.commons.configuration2.Configuration in project hadoop by apache.
the class MetricsConfig method loadFirst.
/**
* Load configuration from a list of files until the first successful load
* @param conf the configuration object
* @param files the list of filenames to try
* @return the configuration object
*/
static MetricsConfig loadFirst(String prefix, String... fileNames) {
for (String fname : fileNames) {
try {
Configuration cf = new Configurations().propertiesBuilder(fname).configure(new Parameters().properties().setFileName(fname).setListDelimiterHandler(new DefaultListDelimiterHandler(','))).getConfiguration().interpolatedConfiguration();
LOG.info("loaded properties from " + fname);
LOG.debug(toString(cf));
MetricsConfig mc = new MetricsConfig(cf, prefix);
LOG.debug(mc);
return mc;
} catch (ConfigurationException e) {
// Commons Configuration defines the message text when file not found
if (e.getMessage().startsWith("Could not locate")) {
continue;
}
throw new MetricsConfigException(e);
}
}
LOG.warn("Cannot locate configuration: tried " + Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
use of org.apache.commons.configuration2.Configuration in project hadoop by apache.
the class TestMetricsConfig method testCommon.
/**
* Common use cases
* @throws Exception
*/
@Test
public void testCommon() throws Exception {
String filename = getTestFilename("test-metrics2");
new ConfigBuilder().add("*.foo", "default foo").add("p1.*.bar", "p1 default bar").add("p1.t1.*.bar", "p1.t1 default bar").add("p1.t1.i1.name", "p1.t1.i1.name").add("p1.t1.42.bar", "p1.t1.42.bar").add("p1.t2.i1.foo", "p1.t2.i1.foo").add("p2.*.foo", "p2 default foo").save(filename);
MetricsConfig mc = MetricsConfig.create("p1", filename);
LOG.debug("mc:" + mc);
Configuration expected = new ConfigBuilder().add("*.bar", "p1 default bar").add("t1.*.bar", "p1.t1 default bar").add("t1.i1.name", "p1.t1.i1.name").add("t1.42.bar", "p1.t1.42.bar").add("t2.i1.foo", "p1.t2.i1.foo").config;
assertEq(expected, mc);
testInstances(mc);
}
use of org.apache.commons.configuration2.Configuration in project hadoop by apache.
the class TestMetricsConfig method testLoadFirst.
/**
* Test the config file load order
* @throws Exception
*/
@Test
public void testLoadFirst() throws Exception {
String filename = getTestFilename("hadoop-metrics2-p1");
new ConfigBuilder().add("p1.foo", "p1foo").save(filename);
MetricsConfig mc = MetricsConfig.create("p1");
MetricsConfig mc2 = MetricsConfig.create("p1", "na1", "na2", filename);
Configuration expected = new ConfigBuilder().add("foo", "p1foo").config;
assertEq(expected, mc);
assertEq(expected, mc2);
}
use of org.apache.commons.configuration2.Configuration in project hadoop by apache.
the class TestDataNodeFSDataSetSink method testFSDataSetMetrics.
@Test
public /**
* This test creates a Source and then calls into the Sink that we
* have registered. That is calls into FSDataSetSinkTest
*/
void testFSDataSetMetrics() throws InterruptedException {
Configuration conf = new HdfsConfiguration();
String bpid = "FSDatSetSink-Test";
SimulatedFSDataset fsdataset = new SimulatedFSDataset(null, conf);
fsdataset.addBlockPool(bpid, conf);
FSDataSetSinkTest sink = new FSDataSetSinkTest();
sink.init(null);
ms.init("Test");
ms.start();
ms.register("FSDataSetSource", "FSDataSetSource", fsdataset);
ms.register("FSDataSetSink", "FSDataSetSink", sink);
ms.startMetricsMBeans();
ms.publishMetricsNow();
Thread.sleep(4000);
ms.stopMetricsMBeans();
ms.shutdown();
// make sure we got all expected metric in the call back
assertEquals(sink.getMapCount(), sink.getFoundKeyCount());
}
use of org.apache.commons.configuration2.Configuration in project hadoop by apache.
the class AzureBlobStorageTestAccount method createForEmulator.
/**
* Creates a test account that goes against the storage emulator.
*
* @return The test account, or null if the emulator isn't setup.
*/
public static AzureBlobStorageTestAccount createForEmulator() throws Exception {
saveMetricsConfigFile();
NativeAzureFileSystem fs = null;
CloudBlobContainer container = null;
Configuration conf = createTestConfiguration();
if (!conf.getBoolean(USE_EMULATOR_PROPERTY_NAME, false)) {
// Not configured to test against the storage emulator.
System.out.println("Skipping emulator Azure test because configuration " + "doesn't indicate that it's running." + " Please see RunningLiveWasbTests.txt for guidance.");
return null;
}
CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount();
fs = new NativeAzureFileSystem();
String containerName = String.format("wasbtests-%s-%tQ", System.getProperty("user.name"), new Date());
container = account.createCloudBlobClient().getContainerReference(containerName);
container.create();
// Set account URI and initialize Azure file system.
URI accountUri = createAccountUri(DEFAULT_STORAGE_EMULATOR_ACCOUNT_NAME, containerName);
configureSecureModeTestSettings(conf);
fs.initialize(accountUri, conf);
// Create test account initializing the appropriate member variables.
//
AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(fs, account, container);
return testAcct;
}
Aggregations