forked from GoogleCloudPlatform/dotnet-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
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
samples(storage transfer): add samples and test cases for storage transfer services #9
Open
mahendra-google
wants to merge
57
commits into
main
Choose a base branch
from
event_driven_gcs_transfer_service_samples
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 51 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
ba3c128
feat(Storage Transfer) : Addition of Sample and Test Case for storage…
mahendra-google c2982ef
Merge branch 'missing_.net_transfer_service_samples' of https://githu…
mahendra-google 36706a4
feat(Storage Transfer) : Addition of Schedule End Date in Sample for …
mahendra-google afcba29
samples(storage transfer) : Addition of schedule end date in sample f…
mahendra-google 5d43c18
Merge branch 'missing_.net_transfer_service_samples' of https://githu…
mahendra-google 3efcf76
chore(deps): add dependency xunit.abstractions version 2.0.3 to see o…
mahendra-google 35e18a3
code changes in transfer to nearline related to capture message in st…
mahendra-google 0acb7fd
feat(storage transfer) : addition of sample and test case to check la…
mahendra-google e3c0619
Merge branch 'GoogleCloudPlatform:main' into missing_.net_transfer_se…
mahendra-google 000b432
feat (storage transfer) : addition of samples and test cases for tran…
mahendra-google 910ad26
Merge branch 'GoogleCloudPlatform:main' into main
mahendra-google 398b3d5
Merge branch 'GoogleCloudPlatform:main' into main
mahendra-google b5d9b10
storage transfer from POSIX file system to GCS bucket using manifest …
mahendra-google 3c9d243
minor changes
mahendra-google f4b73e0
samples(storage transfer): transfer from POSIX file system to GCS buc…
mahendra-google 1acec24
Merge branch 'GoogleCloudPlatform:main' into main
mahendra-google 375f1e0
addition of sample and test case for transfer from posix
mahendra-google 81beca4
samples(storage transfer): add samples and test cases for transfer fr…
mahendra-google ce4a089
Merge branch 'GoogleCloudPlatform:main' into main
mahendra-google 139190a
added sample and test case for download to posix storage transfer ser…
mahendra-google 7357db6
samples(storage transfer): add sample and test case for storage trans…
mahendra-google bb66a63
code changes for creation of temp folder in posix file system
mahendra-google 526b445
couple of test checks added in download to posix
mahendra-google 8a06504
samples(storage transfer): code changes in logic for creation of tem…
mahendra-google edc89e4
added sample and test case for posix to posix storage transfer
mahendra-google 7d100d4
one test check added in posix to posix storage transfer
mahendra-google 4b88480
add sample and test case for event driven transfer and few storage fi…
mahendra-google effd0c2
samples(storage transfer): code changes for printing messages to cons…
mahendra-google f5d8252
Update storagetransfer/api/StorageTransfer.Samples/TransferUsingManif…
mahendra-google be9c4bb
Update storagetransfer/api/StorageTransfer.Samples.Tests/TransferUsin…
mahendra-google be74818
code refactoring changes
mahendra-google a69aaa1
Merge branch 'event_driven_gcs_transfer_service_samples' of https://g…
mahendra-google 4b5d2e5
code changes
mahendra-google 52eb9de
Merge branch 'main' into event_driven_gcs_transfer_service_samples
mahendra-google f57ea40
Copyright year reverted for old files
mahendra-google bf89631
Merge branch 'main' into event_driven_gcs_transfer_service_samples
mahendra-google a2192fc
Blank line removed
mahendra-google 2d068d2
changes related to blank spaces
mahendra-google 2e7aa62
Blank spaces reverted in QuickStartTest
mahendra-google 02a0e14
resources for event driven transfer are moved from storage fixture to…
mahendra-google 5e70900
movement of temporary folder path from storage fixture to respective …
mahendra-google d942177
gcssourcepath , manifestobjectname is moved from fixture to test
mahendra-google a59263c
UploadObjectToManifestBucket , UploadObjectToPosixBucket , CreateTran…
mahendra-google 7e2b4dd
style and structure changes as per canonical sample
mahendra-google 04eeea7
Merge branch 'main' into event_driven_gcs_transfer_service_samples
mahendra-google 332f78d
XML documentation is added to describe the sample methods
mahendra-google 522b48a
samples and test linter changes
mahendra-google 8642fbf
Structural and linter changes in tests
mahendra-google 7287261
linter changes in tests
mahendra-google 904c989
reuse of existing fixture's storage client in transfer to nearline test
mahendra-google 1b0d4fa
linter changes as per .editorconfig file at the root of repository
mahendra-google dda9b52
exception handling removed from CheckLatestTransferOperation
mahendra-google f1b05b3
Comments added in tests and sample description modified
mahendra-google b05a6bc
Revert "Comments added in tests and sample description modified"
mahendra-google 526ddad
Comments are added and sample description modified
mahendra-google c6950d8
Quickstart test and sample changes
mahendra-google d043b9e
minor changes
mahendra-google 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
67 changes: 67 additions & 0 deletions
67
storagetransfer/api/StorageTransfer.Samples.Tests/CheckLatestTransferOperationTest.cs
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,67 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed 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 | ||
// | ||
// https://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. | ||
|
||
using Google.Cloud.StorageTransfer.V1; | ||
using Xunit; | ||
|
||
namespace StorageTransfer.Samples.Tests; | ||
|
||
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. Add comments to include what is being tested. |
||
[Collection(nameof(StorageFixture))] | ||
public class CheckLatestTransferOperationTest | ||
{ | ||
private readonly StorageFixture _fixture; | ||
private string _jobName; | ||
private readonly string _transferJobName; | ||
|
||
public CheckLatestTransferOperationTest(StorageFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
_fixture.BucketNameSource = _fixture.GenerateBucketName(); | ||
_fixture.BucketNameSink = _fixture.GenerateBucketName(); | ||
_fixture.CreateBucketAndGrantStsPermissions(_fixture.BucketNameSource); | ||
_fixture.CreateBucketAndGrantStsPermissions(_fixture.BucketNameSink); | ||
_transferJobName = CreateTransferJob(); | ||
} | ||
|
||
[Fact] | ||
public void CheckLatestTransferOperation() | ||
{ | ||
CheckLatestTransferOperationSample checkLatestTransferOperationSample = new CheckLatestTransferOperationSample(); | ||
var transferJob = checkLatestTransferOperationSample.CheckLatestTransferOperation(_fixture.ProjectId, _transferJobName); | ||
Assert.Contains("transferJobs/", transferJob.Name); | ||
_jobName = transferJob.Name; | ||
} | ||
|
||
private string CreateTransferJob() | ||
{ | ||
// Initialize request argument(s) | ||
TransferJob transferJob = new TransferJob | ||
{ | ||
ProjectId = _fixture.ProjectId, | ||
TransferSpec = new TransferSpec | ||
{ | ||
GcsDataSink = new GcsData { BucketName = _fixture.BucketNameSource }, | ||
GcsDataSource = new GcsData { BucketName = _fixture.BucketNameSink } | ||
}, | ||
Status = TransferJob.Types.Status.Enabled | ||
}; | ||
CreateTransferJobRequest request = new CreateTransferJobRequest | ||
{ | ||
TransferJob = transferJob | ||
}; | ||
// Make the request | ||
TransferJob response = _fixture.Sts.CreateTransferJob(new CreateTransferJobRequest { TransferJob = transferJob }); | ||
return response.Name; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
storagetransfer/api/StorageTransfer.Samples.Tests/CreateEventDrivenGcsTransferTest.cs
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,113 @@ | ||
/** | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Copyright 2024 Google Inc. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
using Google.Cloud.PubSub.V1; | ||
using Google.Cloud.StorageTransfer.V1; | ||
using System; | ||
using Xunit; | ||
|
||
namespace StorageTransfer.Samples.Tests; | ||
|
||
[Collection(nameof(StorageFixture))] | ||
public class CreateEventDrivenGcsTransferTest : IDisposable | ||
{ | ||
private readonly StorageFixture _fixture; | ||
private readonly string _pubSubId; | ||
private string _transferJobName; | ||
private string TopicId { get; } = "DotNetTopic" + Guid.NewGuid().ToString(); | ||
private string SubscriptionId { get; } = "DotNetSubscription" + Guid.NewGuid().ToString(); | ||
private SubscriberServiceApiClient SubscriberClient { get; } = SubscriberServiceApiClient.Create(); | ||
private PublisherServiceApiClient PublisherClient { get; } = PublisherServiceApiClient.Create(); | ||
|
||
public CreateEventDrivenGcsTransferTest(StorageFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
_fixture.BucketNameSource = _fixture.GenerateBucketName(); | ||
_fixture.BucketNameSink = _fixture.GenerateBucketName(); | ||
_fixture.CreateBucketAndGrantStsPermissions(_fixture.BucketNameSource); | ||
_fixture.CreateBucketAndGrantStsPermissions(_fixture.BucketNameSink); | ||
_pubSubId = $"projects/{_fixture.ProjectId}/subscriptions/{SubscriptionId}"; | ||
string email = _fixture.Sts.GetGoogleServiceAccount(new GetGoogleServiceAccountRequest() | ||
{ | ||
ProjectId = _fixture.ProjectId | ||
}).AccountEmail; | ||
|
||
string memberServiceAccount = "serviceAccount:" + email; | ||
// Create subscription name | ||
SubscriptionName subscriptionName = new SubscriptionName(_fixture.ProjectId, SubscriptionId); | ||
// Create topic name | ||
TopicName topicName = new TopicName(_fixture.ProjectId, TopicId); | ||
// Create topic | ||
PublisherClient.CreateTopic(topicName); | ||
// Create subscription. | ||
SubscriberClient.CreateSubscription(subscriptionName, topicName, pushConfig: null, ackDeadlineSeconds: 500); | ||
|
||
var policyIamPolicyTopic = new Google.Cloud.Iam.V1.Policy(); | ||
|
||
policyIamPolicyTopic.AddRoleMember("roles/pubsub.publisher", memberServiceAccount); | ||
|
||
PublisherClient.IAMPolicyClient.SetIamPolicy(new Google.Cloud.Iam.V1.SetIamPolicyRequest | ||
{ | ||
ResourceAsResourceName = topicName, | ||
Policy = policyIamPolicyTopic | ||
}); | ||
|
||
var policyIamPolicySubscriber = new Google.Cloud.Iam.V1.Policy(); | ||
|
||
policyIamPolicySubscriber.AddRoleMember("roles/pubsub.subscriber", memberServiceAccount); | ||
|
||
PublisherClient.IAMPolicyClient.SetIamPolicy(new Google.Cloud.Iam.V1.SetIamPolicyRequest | ||
{ | ||
ResourceAsResourceName = subscriptionName, | ||
Policy = policyIamPolicySubscriber | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void CreateEventDrivenGcsTransfer() | ||
{ | ||
CreateEventDrivenGcsTransferSample createEventDrivenGcsTransferSample = new CreateEventDrivenGcsTransferSample(); | ||
var transferJob = createEventDrivenGcsTransferSample.CreateEventDrivenGcsTransfer(_fixture.ProjectId, _fixture.BucketNameSource, _fixture.BucketNameSink, _pubSubId); | ||
Assert.Contains("transferJobs/", transferJob.Name); | ||
_transferJobName = transferJob.Name; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
try | ||
{ | ||
_fixture.Sts.UpdateTransferJob(new UpdateTransferJobRequest() | ||
{ | ||
ProjectId = _fixture.ProjectId, | ||
JobName = _transferJobName, | ||
TransferJob = new TransferJob() | ||
{ | ||
Name = _transferJobName, | ||
Status = TransferJob.Types.Status.Deleted | ||
} | ||
}); | ||
|
||
TopicName topicName = TopicName.FromProjectTopic(_fixture.ProjectId, TopicId); | ||
PublisherClient.DeleteTopic(topicName); | ||
SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(_fixture.ProjectId, SubscriptionId); | ||
SubscriberClient.DeleteSubscription(subscriptionName); | ||
} | ||
catch (Exception) | ||
{ | ||
// Do nothing, we delete on a best effort basis. | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
storagetransfer/api/StorageTransfer.Samples.Tests/DownloadToPosixTest.cs
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,83 @@ | ||
// Copyright 2024 Google LLC | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// Licensed 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 | ||
// | ||
// https://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. | ||
|
||
using Google.Cloud.Storage.V1; | ||
using Google.Cloud.StorageTransfer.V1; | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace StorageTransfer.Samples.Tests; | ||
|
||
[Collection(nameof(StorageFixture))] | ||
public class DownloadToPosixTest : IDisposable | ||
{ | ||
private readonly StorageFixture _fixture; | ||
private string _transferJobName; | ||
private readonly string _tempDirectory; | ||
private readonly string _gcsSourcePath; | ||
private readonly string _bucketNamePosixSource; | ||
|
||
public DownloadToPosixTest(StorageFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
_bucketNamePosixSource = _fixture.GenerateBucketName(); | ||
_fixture.CreateBucketAndGrantStsPermissions(_bucketNamePosixSource); | ||
_tempDirectory = _fixture.GenerateTempFolderPath(); | ||
_gcsSourcePath = $"{Guid.NewGuid()}/{Guid.NewGuid()}/"; | ||
UploadObjectToPosixBucket(_bucketNamePosixSource); | ||
} | ||
|
||
[Fact] | ||
public void DownloadToPosix() | ||
{ | ||
DownloadToPosixSample downloadToPosixSample = new DownloadToPosixSample(); | ||
Directory.CreateDirectory(_tempDirectory); | ||
var transferJob = downloadToPosixSample.DownloadToPosix(_fixture.ProjectId, _fixture.SinkAgentPoolName, _bucketNamePosixSource, _gcsSourcePath, _tempDirectory); | ||
Assert.Contains("transferJobs/", transferJob.Name); | ||
Assert.True(Directory.Exists(_tempDirectory)); | ||
_transferJobName = transferJob.Name; | ||
} | ||
|
||
private void UploadObjectToPosixBucket(string bucketName) | ||
{ | ||
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes($@"{Guid.NewGuid()}.jpeg"); | ||
MemoryStream stream = new MemoryStream(byteArray); | ||
string fileName = $"{_gcsSourcePath}{DateTime.Now.ToString("yyyyMMddHHmmss")}.txt"; | ||
_fixture.Storage.UploadObject(bucketName, fileName, "application/octet-stream", stream); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
try | ||
{ | ||
_fixture.Sts.UpdateTransferJob(new UpdateTransferJobRequest() | ||
{ | ||
ProjectId = _fixture.ProjectId, | ||
JobName = _transferJobName, | ||
TransferJob = new TransferJob() | ||
{ | ||
Name = _transferJobName, | ||
Status = TransferJob.Types.Status.Deleted | ||
} | ||
}); | ||
Directory.Delete(_tempDirectory, true); | ||
_fixture.Storage.DeleteBucket(_bucketNamePosixSource, new DeleteBucketOptions { DeleteObjects = true }); | ||
} | ||
catch (Exception) | ||
{ | ||
// Do nothing, we delete on a best effort basis. | ||
} | ||
} | ||
} |
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
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.
Reviewed and looks good.