-
Notifications
You must be signed in to change notification settings - Fork 2.9k
STS Azure sample #7529
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
Merged
Merged
STS Azure sample #7529
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dcc5f44
STS Azure samples
JesseLovelace ce7b39f
use python in run script
JesseLovelace 009d6f0
adjust run script
JesseLovelace 72577d3
fix python script
JesseLovelace bf28933
fix variable reference
JesseLovelace cac4703
fix lint
JesseLovelace b4f90ee
address review comments
JesseLovelace 0122a02
fix azure acc example
JesseLovelace 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
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
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
112 changes: 112 additions & 0 deletions
112
...fer/src/main/java/com/google/cloud/storage/storagetransfer/samples/TransferFromAzure.java
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 |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright 2022 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. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage.storagetransfer.samples; | ||
|
|
||
| // [START storagetransfer_transfer_from_azure] | ||
| import com.google.storagetransfer.v1.proto.StorageTransferServiceClient; | ||
| import com.google.storagetransfer.v1.proto.TransferProto; | ||
| import com.google.storagetransfer.v1.proto.TransferProto.RunTransferJobRequest; | ||
| import com.google.storagetransfer.v1.proto.TransferTypes.AzureBlobStorageData; | ||
| import com.google.storagetransfer.v1.proto.TransferTypes.AzureCredentials; | ||
| import com.google.storagetransfer.v1.proto.TransferTypes.GcsData; | ||
| import com.google.storagetransfer.v1.proto.TransferTypes.TransferJob; | ||
| import com.google.storagetransfer.v1.proto.TransferTypes.TransferJob.Status; | ||
| import com.google.storagetransfer.v1.proto.TransferTypes.TransferSpec; | ||
| import java.io.IOException; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| public class TransferFromAzure { | ||
| public static void main(String[] args) | ||
| throws IOException, ExecutionException, InterruptedException { | ||
| // TODO(developer): Replace these variables before running the sample. | ||
| // Your Google Cloud Project ID | ||
| String projectId = "my-project-id"; | ||
|
|
||
| // Your Azure Storage Account name | ||
| String azureStorageAccount = "my-azure-account"; | ||
|
|
||
| // The Azure source container to transfer data from | ||
| String azureSourceContainer = "my-source-container"; | ||
|
|
||
| // The GCS bucket to transfer data to | ||
| String gcsSinkBucket = "my-sink-bucket"; | ||
|
|
||
| transferFromAzureBlobStorage( | ||
| projectId, azureStorageAccount, azureSourceContainer, gcsSinkBucket); | ||
| } | ||
|
|
||
| /** | ||
| * Creates and runs a transfer job to transfer all data from an Azure container to a GCS bucket. | ||
| */ | ||
| public static void transferFromAzureBlobStorage(String projectId, String azureStorageAccount, | ||
| String azureSourceContainer, String gcsSinkBucket) | ||
| throws IOException, ExecutionException, InterruptedException { | ||
|
|
||
| // Your Azure SAS token, should be accessed via environment variable | ||
| String azureSasToken = System.getenv("AZURE_SAS_TOKEN"); | ||
|
|
||
| TransferSpec transferSpec = TransferSpec.newBuilder() | ||
| .setAzureBlobStorageDataSource( | ||
| AzureBlobStorageData.newBuilder() | ||
| .setAzureCredentials(AzureCredentials.newBuilder() | ||
| .setSasToken(azureSasToken) | ||
| .build()) | ||
| .setContainer(azureSourceContainer) | ||
| .setStorageAccount(azureStorageAccount)) | ||
| .setGcsDataSink(GcsData.newBuilder().setBucketName(gcsSinkBucket).build()) | ||
| .build(); | ||
|
|
||
| TransferJob transferJob = | ||
| TransferJob.newBuilder() | ||
| .setProjectId(projectId) | ||
| .setStatus(Status.ENABLED) | ||
| .setTransferSpec(transferSpec) | ||
| .build(); | ||
|
|
||
| // Initialize client that will be used to send requests. This client only needs to be created | ||
| // once, and can be reused for multiple requests. After completing all of your requests, call | ||
| // the "close" method on the client to safely clean up any remaining background resources, | ||
| // or use "try-with-close" statement to do this automatically. | ||
| try (StorageTransferServiceClient storageTransfer = StorageTransferServiceClient.create()) { | ||
| // Create the transfer job | ||
| TransferJob response = | ||
| storageTransfer.createTransferJob(TransferProto.CreateTransferJobRequest.newBuilder() | ||
| .setTransferJob(transferJob) | ||
| .build()); | ||
|
|
||
| // Run the created job | ||
| storageTransfer | ||
| .runTransferJobAsync( | ||
| RunTransferJobRequest.newBuilder() | ||
| .setProjectId(projectId) | ||
| .setJobName(response.getName()) | ||
| .build()) | ||
| .get(); | ||
|
|
||
| System.out.println( | ||
Sita04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Created and ran a transfer job from " | ||
| + azureSourceContainer | ||
| + " to " | ||
| + gcsSinkBucket | ||
| + " with " | ||
| + "name " | ||
| + response.getName()); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| // [END storagetransfer_transfer_from_azure] | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.