Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUTCH-3017] Allow fast-urlfilter to load from HDFS/S3 #793

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@
import com.google.common.collect.Multimap;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.nutch.net.URLFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandles;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.zip.GZIPInputStream;

/**
* Filters URLs based on a file of regular expressions using host/domains
Expand Down Expand Up @@ -181,9 +186,23 @@ public String filter(String url) {

public void reloadRules() throws IOException {
String fileRules = conf.get(URLFILTER_FAST_FILE);
try (Reader reader = conf.getConfResourceAsReader(fileRules)) {
reloadRules(reader);

InputStream is;

Path fileRulesPath = new Path(fileRules);
if (fileRulesPath.toUri().getScheme() != null) {
FileSystem fs = fileRulesPath.getFileSystem(conf);
is = fs.open(fileRulesPath);
}
lewismc marked this conversation as resolved.
Show resolved Hide resolved
else {
is = conf.getConfResourceAsInputStream(fileRules);
}

if (fileRules.endsWith(".gz")) {
is = new GZIPInputStream(is);
}

reloadRules(new InputStreamReader(is));
}

private void reloadRules(Reader rules) throws IOException {
Expand Down