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

Allow JavaDNS to be disabled as part of resolving outstanding build and test issues #190

Merged
merged 11 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
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 @@ -47,14 +47,14 @@ protected void verify() throws Exception {
protected void verifyWarcStats() {
StatisticsTracker stats = heritrix.getEngine().getJob("selftest-job").getCrawlController().getStatisticsTracker();
assertNotNull(stats);
assertEquals(14, (long) stats.getCrawledBytes().get(CrawledBytesHistotable.WARC_NOVEL_URLS));
assertEquals(13, (long) stats.getCrawledBytes().get(CrawledBytesHistotable.WARC_NOVEL_URLS));
assertEquals(12669, (long) stats.getCrawledBytes().get(CrawledBytesHistotable.WARC_NOVEL_CONTENT_BYTES) - stats.getBytesPerHost("dns:"));

assertEquals(3, (long) stats.getServerCache().getHostFor("127.0.0.1").getSubstats().get(CrawledBytesHistotable.WARC_NOVEL_URLS));
assertEquals(2942, (long) stats.getServerCache().getHostFor("127.0.0.1").getSubstats().get(CrawledBytesHistotable.WARC_NOVEL_CONTENT_BYTES));
assertEquals(10, (long) stats.getServerCache().getHostFor("localhost").getSubstats().get(CrawledBytesHistotable.WARC_NOVEL_URLS));
assertEquals(9727, (long) stats.getServerCache().getHostFor("localhost").getSubstats().get(CrawledBytesHistotable.WARC_NOVEL_CONTENT_BYTES));
assertEquals(1, (long) stats.getServerCache().getHostFor("dns:").getSubstats().get(CrawledBytesHistotable.WARC_NOVEL_URLS));
assertEquals(0, (long) stats.getServerCache().getHostFor("dns:").getSubstats().get(CrawledBytesHistotable.WARC_NOVEL_URLS));
}

protected void verifySourceStats() throws Exception {
Expand All @@ -77,7 +77,7 @@ protected void verifySourceStats() throws Exception {
assertEquals(9727l, (long) sourceStats.get("novel") - stats.getBytesPerHost("dns:"));
assertEquals(11l, (long) sourceStats.get("novelCount"));
assertEquals(9727l, (long) sourceStats.get("warcNovelContentBytes") - stats.getBytesPerHost("dns:"));
assertEquals(11l, (long) sourceStats.get("warcNovelUrls"));
assertEquals(10l, (long) sourceStats.get("warcNovelUrls"));
}

}
4 changes: 3 additions & 1 deletion engine/testdata/selftest/conf/selftest-crawler-beans.cxml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ crawlController.pauseAtStart=false
</bean>
<bean id="preconditionEnforcer" class="org.archive.crawler.prefetch.PreconditionEnforcer">
</bean>
<bean id="fetchDns" class="org.archive.modules.fetcher.FetchDNS">
<bean id="fetchDns" class="org.archive.modules.fetcher.FetchDNS">
<!-- This setting is not recommended for production crawling -->
<property name="disableJavaDnsResolves" value="true"/>
</bean>
<bean id="fetchHttp" class="org.archive.modules.fetcher.FetchHTTP">
</bean>
Expand Down
42 changes: 33 additions & 9 deletions modules/src/main/java/org/archive/modules/fetcher/FetchDNS.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,35 @@ public class FetchDNS extends Processor {
protected InetAddress serverInetAddr = null;

/**
* If a DNS lookup fails, whether or not to fallback to InetAddress
* If a DNS lookup fails, whether or not to fall back to InetAddress
* resolution, which may use local 'hosts' files or other mechanisms.
*/
protected boolean acceptNonDnsResolves = false;
{
setAcceptNonDnsResolves(false);
}
public boolean getAcceptNonDnsResolves() {
return acceptNonDnsResolves;
return (Boolean) kp.get("acceptNonDnsResolves");
}
public void setAcceptNonDnsResolves(boolean acceptNonDnsResolves) {
this.acceptNonDnsResolves = acceptNonDnsResolves;
kp.put("acceptNonDnsResolves",acceptNonDnsResolves);
}

/**
* Optionally, only allow InetAddress resolution, precisely because it
* may use local 'hosts' files or other mechanisms.
*
* This should not generally be used in production as it will prevent
* DNS lookups from being recorded properly.
*
*/
{
setDisableJavaDnsResolves(false);
}
public boolean getDisableJavaDnsResolves() {
return (Boolean) kp.get("disableJavaDnsResolves");
}
public void setDisableJavaDnsResolves(boolean disableJavaDnsResolves) {
kp.put("disableJavaDnsResolves",disableJavaDnsResolves);
}

/**
Expand Down Expand Up @@ -158,10 +178,13 @@ protected void innerProcess(CrawlURI curi) {
// Try to get the records for this host (assume domain name)
// TODO: Bug #935119 concerns potential hang here
String lookupName = dnsName.endsWith(".") ? dnsName : dnsName + ".";
try {
rrecordSet = (new Lookup(lookupName, TypeType, ClassType)).run();
} catch (TextParseException e) {
rrecordSet = null;
// If we have not disabled JavaDNS, use that:
if (!getDisableJavaDnsResolves()) {
try {
rrecordSet = (new Lookup(lookupName, TypeType, ClassType)).run();
} catch (TextParseException e) {
rrecordSet = null;
}
}
curi.setContentType("text/dns");
if (rrecordSet != null) {
Expand All @@ -173,7 +196,7 @@ protected void innerProcess(CrawlURI curi) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Failed find of recordset for " + lookupName);
}
if (getAcceptNonDnsResolves()||"localhost".equals(dnsName)) {
if (getAcceptNonDnsResolves()||getDisableJavaDnsResolves()||"localhost".equals(dnsName)) {
// Do lookup that bypasses javadns.
InetAddress address = null;
try {
Expand All @@ -184,6 +207,7 @@ protected void innerProcess(CrawlURI curi) {
if (address != null) {
targetHost.setIP(address, DEFAULT_TTL_FOR_NON_DNS_RESOLVES);
curi.setFetchStatus(S_GETBYNAME_SUCCESS);
curi.setContentSize(0);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Found address for " + dnsName +
" using native dns.");
Expand Down
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,19 @@ http://maven.apache.org/guides/mini/guide-m1-m2.html
<encoding>UTF-8</encoding>
</configuration>
</plugin>

</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<argLine>-Xmx1g</argLine>
<systemPropertyVariables>
<testtmpdir>${project.build.directory}/heritrix-junit-tests</testtmpdir>
<heritrix.hostname>localhost</heritrix.hostname>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down