fix for file not found execption at the graphite extension module (#2917)

This commit is contained in:
Slim 2016-05-04 17:37:10 -05:00 committed by Fangjin Yang
parent f8ddfb9a4b
commit 035134d070
1 changed files with 11 additions and 6 deletions

View File

@ -31,6 +31,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.metamx.common.ISE;
import com.metamx.common.logger.Logger;
@ -38,6 +39,7 @@ import com.metamx.emitter.service.ServiceMetricEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
@ -247,13 +249,16 @@ public class WhiteListBasedConverter implements DruidToGraphiteEventConverter
{
String fileContent;
String actualPath = mapPath;
try {
if (Strings.isNullOrEmpty(mapPath)) {
actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile();
LOGGER.warn("using default whiteList map located at [%s]", actualPath);
LOGGER.info("using default whiteList map located at [%s]", actualPath);
fileContent = CharStreams.toString(new InputStreamReader(this.getClass()
.getClassLoader()
.getResourceAsStream("defaultWhiteListMap.json")));
} else {
fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read();
}
try {
fileContent = Files.asCharSource(new File(actualPath), Charset.forName("UTF-8")).read();
return mapper.reader(new TypeReference<ImmutableSortedMap<String, ImmutableSet<String>>>()
{
}).readValue(fileContent);