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
20 changes: 14 additions & 6 deletions src/main/java/com/conveyal/datatools/manager/jobs/DeployJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,7 @@ else if ("true".equals(System.getenv("RUN_E2E"))) {
// add GTFS data
for (String feedVersionId : deployment.feedVersionIds) {
CustomFile gtfsFile = new CustomFile();
// OTP 2.x must have the string `gtfs` somewhere inside the filename, so prepend the filename
// with the string `gtfs-`.
gtfsFile.filename = String.format("gtfs-%s", feedVersionId);
gtfsFile.filename = getGraphBuildFeedFilename(feedVersionId);
gtfsFile.uri = S3Utils.getS3FeedUri(feedVersionId);
addCustomFileAsBaseFolderDownload(manifest, gtfsFile);
}
Expand Down Expand Up @@ -1217,9 +1215,7 @@ public OtpRunnerManifest createAndUploadManifestAndConfigs(boolean graphAlreadyB
// add GTFS data
for (String feedVersionId : deployment.feedVersionIds) {
CustomFile gtfsFile = new CustomFile();
// OTP 2.x must have the string `gtfs` somewhere inside the filename, so prepend the filename
// with the string `gtfs-`.
gtfsFile.filename = String.format("gtfs-%s", feedVersionId);
gtfsFile.filename = getGraphBuildFeedFilename(feedVersionId);
gtfsFile.uri = S3Utils.getS3FeedUri(feedVersionId);
addCustomFileAsBaseFolderDownload(manifest, gtfsFile);
}
Expand Down Expand Up @@ -1310,6 +1306,18 @@ public OtpRunnerManifest createAndUploadManifestAndConfigs(boolean graphAlreadyB
return manifest;
}

/**
* Determine the name used when otp-runner downloads a feed for graph building.
* Preserve the existing feed-version fallback while honoring the FeedSource filename exactly when configured.
*/
private String getGraphBuildFeedFilename(String feedVersionId) {
FeedVersion feedVersion = Persistence.feedVersions.getById(feedVersionId);
return deployment.getFeedSourceBundleFilename(
feedVersion,
String.format("gtfs-%s", feedVersionId)
Comment thread
daniel-heppner-ibigroup marked this conversation as resolved.
);
}

/**
* Adds a custom file as a base folder download. If the custom file has non-null contents, then those contents will
* be uploaded to AWS S3 and that corresponding AWS S3 URI will be added to the list of base folder downloads. If
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/conveyal/datatools/manager/models/Deployment.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void dump (File output, boolean includeManifest, boolean includeOsm, bool
File gtfsFile = v.retrieveGtfsFile();
try (FileInputStream in = new FileInputStream(gtfsFile)) {
// Determine the entry name for the zip file.
String entryName = getFeedSourceBundleFilename(v, gtfsFile);
String entryName = getFeedSourceBundleFilename(v, gtfsFile.getName());
ZipEntry e = new ZipEntry(entryName);
out.putNextEntry(e);
ByteStreams.copy(in, out);
Expand Down Expand Up @@ -403,26 +403,26 @@ public void dump (File output, boolean includeManifest, boolean includeOsm, bool
}

/**
* Determine the entry name for a GTFS file within the deployment bundle.
* This prioritizes the FeedSource filename if available and valid, otherwise falls back
* to the original GTFS filename derived from the FeedVersion.
* Determine the entry name for a GTFS file within a deployment.
* This prioritizes the FeedSource filename if available and valid, otherwise it falls back
* to the provided filename.
*
* @param feedVersion The FeedVersion being processed.
* @param gtfsFile The GTFS file associated with the FeedVersion.
* @return The calculated entry name for the zip file.
* @param feedVersion The FeedVersion being processed.
* @param fallbackName The filename to use when the FeedSource has no configured filename.
* @return The calculated filename for the GTFS file.
*/
public String getFeedSourceBundleFilename(FeedVersion feedVersion, File gtfsFile) {
String gtfsFileName = gtfsFile.getName();
FeedSource fs = feedVersion.parentFeedSource();
public String getFeedSourceBundleFilename(FeedVersion feedVersion, String fallbackName) {
FeedSource fs = feedVersion == null ? null : feedVersion.parentFeedSource();

if (fs != null && !Strings.isBlank(fs.filename)) {
// Use FeedSource filename if available, ensuring it ends with .zip
LOG.info("Using FeedSource filename for zip entry: {}", gtfsFileName);
LOG.info("Using FeedSource filename for zip entry: {}", fs.filename);
return fs.filename.endsWith(".zip") ? fs.filename : fs.filename + ".zip";
}
// Fallback to the original GTFS filename derived from FeedVersion
LOG.info("Using FeedVersion filename for zip entry: {}", gtfsFileName);
return gtfsFileName;
}

// Fall back to the filename associated with the FeedVersion.
LOG.info("Using fallback filename for zip entry: {}", fallbackName);
return fallbackName;
}

/** Download config from provided URL. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,15 @@ public void canGetFeedSourceBundleFilename() throws IOException {

feedSource.filename = "gtfs_from_source.zip";
Persistence.feedSources.create(feedSource);
assertEquals("gtfs_from_source.zip", deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile));

feedSource.filename = "gtfs_from_source";
Persistence.feedSources.replace(feedSource.id, feedSource);
assertEquals("gtfs_from_source.zip", deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile));
assertEquals("gtfs_from_source.zip", deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile.getName()));

feedSource.filename = " ";
Persistence.feedSources.replace(feedSource.id, feedSource);
assertEquals(gtfsFileName, deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile));
assertEquals(gtfsFileName, deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile.getName()));

feedSource.filename = null;
Persistence.feedSources.replace(feedSource.id, feedSource);
assertEquals(gtfsFileName, deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile));

FeedVersion versionWithNullSource = new FeedVersion();
assertEquals(gtfsFileName, deployment.getFeedSourceBundleFilename(versionWithNullSource, gtfsFile));
assertEquals(gtfsFileName, deployment.getFeedSourceBundleFilename(feedVersion, gtfsFile.getName() ));

Persistence.feedVersions.removeById(feedVersion.id);
Persistence.feedSources.removeById(feedSource.id);
Expand Down
Loading