-
Notifications
You must be signed in to change notification settings - Fork 480
feat(s3-publishing): Add S3 static publishing support for vanity URLs #35808
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
Open
dsilvam
wants to merge
1
commit into
main
Choose a base branch
from
s3-static-push-vanity-url-dsilvam
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,16 @@ public void shutdownTransferManager(){ | |
| this.storage.shutdownTransferManager(); | ||
| } | ||
|
|
||
| /** | ||
| * Indica se il file viene gestito dal publisher S3. | ||
| * | ||
| * @param file file da verificare | ||
| * @return true se il file puo essere pubblicato o rimosso | ||
| */ | ||
| public boolean acceptsFile(final File file) { | ||
| return awss3FileFilter.accept(file); | ||
| } | ||
|
|
||
| /** | ||
| * Implementation of {@link EndPointPublisher#checkConnectSuccessfully(String)}. | ||
| * | ||
|
|
@@ -127,13 +137,7 @@ public void deleteFilesFromEndpoint(final String bucketName, | |
| try{ | ||
| //We want to ignore these extensions because they weren't pushed. | ||
| if (awss3FileFilter.accept(new File(filePath))) { | ||
| String filePathInBucket = filePath; | ||
| if (filePathInBucket.startsWith(File.separator)){ | ||
| filePathInBucket = filePathInBucket.substring(1); | ||
| } | ||
| if (UtilMethods.isSet(bucketRootPrefix)){ | ||
| filePathInBucket = bucketRootPrefix + File.separator + filePathInBucket; | ||
| } | ||
| final String filePathInBucket = getCompleteFileKey(bucketRootPrefix, filePath); | ||
| Logger.debug(this, "Deleting file named: " + filePathInBucket + " from bucket: " + bucketName); | ||
| this.storage.deleteFile(bucketName, filePathInBucket); | ||
| } | ||
|
|
@@ -144,6 +148,84 @@ public void deleteFilesFromEndpoint(final String bucketName, | |
| } | ||
| } // deleteFilesFromEndpoint | ||
|
|
||
| /** | ||
| * Pubblica un file usando una key S3 esplicita. | ||
| * | ||
| * @param bucketName nome bucket | ||
| * @param region regione bucket | ||
| * @param bucketRootPrefix prefisso bucket | ||
| * @param filePath key S3 relativa o assoluta | ||
| * @param file file fisico da inviare | ||
| * @throws DotPublishingException se la pubblicazione fallisce | ||
| */ | ||
| public void pushFileToEndpoint(final String bucketName, final String region, final String bucketRootPrefix, | ||
| final String filePath, final File file) throws DotPublishingException { | ||
| final int secondsToSleep = Config.getIntProperty("STATIC_PUSH_SLEEP_ON_ERROR_SECONDS", 10); | ||
| final int pushRetries = Config.getIntProperty("STATIC_PUSH_RETRY_ATTEMPTS", 3); | ||
|
|
||
| boolean success = false; | ||
| int retriesCount = 0; | ||
| String errorMessages = ""; | ||
|
|
||
| while (!success && retriesCount <= pushRetries) { | ||
| try { | ||
| Logger.info(this, "Pushing File with explicit key: " + filePath + ", retries: " + retriesCount); | ||
| this.pushExactFile(bucketName, bucketRootPrefix, filePath, file); | ||
| success = true; | ||
| } catch (final Exception e) { | ||
| errorMessages += "\n Retry #: " + retriesCount + ", Error: " + e.getMessage(); | ||
| retriesCount++; | ||
| try { | ||
| Logger.info(this, "Sleeping before next push try, seconds: " + secondsToSleep); | ||
| Thread.sleep(secondsToSleep * 1000); | ||
| } catch (InterruptedException ie) { | ||
| Logger.error(this, "Can't Sleep before retry file: " + file.getAbsolutePath()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're missing a Thread.currentThread().interrupt(); here |
||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!success) { | ||
| Logger.error(this, "Can't push file: " + file.getAbsolutePath() + ", reasons : " + errorMessages); | ||
| throw new DotPublishingException("Can't push file: " + file.getAbsolutePath() + ", reasons : " + errorMessages); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Pubblica un file usando la key esplicita fornita. | ||
| * | ||
| * @param bucketName nome bucket | ||
| * @param bucketRootPrefix prefisso bucket | ||
| * @param filePath key S3 | ||
| * @param file file fisico da inviare | ||
| * @throws IOException in caso di errore I/O | ||
| * @throws DecoderException in caso di errore MD5 | ||
| * @throws InterruptedException in caso di attesa interrotta | ||
| */ | ||
| private void pushExactFile(final String bucketName, final String bucketRootPrefix, | ||
| final String filePath, final File file) | ||
| throws IOException, DecoderException, InterruptedException { | ||
| if (!awss3FileFilter.accept(file)) { | ||
| return; | ||
| } | ||
|
|
||
| Logger.debug(this, "Pushing explicit File: " + file); | ||
|
|
||
| final String completeFileKey = getCompleteFileKey(bucketRootPrefix, filePath); | ||
| ObjectMetadata objectMetadata = new ObjectMetadata(); | ||
| setMD5Based64(file, objectMetadata); | ||
| setContentType(file, objectMetadata); | ||
| try (InputStream is = Files.newInputStream(file.toPath())) { | ||
| objectMetadata.setContentLength(file.length()); | ||
| PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, completeFileKey, is, objectMetadata); | ||
| final Upload upload = this.storage.uploadFile(putObjectRequest); | ||
|
|
||
| if (null != upload && this.isWaitForCompletionNeeded()) { | ||
| final UploadResult result = upload.waitForUploadResult(); | ||
| Logger.debug(this, "File: " + file + " has been uploaded, result: " + result); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void pushBundleToEndpoint(final String bucketName, final String region, final String bucketRootPrefix, | ||
| final String filePath, final File file) throws DotPublishingException { | ||
|
|
@@ -332,6 +414,32 @@ protected String getFolderPath(final String bucketRootPrefix, | |
| return folderPath; | ||
| } // getFolderPath. | ||
|
|
||
| /** | ||
| * Costruisce la key S3 completa a partire da un path relativo. | ||
| * | ||
| * @param bucketRootPrefix prefisso bucket | ||
| * @param filePath path relativo o assoluto | ||
| * @return key S3 normalizzata | ||
| */ | ||
| protected String getCompleteFileKey(final String bucketRootPrefix, final String filePath) { | ||
| String completeFileKey = filePath; | ||
| if (completeFileKey.startsWith(File.separator)) { | ||
| completeFileKey = completeFileKey.substring(1); | ||
| } | ||
|
|
||
| if (UtilMethods.isSet(bucketRootPrefix)) { | ||
| if (bucketRootPrefix.endsWith(File.separator) && completeFileKey.startsWith(File.separator)) { | ||
| completeFileKey = bucketRootPrefix + completeFileKey.substring(1); | ||
| } else if (bucketRootPrefix.endsWith(File.separator) || completeFileKey.startsWith(File.separator)) { | ||
| completeFileKey = bucketRootPrefix + completeFileKey; | ||
| } else { | ||
| completeFileKey = bucketRootPrefix + File.separator + completeFileKey; | ||
| } | ||
| } | ||
|
|
||
| return completeFileKey; | ||
| } | ||
|
|
||
| public void createBucket(final String bucketName, final String region) throws DotPublishingException { | ||
|
|
||
| if (!this.exists (bucketName)) { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
italian - must be English