Search in sources :

Example 16 with MetricsException

use of org.apache.hadoop.metrics2.MetricsException in project hadoop by apache.

the class TestContainerMetrics method testContainerMetricsFinished.

@Test
public void testContainerMetricsFinished() throws InterruptedException {
    MetricsSystemImpl system = new MetricsSystemImpl();
    system.init("test");
    ApplicationId appId = ApplicationId.newInstance(1234, 3);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 4);
    ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 1);
    ContainerMetrics metrics1 = ContainerMetrics.forContainer(system, containerId1, 1, 0);
    ContainerId containerId2 = ContainerId.newContainerId(appAttemptId, 2);
    ContainerMetrics metrics2 = ContainerMetrics.forContainer(system, containerId2, 1, 0);
    ContainerId containerId3 = ContainerId.newContainerId(appAttemptId, 3);
    ContainerMetrics metrics3 = ContainerMetrics.forContainer(system, containerId3, 1, 0);
    metrics1.finished();
    metrics2.finished();
    system.sampleMetrics();
    system.sampleMetrics();
    Thread.sleep(100);
    // verify metrics1 is unregistered
    assertTrue(metrics1 != ContainerMetrics.forContainer(system, containerId1, 1, 0));
    // verify metrics2 is unregistered
    assertTrue(metrics2 != ContainerMetrics.forContainer(system, containerId2, 1, 0));
    // verify metrics3 is still registered
    assertTrue(metrics3 == ContainerMetrics.forContainer(system, containerId3, 1, 0));
    // YARN-5190: move stop() to the end to verify registering containerId1 and
    // containerId2 won't get MetricsException thrown.
    system.stop();
    system.shutdown();
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) MetricsSystemImpl(org.apache.hadoop.metrics2.impl.MetricsSystemImpl) Test(org.junit.Test)

Example 17 with MetricsException

use of org.apache.hadoop.metrics2.MetricsException in project SSM by Intel-bigdata.

the class NNMetricsAccessEventCollector method getRollInterval.

private static long getRollInterval(SubsetConfiguration properties) {
    String rollInterval = properties.getString(ROLL_INTERVAL_KEY, DEFAULT_ROLL_INTERVAL);
    Pattern pattern = Pattern.compile("^\\s*(\\d+)\\s*([A-Za-z]*)\\s*$");
    Matcher match = pattern.matcher(rollInterval);
    long millis;
    if (match.matches()) {
        String flushUnit = match.group(2);
        int rollIntervalInt;
        try {
            rollIntervalInt = Integer.parseInt(match.group(1));
        } catch (NumberFormatException ex) {
            throw new MetricsException("Unrecognized flush interval: " + rollInterval + ". Must be a number followed by an optional " + "unit. The unit must be one of: minute, hour, day", ex);
        }
        if ("".equals(flushUnit)) {
            millis = TimeUnit.HOURS.toMillis(rollIntervalInt);
        } else {
            switch(flushUnit.toLowerCase()) {
                /*          case "s":
          case "sec":
          case "second":
          case "seconds":
            millis = TimeUnit.SECONDS.toMillis(rollIntervalInt);
            break;*/
                case "m":
                case "min":
                case "minute":
                case "minutes":
                    millis = TimeUnit.MINUTES.toMillis(rollIntervalInt);
                    break;
                case "h":
                case "hr":
                case "hour":
                case "hours":
                    millis = TimeUnit.HOURS.toMillis(rollIntervalInt);
                    break;
                case "d":
                case "day":
                case "days":
                    millis = TimeUnit.DAYS.toMillis(rollIntervalInt);
                    break;
                default:
                    throw new MetricsException("Unrecognized unit for flush interval: " + flushUnit + ". Must be one of: minute, hour, day");
            }
        }
    } else {
        throw new MetricsException("Unrecognized flush interval: " + rollInterval + ". Must be a number followed by an optional unit." + " The unit must be one of: minute, hour, day");
    }
    if (millis < 60000) {
        throw new MetricsException("The flush interval property must be " + "at least 1 minute. Value was " + rollInterval);
    }
    return millis;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Aggregations

MetricsException (org.apache.hadoop.metrics2.MetricsException)16 IOException (java.io.IOException)5 AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)3 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)3 Test (org.junit.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Matcher (com.google.re2j.Matcher)1 Annotation (java.lang.annotation.Annotation)1 URISyntaxException (java.net.URISyntaxException)1 Instant (java.time.Instant)1 LocalDateTime (java.time.LocalDateTime)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Timer (java.util.Timer)1