-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add support for HTTPS datasource for Graph Building #4482
Add support for HTTPS datasource for Graph Building #4482
Conversation
src/main/java/org/opentripplanner/datastore/https/HttpsDataSourceRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/datastore/https/HttpsFileDataSource.java
Outdated
Show resolved
Hide resolved
/* private methods */ | ||
|
||
private static boolean skipUri(URI uri) { | ||
return !"https".equals(uri.getScheme()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doesn't happen a lot but do we not want to support HTTP without TLS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not implement it right away (for security reasons). This could be easily added later if someone asks for it.
Codecov ReportBase: 58.48% // Head: 58.62% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #4482 +/- ##
=============================================
+ Coverage 58.48% 58.62% +0.13%
- Complexity 11431 11548 +117
=============================================
Files 1512 1520 +8
Lines 60102 60611 +509
Branches 6829 6890 +61
=============================================
+ Hits 35152 35534 +382
- Misses 22887 22986 +99
- Partials 2063 2091 +28
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
if (lastModifiedHeader != null) { | ||
Date lastModifiedDate = DateUtils.parseDate(lastModifiedHeader); | ||
if (lastModifiedDate != null) { | ||
return lastModifiedDate.getTime(); | ||
} | ||
} | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very much a matter of personal taste but I dislike repeated null checks (an null checks in general).
How to you like this?
if (lastModifiedHeader != null) { | |
Date lastModifiedDate = DateUtils.parseDate(lastModifiedHeader); | |
if (lastModifiedDate != null) { | |
return lastModifiedDate.getTime(); | |
} | |
} | |
return 0; | |
return Optional | |
.ofNullable(lastModifiedHeader) | |
.map(DateUtils::parseDate) | |
.map(Date::getTime) | |
.orElse(0L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion about this, but it seems @t2gran has :-)
#4480 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just hope that there would be a clean syntax for this, similar to how optional chaining in JavaScript is. I really dislike how the repeated null-checks look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could also chime in here: #4480 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Optional
is not made for this, and it reduces readability - I wish Java had support for a safe operator like Kotlin(?.
) as well, but until then, use the language feature, not a library feature intended for something else. I would probably written the above code like this, to avoid nested if
s - but this is just personal taste:
if (lastModifiedHeader == null) {
return -1;
}
Date lastModifiedDate = DateUtils.parseDate(lastModifiedHeader);
if (lastModifiedDate != null) {
return -1;
}
return lastModifiedDate.getTime();
PS ! The method should return -1
not 0
if the value does not exist
* @return last modified timestamp in ms, if unknown returns {@code -1} |
@@ -85,4 +98,28 @@ public static InputStream openInputStream(URI uri, Map<String, String> headers) | |||
return downloadUrl.openStream(); | |||
} | |||
} | |||
|
|||
private static HttpResponse getResponse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with your PR but now that we have this method we can actually use it in SiriHttpUtils.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've ran the code and it works great but I have a suggestion about the null checks.
What I want to add in the future is progress bar and local caching of files (if the ETag/Last-Modified) hasn't changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to see the (in my view ugly) null checks go but the code is solid otherwise.
try { | ||
return Long.parseLong(header); | ||
} catch (Exception e) { | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return size in bytes, if unknown returns {@code -1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 0
end up as the returned value for the HttpDataSource#size()
. The JavaDoc is either wrong or this is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nice fix to this would be to change the DataSource
interface and return an OptionalLong
for size
and lastModified
. If you don´t want to do that in this PR, I can fix it in a separate PR later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the two methods to be consistent with the Javadoc.
Updating the DataSource interface should probably be done in a separate PR.
Google Cloud Storage files: `"gs://otp-test-bucket/a/b/graph.obj"` | ||
Local files: `"file:///Users/kelvin/otp/streetGraph.obj"` | ||
HTTPS resources: `"https://download.geofabrik.de/europe/norway-latest.osm.pbf"` | ||
Google Cloud Storage files: `"gs://otp-test-bucket/a/b/graph.obj"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a mention of osmCacheDataInMem
somewhere, or even enable it by default, if it is a https source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll do this later
/** | ||
* HTTPS data source metadata returned by the HTTP server (HTTP headers). | ||
*/ | ||
public class HttpsDataSourceMetadata { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably have a toString
, as it is being logged
Summary
This PR implements support for reading data sources from an HTTPS resource.
The data source provides only read operations.
Issue
Implements #4481
Unit tests
Added unit tests
Documentation
Updated BuildConfiguration.md