Search in sources :

Example 16 with Configuration

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);
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 17 with Configuration

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);
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) Test(org.junit.Test)

Example 18 with Configuration

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);
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) Test(org.junit.Test)

Example 19 with Configuration

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());
}
Also used : HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Configuration(org.apache.hadoop.conf.Configuration) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Test(org.junit.Test)

Example 20 with Configuration

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;
}
Also used : SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI)

Aggregations

SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)10 Configuration (org.graylog2.Configuration)10 Test (org.junit.Test)9 Configuration (org.apache.hadoop.conf.Configuration)8 URI (java.net.URI)7 Configuration (org.apache.commons.configuration2.Configuration)5 Before (org.junit.Before)5 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)2 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Role (org.graylog2.shared.users.Role)2 UserService (org.graylog2.shared.users.UserService)2 EventBus (com.google.common.eventbus.EventBus)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1