-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Java] Disable soft delete policy when creating a default bucket for a project. #31324
Merged
damccorm
merged 5 commits into
apache:master
from
shunping:gcs-bucket-rentention-policy
May 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f2d2c6
Disable soft delete policy when creating a default bucket for a project.
shunping c213d7e
Add random number to prefix to avoid collision on multiple test insta…
shunping aa5ddf3
Remove default bucket before creating in the integration test.
shunping 6601e2c
Add one line in CHANGES.md to mention this change and fix a typo.
shunping 2a45295
Merge branch 'master' into gcs-bucket-rentention-policy
shunping 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 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
This file contains 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
This file contains 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
71 changes: 71 additions & 0 deletions
71
...-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/options/GcpOptionsIT.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.beam.sdk.extensions.gcp.options; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import com.google.api.services.cloudresourcemanager.CloudResourceManager; | ||
import com.google.api.services.storage.model.Bucket; | ||
import java.io.IOException; | ||
import org.apache.beam.sdk.extensions.gcp.util.GcsUtil; | ||
import org.apache.beam.sdk.extensions.gcp.util.gcsfs.GcsPath; | ||
import org.apache.beam.sdk.testing.TestPipeline; | ||
import org.apache.beam.sdk.testing.TestPipelineOptions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** | ||
* Integration tests for {@link GcpOptions}. These tests are designed to run against production | ||
* Google Cloud Storage. | ||
* | ||
* <p>This is a runnerless integration test, even though the Beam IT framework assumes one. Thus, | ||
* this test should only be run against single runner (such as DirectRunner). | ||
*/ | ||
@RunWith(JUnit4.class) | ||
public class GcpOptionsIT { | ||
/** Tests the creation of a default bucket in a project. */ | ||
@Test | ||
public void testCreateDefaultBucket() throws IOException { | ||
TestPipelineOptions options = | ||
TestPipeline.testingPipelineOptions().as(TestPipelineOptions.class); | ||
|
||
CloudResourceManager crmClient = | ||
GcpOptions.GcpTempLocationFactory.newCloudResourceManagerClient( | ||
options.as(CloudResourceManagerOptions.class)) | ||
.build(); | ||
|
||
GcsOptions gcsOptions = options.as(GcsOptions.class); | ||
GcsUtil gcsUtil = gcsOptions.getGcsUtil(); | ||
|
||
String tempLocation = | ||
GcpOptions.GcpTempLocationFactory.tryCreateDefaultBucketWithPrefix( | ||
options, crmClient, "gcp-options-it-"); | ||
|
||
GcsPath gcsPath = GcsPath.fromUri(tempLocation); | ||
System.out.println(gcsPath); | ||
|
||
Bucket bucket = gcsUtil.getBucket(gcsPath); | ||
assertNotNull(bucket); | ||
// verify the soft delete policy is disabled | ||
assertEquals(bucket.getSoftDeletePolicy().getRetentionDurationSeconds(), Long.valueOf(0L)); | ||
|
||
gcsUtil.removeBucket(bucket); | ||
} | ||
} |
This file contains 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
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.
Should we check for existence of the bucket and delete it if it exists before we do this? That way we avoid a bad condition where the delete fails on one test and then we're stuck in a bad state indefinitely
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.
Can we remove it? I haven't checked the internal logic. Could two Dataflow jobs use the same default bucket?
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 default bucket name is a concatenation of a fixed prefix, region and a project number. So for a given project, if it is running in the same region, the default bucket name would be the same.
For our integration test, it would always be the same as "gcp-options-it-us-central1-844138762903". Actually, this may cause race condition if we run this integration test twice at the same time though.
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.
For this test, I think I have to add some random number in the prefix then.
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.
Well, if we add a random number to avoid race condition, then we could end up with multiple dangling buckets if deletion fails. That's a tradeoff we need to make, to avoid race condition or to avoid dangling buckets. Thoughts?
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 think that is fine. If it causes problems we could always add a cleanup job like https://github.com/apache/beam/blob/master/.test-infra/tools/stale_bq_datasets_cleaner.sh
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.
Done.