Search in sources :

Example 1 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class RollingFileSystemSinkTestBase method readLogFile.

/**
   * Read the log files at the target path and return the contents as a single
   * string. This method will assert that the correct number of files is found.
   *
   * @param path the target path
   * @param then when the test method began. Used to find the log directory in
   * the case that the test run crosses the top of the hour.
   * @param count the number of log files to expect
   * @return
   * @throws IOException
   * @throws URISyntaxException
   */
protected String readLogFile(String path, String then, int count) throws IOException, URISyntaxException {
    final String now = DATE_FORMAT.format(new Date()) + "00";
    final String logFile = getLogFilename();
    FileSystem fs = FileSystem.get(new URI(path), new Configuration());
    StringBuilder metrics = new StringBuilder();
    boolean found = false;
    for (FileStatus status : fs.listStatus(new Path(path))) {
        Path logDir = status.getPath();
        // the test started and the current time.  Anything else can be ignored.
        if (now.equals(logDir.getName()) || then.equals(logDir.getName())) {
            readLogData(fs, findMostRecentLogFile(fs, new Path(logDir, logFile)), metrics);
            assertFileCount(fs, logDir, count);
            found = true;
        }
    }
    assertTrue("No valid log directories found", found);
    return metrics.toString();
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) Configuration(org.apache.hadoop.conf.Configuration) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) URI(java.net.URI) Date(java.util.Date)

Example 2 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class TestRollingFileSystemSink method testGetRollInterval.

/**
   * Test whether the roll interval is correctly calculated from the
   * configuration settings.
   */
@Test
public void testGetRollInterval() {
    doTestGetRollInterval(1, new String[] { "m", "min", "minute", "minutes" }, 60 * 1000L);
    doTestGetRollInterval(1, new String[] { "h", "hr", "hour", "hours" }, 60 * 60 * 1000L);
    doTestGetRollInterval(1, new String[] { "d", "day", "days" }, 24 * 60 * 60 * 1000L);
    ConfigBuilder builder = new ConfigBuilder();
    SubsetConfiguration conf = builder.add("sink.roll-interval", "1").subset("sink");
    // We can reuse the same sink evry time because we're setting the same
    // property every time.
    RollingFileSystemSink sink = new RollingFileSystemSink();
    sink.init(conf);
    assertEquals(3600000L, sink.getRollInterval());
    for (char c : "abcefgijklnopqrtuvwxyz".toCharArray()) {
        builder = new ConfigBuilder();
        conf = builder.add("sink.roll-interval", "90 " + c).subset("sink");
        try {
            sink.init(conf);
            sink.getRollInterval();
            fail("Allowed flush interval with bad units: " + c);
        } catch (MetricsException ex) {
        // Expected
        }
    }
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) MetricsException(org.apache.hadoop.metrics2.MetricsException) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 3 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class TestMetricsConfig method testInstances.

private void testInstances(MetricsConfig c) throws Exception {
    Map<String, MetricsConfig> map = c.getInstanceConfigs("t1");
    Map<String, MetricsConfig> map2 = c.getInstanceConfigs("t2");
    assertEquals("number of t1 instances", 2, map.size());
    assertEquals("number of t2 instances", 1, map2.size());
    assertTrue("contains t1 instance i1", map.containsKey("i1"));
    assertTrue("contains t1 instance 42", map.containsKey("42"));
    assertTrue("contains t2 instance i1", map2.containsKey("i1"));
    MetricsConfig t1i1 = map.get("i1");
    MetricsConfig t1i42 = map.get("42");
    MetricsConfig t2i1 = map2.get("i1");
    LOG.debug("--- t1 instance i1:" + t1i1);
    LOG.debug("--- t1 instance 42:" + t1i42);
    LOG.debug("--- t2 instance i1:" + t2i1);
    Configuration t1expected1 = new ConfigBuilder().add("name", "p1.t1.i1.name").config;
    Configuration t1expected42 = new ConfigBuilder().add("bar", "p1.t1.42.bar").config;
    Configuration t2expected1 = new ConfigBuilder().add("foo", "p1.t2.i1.foo").config;
    assertEq(t1expected1, t1i1);
    assertEq(t1expected42, t1i42);
    assertEq(t2expected1, t2i1);
    LOG.debug("asserting foo == default foo");
    // Check default lookups
    assertEquals("value of foo in t1 instance i1", "default foo", t1i1.getString("foo"));
    assertEquals("value of bar in t1 instance i1", "p1.t1 default bar", t1i1.getString("bar"));
    assertEquals("value of foo in t1 instance 42", "default foo", t1i42.getString("foo"));
    assertEquals("value of foo in t2 instance i1", "p1.t2.i1.foo", t2i1.getString("foo"));
    assertEquals("value of bar in t2 instance i1", "p1 default bar", t2i1.getString("bar"));
}
Also used : Configuration(org.apache.commons.configuration2.Configuration)

Example 4 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class ConfigUtil method dump.

static void dump(String header, Configuration c, PrintWriter out) {
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.copy(c);
    if (header != null) {
        out.println(header);
    }
    try {
        p.write(out);
    } catch (Exception e) {
        throw new RuntimeException("Error saving config", e);
    }
}
Also used : PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 5 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class AzureBlobStorageTestAccount method createRoot.

public static AzureBlobStorageTestAccount createRoot(final String blobName, final int fileSize) throws Exception {
    NativeAzureFileSystem fs = null;
    CloudBlobContainer container = null;
    Configuration conf = createTestConfiguration();
    // Set up a session with the cloud blob client to generate SAS and check the
    // existence of a container and capture the container object.
    CloudStorageAccount account = createTestAccount(conf);
    if (account == null) {
        return null;
    }
    CloudBlobClient blobClient = account.createCloudBlobClient();
    // Capture the account URL and the account name.
    String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME);
    configureSecureModeTestSettings(conf);
    // Set up public container with the specified blob name.
    CloudBlockBlob blobRoot = primeRootContainer(blobClient, accountName, blobName, fileSize);
    // Capture the blob container object. It should exist after generating the
    // shared access signature.
    container = blobClient.getContainerReference(AZURE_ROOT_CONTAINER);
    if (null == container || !container.exists()) {
        final String errMsg = String.format("Container '%s' expected but not found while creating SAS account.");
        throw new Exception(errMsg);
    }
    // Set the account URI without a container name.
    URI accountUri = createAccountUri(accountName);
    // Initialize the Native Azure file system with anonymous credentials.
    fs = new NativeAzureFileSystem();
    fs.initialize(accountUri, conf);
    // Create test account initializing the appropriate member variables.
    // Set the container value to null for the default root container.
    //
    AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(fs, account, blobRoot);
    // Return to caller with test account.
    return testAcct;
}
Also used : SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

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