You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/06/14 16:26:02 UTC
[trafficcontrol] branch master updated (e04a9ca -> 03e3b52)
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git.
from e04a9ca Add Go DS API query parameter alias for xml_id -> xmlId
new d8c2d20 updated to improve the logging to understand the real URL being watched
new 1c10d21 modified to check null in the event the HTTP Connection is down
new d4754bf added a try catch to 'disconnect' the HTTP session to prevent too many file handles are open. See issue: #2223
new b186abd updated to solve the PMD error
new 5429079 updated the TrafficMonitor watcher to close and refresh the connection when TrafficMonitor is down
new dce4153 added null check to prevent NPE
new 03e3b52 Removed static on AsyncHttpClient to allow prevent leak warnings in Tomcat
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../core/util/AbstractResourceWatcher.java | 7 +-
.../traffic_router/core/util/Fetcher.java | 119 ++++++++++++---------
.../core/util/PeriodicResourceUpdater.java | 24 +++--
.../traffic_router/core/util/ProtectedFetcher.java | 3 +-
4 files changed, 90 insertions(+), 63 deletions(-)
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 05/07: updated the TrafficMonitor watcher to close
and refresh the connection when TrafficMonitor is down
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 5429079cbe0333eb317f71081f89a6ceb5c21940
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Fri May 25 12:02:06 2018 -0600
updated the TrafficMonitor watcher to close and refresh the connection when TrafficMonitor is down
---
.../core/util/PeriodicResourceUpdater.java | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java
index 3072b65..7165f9f 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java
@@ -52,11 +52,7 @@ import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
public class PeriodicResourceUpdater {
private static final Logger LOGGER = Logger.getLogger(PeriodicResourceUpdater.class);
- private static final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(
- new AsyncHttpClientConfig.Builder()
- .setConnectionTimeoutInMs(10000)
- .build());
-
+ private static AsyncHttpClient asyncHttpClient;
protected String databaseLocation;
protected final ResourceUrl urls;
protected ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
@@ -105,6 +101,7 @@ public class PeriodicResourceUpdater {
final private boolean pauseTilLoaded;
public void init() {
+ asyncHttpClient = newAsyncClient();
putCurrent();
LOGGER.info("Starting schedule with interval: "+getPollingInterval() + " : "+TimeUnit.MILLISECONDS);
scheduledService = executorService.scheduleWithFixedDelay(updater, 0, getPollingInterval(), TimeUnit.MILLISECONDS);
@@ -121,6 +118,13 @@ public class PeriodicResourceUpdater {
}
}
+ private AsyncHttpClient newAsyncClient() {
+ return new AsyncHttpClient(
+ new AsyncHttpClientConfig.Builder()
+ .setConnectionTimeoutInMs(10000)
+ .build());
+ }
+
private synchronized void putCurrent() {
final File existingDB = new File(databaseLocation);
if(existingDB.exists()) {
@@ -284,6 +288,12 @@ public class PeriodicResourceUpdater {
@Override
public void onThrowable(final Throwable t){
LOGGER.warn("Failed request " + request.getUrl() + ": " + t, t);
+ if (asyncHttpClient!=null) {
+ while (!asyncHttpClient.isClosed()) {
+ asyncHttpClient.close();
+ }
+ }
+ asyncHttpClient = newAsyncClient();
}
};
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 04/07: updated to solve the PMD error
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit b186abd3d5d1316f4a8b2a2ea4531b0304119f3e
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed May 23 14:44:59 2018 -0600
updated to solve the PMD error
---
.../traffic_control/traffic_router/core/util/ProtectedFetcher.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
index ce019cd..0edb429 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
@@ -40,10 +40,8 @@ public class ProtectedFetcher extends Fetcher {
}
private HttpURLConnection extractCookie(final HttpURLConnection http) throws IOException {
- if (http != null) {
- if (http.getHeaderField("Set-Cookie") != null) {
- setCookie(HttpCookie.parse(http.getHeaderField("Set-Cookie")).get(0));
- }
+ if ((http != null) && (http.getHeaderField("Set-Cookie") != null)) {
+ setCookie(HttpCookie.parse(http.getHeaderField("Set-Cookie")).get(0));
}
return http;
}
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 03/07: added a try catch to 'disconnect' the HTTP
session to prevent too many file handles are open. See issue: #2223
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit d4754bfcfa705f75ba081ec89584f96fe6f4ec56
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu May 17 14:27:11 2018 -0600
added a try catch to 'disconnect' the HTTP session to prevent too many file handles are open. See issue: #2223
---
.../traffic_router/core/util/Fetcher.java | 119 ++++++++++++---------
1 file changed, 66 insertions(+), 53 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
index 772c00c..8c62cce 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
@@ -72,53 +72,60 @@ public class Fetcher {
}
protected HttpURLConnection getConnection(final String url, final String data, final String requestMethod, final long lastFetchTime) throws IOException {
- String method = GET_STR;
+ HttpURLConnection http = null;
+ try {
+ String method = GET_STR;
- if (requestMethod != null) {
- method = requestMethod;
- }
+ if (requestMethod != null) {
+ method = requestMethod;
+ }
- LOGGER.info(method + "ing: " + url + "; timeout is " + timeout);
+ LOGGER.info(method + "ing: " + url + "; timeout is " + timeout);
- final URLConnection connection = new URL(url).openConnection();
+ final URLConnection connection = new URL(url).openConnection();
- connection.setIfModifiedSince(lastFetchTime);
+ connection.setIfModifiedSince(lastFetchTime);
- if (timeout != 0) {
- connection.setConnectTimeout(timeout);
- connection.setReadTimeout(timeout);
- }
+ if (timeout != 0) {
+ connection.setConnectTimeout(timeout);
+ connection.setReadTimeout(timeout);
+ }
- final HttpURLConnection http = (HttpURLConnection) connection;
+ http = (HttpURLConnection) connection;
- if (connection instanceof HttpsURLConnection) {
- final HttpsURLConnection https = (HttpsURLConnection) connection;
- https.setHostnameVerifier(new HostnameVerifier() {
- @Override
- public boolean verify(final String arg0, final SSLSession arg1) {
- return true;
- }
- });
- }
+ if (connection instanceof HttpsURLConnection) {
+ final HttpsURLConnection https = (HttpsURLConnection) connection;
+ https.setHostnameVerifier(new HostnameVerifier() {
+ @Override
+ public boolean verify(final String arg0, final SSLSession arg1) {
+ return true;
+ }
+ });
+ }
- http.setInstanceFollowRedirects(false);
- http.setRequestMethod(method);
- http.setAllowUserInteraction(true);
- http.addRequestProperty("Accept-Encoding", GZIP_ENCODING_STRING);
+ http.setInstanceFollowRedirects(false);
+ http.setRequestMethod(method);
+ http.setAllowUserInteraction(true);
+ http.addRequestProperty("Accept-Encoding", GZIP_ENCODING_STRING);
- for (final String key : requestProps.keySet()) {
- http.addRequestProperty(key, requestProps.get(key));
- }
+ for (final String key : requestProps.keySet()) {
+ http.addRequestProperty(key, requestProps.get(key));
+ }
- if (method.equals(POST_STR) && data != null) {
- http.setDoOutput(true); // Triggers POST.
+ if (method.equals(POST_STR) && data != null) {
+ http.setDoOutput(true); // Triggers POST.
- try (final OutputStream output = http.getOutputStream()) {
- output.write(data.getBytes(UTF8_STR));
+ try (final OutputStream output = http.getOutputStream()) {
+ output.write(data.getBytes(UTF8_STR));
+ }
}
- }
- connection.connect();
+ connection.connect();
+
+ } catch (Exception e) {
+ LOGGER.error("Failed Http Request to " + http.getURL() + " Status " + http.getResponseCode());
+ http.disconnect();
+ }
return http;
}
@@ -133,44 +140,50 @@ public class Fetcher {
private String fetchIfModifiedSince(final String url, final String data, final String method, final long lastFetchTime) throws IOException {
final OutputStream out = null;
+ String ifModifiedSince = null;
try {
final HttpURLConnection connection = getConnection(url, data, method, lastFetchTime);
+ if (connection != null) {
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
+ return null;
+ }
- if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
- return null;
- }
+ if (connection.getResponseCode() > 399) {
+ LOGGER.warn("Failed Http Request to " + url + " Status " + connection.getResponseCode());
+ return null;
+ }
- if (connection.getResponseCode() > 399) {
- LOGGER.warn("Failed Http Request to " + url + " Status " + connection.getResponseCode());
- return null;
+ final StringBuilder sb = new StringBuilder();
+ createStringBuilderFromResponse(sb, connection);
+ ifModifiedSince = sb.toString();
}
- final StringBuilder sb = new StringBuilder();
- createStringBuilderFromResponse(sb, connection);
-
- return sb.toString();
} finally {
IOUtils.closeQuietly(out);
}
+ return ifModifiedSince;
}
public int getIfModifiedSince(final String url, final long lastFetchTime, final StringBuilder stringBuilder) throws IOException {
final OutputStream out = null;
+ int status = 0;
try {
final HttpURLConnection connection = getConnection(url, null, "GET", lastFetchTime);
- final int status = connection.getResponseCode();
+ if (connection != null) {
+ status = connection.getResponseCode();
- if (status == HttpURLConnection.HTTP_NOT_MODIFIED) {
- return status;
- }
+ if (status == HttpURLConnection.HTTP_NOT_MODIFIED) {
+ return status;
+ }
- if (connection.getResponseCode() > 399) {
- LOGGER.warn("Failed Http Request to " + url + " Status " + connection.getResponseCode());
- return status;
- }
+ if (connection.getResponseCode() > 399) {
+ LOGGER.warn("Failed Http Request to " + url + " Status " + connection.getResponseCode());
+ return status;
+ }
- createStringBuilderFromResponse(stringBuilder, connection);
+ createStringBuilderFromResponse(stringBuilder, connection);
+ }
return status;
} finally {
IOUtils.closeQuietly(out);
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 02/07: modified to check null in the event the
HTTP Connection is down
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 1c10d2172b5211289fa7bbc9c6025b8b3fa71184
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu May 17 14:25:54 2018 -0600
modified to check null in the event the HTTP Connection is down
---
.../traffic_control/traffic_router/core/util/ProtectedFetcher.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
index 10da44f..ce019cd 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
@@ -40,10 +40,11 @@ public class ProtectedFetcher extends Fetcher {
}
private HttpURLConnection extractCookie(final HttpURLConnection http) throws IOException {
- if (http.getHeaderField("Set-Cookie") != null) {
- setCookie(HttpCookie.parse(http.getHeaderField("Set-Cookie")).get(0));
+ if (http != null) {
+ if (http.getHeaderField("Set-Cookie") != null) {
+ setCookie(HttpCookie.parse(http.getHeaderField("Set-Cookie")).get(0));
+ }
}
-
return http;
}
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 07/07: Removed static on AsyncHttpClient to allow
prevent leak warnings in Tomcat
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 03e3b521214b87c343c34de2dccb0be882b0a01a
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Jun 5 08:46:15 2018 -0600
Removed static on AsyncHttpClient to allow prevent leak warnings in Tomcat
---
.../traffic_router/core/util/PeriodicResourceUpdater.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java
index 7165f9f..5415bfb 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/PeriodicResourceUpdater.java
@@ -52,7 +52,7 @@ import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
public class PeriodicResourceUpdater {
private static final Logger LOGGER = Logger.getLogger(PeriodicResourceUpdater.class);
- private static AsyncHttpClient asyncHttpClient;
+ private AsyncHttpClient asyncHttpClient;
protected String databaseLocation;
protected final ResourceUrl urls;
protected ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
@@ -143,7 +143,9 @@ public class PeriodicResourceUpdater {
final Request request = getRequest(urls.nextUrl());
if (request != null) {
request.getHeaders().add("Accept-Encoding", GZIP_ENCODING_STRING);
- asyncHttpClient.executeRequest(request, new UpdateHandler(request)); // AsyncHandlers are NOT thread safe; one instance per request
+ if ((asyncHttpClient!=null) && (!asyncHttpClient.isClosed())) {
+ asyncHttpClient.executeRequest(request, new UpdateHandler(request)); // AsyncHandlers are NOT thread safe; one instance per request
+ }
return true;
}
} else {
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 01/07: updated to improve the logging to
understand the real URL being watched
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit d8c2d20fe0f65f9be08256ba942a57e6261bdac8
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu May 17 14:20:44 2018 -0600
updated to improve the logging to understand the real URL being watched
---
.../traffic_router/core/util/AbstractResourceWatcher.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java
index 24b2008..9574497 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java
@@ -129,13 +129,13 @@ public abstract class AbstractResourceWatcher extends AbstractServiceUpdater {
@Override
protected File downloadDatabase(final String url, final File existingDb) {
+ final String interpolatedUrl = trafficOpsUtils.replaceTokens(url);
if (fetcher == null) {
- LOGGER.warn("[" + getClass().getSimpleName() + "] Waiting for configuration to be processed, unable to download from '" + url + "'");
+ LOGGER.warn("[" + getClass().getSimpleName() + "] Waiting for configuration to be processed, unable to download from '" + interpolatedUrl + "'");
return null;
}
String jsonData = null;
- final String interpolatedUrl = trafficOpsUtils.replaceTokens(url);
try {
jsonData = fetcher.fetchIfModifiedSince(interpolatedUrl, existingDb.lastModified());
}
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[trafficcontrol] 06/07: added null check to prevent NPE
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit dce41530806e363b13ebf99b38bcd6998ef26af5
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Tue Jun 5 08:42:31 2018 -0600
added null check to prevent NPE
---
.../traffic_router/core/util/AbstractResourceWatcher.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java
index 9574497..a9c634d 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/AbstractResourceWatcher.java
@@ -129,6 +129,9 @@ public abstract class AbstractResourceWatcher extends AbstractServiceUpdater {
@Override
protected File downloadDatabase(final String url, final File existingDb) {
+ if ((trafficOpsUtils.getHostname() == null) || trafficOpsUtils.getCdnName() == null) {
+ return null;
+ }
final String interpolatedUrl = trafficOpsUtils.replaceTokens(url);
if (fetcher == null) {
LOGGER.warn("[" + getClass().getSimpleName() + "] Waiting for configuration to be processed, unable to download from '" + interpolatedUrl + "'");
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.