use of org.apache.hadoop.metrics2.MetricsException in project hadoop by apache.
the class AbstractPatternFilter method init.
@Override
public void init(SubsetConfiguration conf) {
String patternString = conf.getString(INCLUDE_KEY);
if (patternString != null && !patternString.isEmpty()) {
setIncludePattern(compile(patternString));
}
patternString = conf.getString(EXCLUDE_KEY);
if (patternString != null && !patternString.isEmpty()) {
setExcludePattern(compile(patternString));
}
String[] patternStrings = conf.getStringArray(INCLUDE_TAGS_KEY);
if (patternStrings != null && patternStrings.length != 0) {
for (String pstr : patternStrings) {
Matcher matcher = tagPattern.matcher(pstr);
if (!matcher.matches()) {
throw new MetricsException("Illegal tag pattern: " + pstr);
}
setIncludeTagPattern(matcher.group(1), compile(matcher.group(2)));
}
}
patternStrings = conf.getStringArray(EXCLUDE_TAGS_KEY);
if (patternStrings != null && patternStrings.length != 0) {
for (String pstr : patternStrings) {
Matcher matcher = tagPattern.matcher(pstr);
if (!matcher.matches()) {
throw new MetricsException("Illegal tag pattern: " + pstr);
}
setExcludeTagPattern(matcher.group(1), compile(matcher.group(2)));
}
}
}
use of org.apache.hadoop.metrics2.MetricsException 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
}
}
}
use of org.apache.hadoop.metrics2.MetricsException in project hadoop by apache.
the class TestRollingFileSystemSinkWithHdfs method testFailedClose.
/**
* Test that closing a file in HDFS fails when HDFS is unavailable.
*
* @throws IOException thrown when reading or writing log files
*/
@Test
public void testFailedClose() throws IOException {
final String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp";
MetricsSystem ms = initMetricsSystem(path, false, false);
new MyMetrics1().registerWith(ms);
// publish the metrics
ms.publishMetricsNow();
shutdownHdfs();
MockSink.errored = false;
try {
ms.stop();
assertTrue("No exception was generated while stopping sink " + "even though HDFS was unavailable", MockSink.errored);
} catch (MetricsException ex) {
// Expected
} finally {
ms.shutdown();
}
}
use of org.apache.hadoop.metrics2.MetricsException in project hbase by apache.
the class DynamicMetricsRegistry method tag.
/**
* Add a tag to the metrics
* @param info metadata of the tag
* @param value of the tag
* @param override existing tag if true
* @return the registry (for keep adding tags etc.)
*/
public DynamicMetricsRegistry tag(MetricsInfo info, String value, boolean override) {
MetricsTag tag = Interns.tag(info, value);
if (!override) {
MetricsTag existing = tagsMap.putIfAbsent(info.name(), tag);
if (existing != null) {
throw new MetricsException("Tag " + info.name() + " already exists!");
}
return this;
}
tagsMap.put(info.name(), tag);
return this;
}
use of org.apache.hadoop.metrics2.MetricsException in project hadoop by apache.
the class RollingFileSystemSink method getRollInterval.
/**
* Extract the roll interval from the configuration and return it in
* milliseconds.
*
* @return the roll interval in millis
*/
@VisibleForTesting
protected long getRollInterval() {
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 "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;
}
Aggregations