Skip to content
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 @@ -248,6 +248,7 @@ public void declareOutputFields(OutputFieldsDeclarer declarer) {

@Override
public void cleanup() {
super.cleanup();
if (parseFilters != null) {
parseFilters.cleanup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ public void declareOutputFields(OutputFieldsDeclarer declarer) {

@Override
public void cleanup() {
super.cleanup();
protocolFactory.cleanup();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ protected List<Outlink> toOutlinks(

@Override
public void cleanup() {
super.cleanup();
if (parseFilters != null) {
parseFilters.cleanup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public void declareOutputFields(OutputFieldsDeclarer declarer) {

@Override
public void cleanup() {
super.cleanup();
protocolFactory.cleanup();
if (fetchExecutor != null) {
fetchExecutor.shutdownNow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ private boolean sniff(byte[] content) {

@Override
public void cleanup() {
super.cleanup();
if (parseFilters != null) {
parseFilters.cleanup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ protected Outlink filterOutlink(
protected boolean allowRedirs() {
return allowRedirs;
}

@Override
public void cleanup() {
if (urlFilters != null) {
urlFilters.cleanup();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,11 @@ public void prepare(
urlFilters = URLFilters.fromConf(stormConf);
}
}

@Override
public void cleanup() {
if (urlFilters != null) {
urlFilters.cleanup();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.stormcrawler.filtering;

import java.net.URL;
import org.apache.storm.task.IBolt;
import org.apache.stormcrawler.Metadata;
import org.apache.stormcrawler.util.AbstractConfigurable;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -46,4 +47,12 @@ public abstract String filter(
@Nullable URL sourceUrl,
@Nullable Metadata sourceMetadata,
@NotNull String urlToFilter);

/**
* Might be used to clean any resources associated with this {@link URLFilter}. See {@link
* IBolt#cleanup()} for more details.
*/
public void cleanup() {
// nothing to do here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ public void configure(@NotNull Map<String, Object> stormConf, @NotNull JsonNode
filters = list.toArray(new URLFilter[0]);
}

@Override
public void cleanup() {
for (URLFilter filter : filters) {
filter.cleanup();
}
}

/** Utility to check the filtering of a URL. */
public static void main(String[] args) throws ParseException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.Timer;
Expand Down Expand Up @@ -71,6 +72,8 @@ public class JSONURLFilterWrapper extends URLFilter {
private static final Logger LOG = LoggerFactory.getLogger(JSONURLFilterWrapper.class);

private URLFilter delegatedURLFilter;
private Timer refreshTimer;
private RestHighLevelClient osClient;

public void configure(@NotNull Map<String, Object> stormConf, @NotNull JsonNode filterParams) {

Expand Down Expand Up @@ -127,42 +130,35 @@ public void configure(@NotNull Map<String, Object> stormConf, @NotNull JsonNode

final JSONResource resource = (JSONResource) delegatedURLFilter;

new Timer()
.schedule(
new TimerTask() {
private RestHighLevelClient osClient;

public void run() {
if (osClient == null) {
try {
osClient =
OpenSearchConnection.getClient(stormConf, "config");
} catch (Exception e) {
LOG.error(
"Exception while creating OpenSearch connection",
e);
}
}
if (osClient != null) {
LOG.info("Reloading json resources from OpenSearch");
try {
GetResponse response =
osClient.get(
new GetRequest(
"config",
resource.getResourceFile()),
RequestOptions.DEFAULT);
resource.loadJSONResources(
new ByteArrayInputStream(
response.getSourceAsBytes()));
} catch (Exception e) {
LOG.error("Can't load config from OpenSearch", e);
}
}
refreshTimer = new Timer();
refreshTimer.schedule(
new TimerTask() {
public void run() {
if (osClient == null) {
try {
osClient = OpenSearchConnection.getClient(stormConf, "config");
} catch (Exception e) {
LOG.error("Exception while creating OpenSearch connection", e);
}
},
0,
refreshRate * 1000);
}
if (osClient != null) {
LOG.info("Reloading json resources from OpenSearch");
try {
GetResponse response =
osClient.get(
new GetRequest(
"config", resource.getResourceFile()),
RequestOptions.DEFAULT);
resource.loadJSONResources(
new ByteArrayInputStream(response.getSourceAsBytes()));
} catch (Exception e) {
LOG.error("Can't load config from OpenSearch", e);
}
}
}
},
0,
refreshRate * 1000);
}

@Override
Expand All @@ -172,4 +168,18 @@ public void run() {
@NotNull String urlToFilter) {
return delegatedURLFilter.filter(sourceUrl, sourceMetadata, urlToFilter);
}

@Override
public void cleanup() {
if (refreshTimer != null) {
refreshTimer.cancel();
}
if (osClient != null) {
try {
osClient.close();
} catch (IOException e) {
LOG.error("Exception when closing OpenSearch client", e);
}
}
}
}