This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
feat(samples): Add POSIX & Manifest samples #67
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7ace33d
feat(samples): Add POSIX samples
d-goog 612b850
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 7cc13dd
Fix: `fs.promises` import
d-goog 8e4e6d1
Merge branch 'posix-samples' of https://github.com/googleapis/nodejs-…
d-goog e1696d1
fix: clean-up created transfer job
d-goog 0951983
chore: Add (safe) debug log
d-goog 4a47cd5
fix: misc bugs
d-goog 6236e9e
chore: remove debug log
d-goog 86301e0
feat: add POSIX to POSIX sample
d-goog 1946b0c
chore: typo & clean-up
d-goog 7215ff6
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] cbf6aae
refactor: styling
d-goog 28308ed
Merge branch 'posix-samples' of https://github.com/googleapis/nodejs-…
d-goog ba86cae
feat: Add POSIX Download sample
d-goog d613f20
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 9b08257
fix: Add ending '/'
d-goog dc22f57
style: shorten variable
d-goog bc80220
feat: Transfer Manifest request
d-goog ab5dafa
fix: typo
d-goog de8d929
Merge branch 'main' of https://github.com/googleapis/nodejs-storage-t…
d-goog 28bb7cf
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 12dc353
Merge branch 'posix-samples' of https://github.com/googleapis/nodejs-…
gcf-owl-bot[bot] 9b199ac
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 87c8161
Merge branch 'posix-samples' of https://github.com/googleapis/nodejs-…
gcf-owl-bot[bot] 233441c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 56be733
Merge branch 'posix-samples' of https://github.com/googleapis/nodejs-…
gcf-owl-bot[bot] 87c90a2
fix: `replaceAll` (not available in Node 12) -> `replace`
d-goog b7a99ca
Merge branch 'posix-samples' of https://github.com/googleapis/nodejs-…
d-goog 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Copyright 2022 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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
sourceAgentPoolName = '', | ||
rootDirectory = '', | ||
gcsSinkBucket = '', | ||
manifestLocation = '' | ||
) { | ||
// [START storagetransfer_manifest_request] | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
StorageTransferServiceClient, | ||
} = require('@google-cloud/storage-transfer'); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// Your project id | ||
// const projectId = 'my-project' | ||
|
||
// The agent pool associated with the POSIX data source. Defaults to the default agent | ||
// const sourceAgentPoolName = 'projects/my-project/agentPools/transfer_service_default' | ||
|
||
// The root directory path on the source filesystem | ||
// const rootDirectory = '/directory/to/transfer/source', | ||
|
||
// The ID of the GCS bucket to transfer data to | ||
// const gcsSinkBucket = 'my-sink-bucket' | ||
|
||
// Transfer manifest location. Must be a | ||
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. Must be a what? |
||
// const manifestLocation = 'gs://my-bucket/sample_manifest.csv' | ||
|
||
// Creates a client | ||
const client = new StorageTransferServiceClient(); | ||
|
||
/** | ||
* Creates a request to transfer from the local file system to the sink bucket | ||
*/ | ||
async function transferDirectory() { | ||
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. Is "transferDirectory" the right name for this function? This only transfers the files specified in the manifest right? which may not be the entire directory if i understand it correctly, and may in fact include files from multiple directories within the root directory |
||
const createRequest = { | ||
transferJob: { | ||
projectId, | ||
transferSpec: { | ||
sourceAgentPoolName, | ||
posixDataSource: { | ||
rootDirectory, | ||
}, | ||
gcsDataSink: {bucketName: gcsSinkBucket}, | ||
transferManifest: { | ||
location: manifestLocation, | ||
}, | ||
}, | ||
status: 'ENABLED', | ||
}, | ||
}; | ||
|
||
// Runs the request and creates the job | ||
const [transferJob] = await client.createTransferJob(createRequest); | ||
|
||
const runRequest = { | ||
jobName: transferJob.name, | ||
projectId: projectId, | ||
}; | ||
|
||
await client.runTransferJob(runRequest); | ||
|
||
console.log( | ||
`Created and ran a transfer job from '${rootDirectory}' to '${gcsSinkBucket}' using manifest \`${manifestLocation}\` with name ${transferJob.name}` | ||
); | ||
} | ||
|
||
transferDirectory(); | ||
// [END storagetransfer_manifest_request] | ||
} | ||
|
||
main(...process.argv.slice(2)); | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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,99 @@ | ||
/** | ||
* Copyright 2022 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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
sinkAgentPoolName = '', | ||
gcsSourceBucket = '', | ||
gcsSourcePath = '', | ||
rootDirectory = '' | ||
) { | ||
// [START storagetransfer_download_to_posix] | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
StorageTransferServiceClient, | ||
} = require('@google-cloud/storage-transfer'); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// Your project id | ||
// const projectId = 'my-project' | ||
|
||
// The agent pool associated with the POSIX data sink. Defaults to the default agent | ||
// const sinkAgentPoolName = 'projects/my-project/agentPools/transfer_service_default' | ||
|
||
// Google Cloud Storage source bucket name | ||
// const gcsSourceBucket = 'my-gcs-source-bucket' | ||
|
||
// An optional path on the Google Cloud Storage bucket to download from | ||
// const gcsSourcePath = 'foo/bar/' | ||
|
||
// The root directory path on the source filesystem | ||
// const rootDirectory = '/directory/to/transfer/source', | ||
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. trailing comma |
||
|
||
// Creates a client | ||
const client = new StorageTransferServiceClient(); | ||
|
||
/** | ||
* Creates a request to transfer from the local file system to the sink bucket | ||
*/ | ||
async function transferDirectory() { | ||
const createRequest = { | ||
transferJob: { | ||
projectId, | ||
transferSpec: { | ||
sinkAgentPoolName, | ||
gcsDataSource: { | ||
bucketName: gcsSourceBucket, | ||
path: gcsSourcePath, | ||
}, | ||
posixDataSink: { | ||
rootDirectory, | ||
}, | ||
}, | ||
status: 'ENABLED', | ||
}, | ||
}; | ||
|
||
// Runs the request and creates the job | ||
const [transferJob] = await client.createTransferJob(createRequest); | ||
|
||
const runRequest = { | ||
jobName: transferJob.name, | ||
projectId: projectId, | ||
}; | ||
|
||
await client.runTransferJob(runRequest); | ||
|
||
console.log( | ||
`Downloading from '${gcsSourceBucket}' (path: \`${gcsSourcePath}\`) to '${rootDirectory}' with name ${transferJob.name}` | ||
); | ||
} | ||
|
||
transferDirectory(); | ||
// [END storagetransfer_download_to_posix] | ||
} | ||
|
||
main(...process.argv.slice(2)); | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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,92 @@ | ||
/** | ||
* Copyright 2022 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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
sourceAgentPoolName = '', | ||
rootDirectory = '', | ||
gcsSinkBucket = '' | ||
) { | ||
// [START storagetransfer_transfer_from_posix] | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
StorageTransferServiceClient, | ||
} = require('@google-cloud/storage-transfer'); | ||
|
||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// Your project id | ||
// const projectId = 'my-project' | ||
|
||
// The agent pool associated with the POSIX data source. Defaults to the default agent | ||
// const sourceAgentPoolName = 'projects/my-project/agentPools/transfer_service_default' | ||
|
||
// The root directory path on the source filesystem | ||
// const rootDirectory = '/directory/to/transfer/source', | ||
|
||
// The ID of the GCS bucket to transfer data to | ||
// const gcsSinkBucket = 'my-sink-bucket' | ||
|
||
// Creates a client | ||
const client = new StorageTransferServiceClient(); | ||
|
||
/** | ||
* Creates a request to transfer from the local file system to the sink bucket | ||
*/ | ||
async function transferDirectory() { | ||
const createRequest = { | ||
transferJob: { | ||
projectId, | ||
transferSpec: { | ||
sourceAgentPoolName, | ||
posixDataSource: { | ||
rootDirectory, | ||
}, | ||
gcsDataSink: {bucketName: gcsSinkBucket}, | ||
}, | ||
status: 'ENABLED', | ||
}, | ||
}; | ||
|
||
// Runs the request and creates the job | ||
const [transferJob] = await client.createTransferJob(createRequest); | ||
|
||
const runRequest = { | ||
jobName: transferJob.name, | ||
projectId: projectId, | ||
}; | ||
|
||
await client.runTransferJob(runRequest); | ||
|
||
console.log( | ||
`Created and ran a transfer job from '${rootDirectory}' to '${gcsSinkBucket}' with name ${transferJob.name}` | ||
); | ||
} | ||
|
||
transferDirectory(); | ||
// [END storagetransfer_transfer_from_posix] | ||
} | ||
|
||
main(...process.argv.slice(2)); | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
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.
Trailing comma here