From 048497166f3ac8747020a17e2ff549353a73112f Mon Sep 17 00:00:00 2001 From: mesmacosta Date: Tue, 13 Aug 2019 19:51:33 -0300 Subject: [PATCH 1/6] ADD Datacatalog structure and lookupEntry samples --- datacatalog/cloud-client/README.md | 19 +++++++ datacatalog/cloud-client/lookupEntry.js | 52 +++++++++++++++++++ datacatalog/cloud-client/package.json | 34 ++++++++++++ .../system-test/datacatalog.test.js | 35 +++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 datacatalog/cloud-client/README.md create mode 100644 datacatalog/cloud-client/lookupEntry.js create mode 100644 datacatalog/cloud-client/package.json create mode 100644 datacatalog/cloud-client/system-test/datacatalog.test.js diff --git a/datacatalog/cloud-client/README.md b/datacatalog/cloud-client/README.md new file mode 100644 index 0000000000..66f2f614d1 --- /dev/null +++ b/datacatalog/cloud-client/README.md @@ -0,0 +1,19 @@ +Google Cloud Platform logo + +# Google Cloud Data Catalog API Node.js Samples + +This directory contains samples for Google Cloud Data Catalog. Google Cloud Data Catalog is a fully managed and scalable metadata management service that empowers organizations to quickly discover, manage, and understand all their data in Google Cloud. + +# Setup + +Run the following command to install the library dependencies for Node.js: + + npm install + +# Running the sample + + Commands: + lookupEntry.js Lookup a dataset entry. + + +For more information, see https://cloud.google.com/data-catalog/docs/ \ No newline at end of file diff --git a/datacatalog/cloud-client/lookupEntry.js b/datacatalog/cloud-client/lookupEntry.js new file mode 100644 index 0000000000..8c30b91872 --- /dev/null +++ b/datacatalog/cloud-client/lookupEntry.js @@ -0,0 +1,52 @@ +/** + * Copyright 2019 Google Inc. All Rights Reserved. + * 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'; + +/** + * This application demonstrates how to perform lookup operations with the + * Cloud Data Catalog API. + + * For more information, see the README.md under /datacatalog and the + * documentation at https://cloud.google.com/data-catalog/docs. + */ +function main( + projectId = process.env.GCLOUD_PROJECT, + datasetId = process.env.GCLOUD_DATASET_ID +) { + + // [START datacatalog_lookup_dataset] + // ------------------------------- + // Import required modules. + // ------------------------------- + const { DataCatalogClient } = require('@google-cloud/datacatalog').v1beta1; + const datacatalog = new DataCatalogClient(); + + async function lookup() { + // TODO(developer): Uncomment the following lines before running the sample. + // const projectId = 'my-project' + // const datasetId = 'my_dataset' + const resourceName = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; + const request = { linkedResource: resourceName }; + const [result] = await datacatalog.lookupEntry(request); + return result; + } + + lookup().then(response => { console.log(response) }); + // [END datacatalog_lookup_dataset] +} + +// node lookupEntry.js +main(...process.argv.slice(2)); diff --git a/datacatalog/cloud-client/package.json b/datacatalog/cloud-client/package.json new file mode 100644 index 0000000000..51e526f6e9 --- /dev/null +++ b/datacatalog/cloud-client/package.json @@ -0,0 +1,34 @@ +{ + "name": "@google-cloud/datacatalog-samples", + "version": "0.0.1", + "private": true, + "description": "Samples for the Cloud Data Catalog client library for Node.js", + "license": "Apache-2.0", + "author": "Google LLC", + "repository": "GoogleCloudPlatform/nodejs-docs-samples", + "engines": { + "node": ">=8.0.0" + }, + "scripts": { + "test": "mocha system-test/*.test.js --timeout=60000" + }, + "devDependencies": { + "@google-cloud/nodejs-repo-tools": "^3.3.0", + "mocha": "^6.0.0" + }, + "dependencies": { + "@google-cloud/datacatalog": "^1.0.1" + }, + "cloud-repo-tools": { + "requiresKeyFile": true, + "requiresProjectId": true, + "test": { + "build": { + "requiredEnvVars": [ + "GCLOUD_PROJECT", + "GCLOUD_DATASET_ID" + ] + } + } + } +} diff --git a/datacatalog/cloud-client/system-test/datacatalog.test.js b/datacatalog/cloud-client/system-test/datacatalog.test.js new file mode 100644 index 0000000000..910e787645 --- /dev/null +++ b/datacatalog/cloud-client/system-test/datacatalog.test.js @@ -0,0 +1,35 @@ +/** + * Copyright 2019 Google Inc. All Rights Reserved. + * 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'; + +const path = require('path'); +const assert = require('assert'); +const tools = require('@google-cloud/nodejs-repo-tools'); + +const cwd = path.join(__dirname, '..'); +const projectId = process.env.GCLOUD_PROJECT; +const datasetId = process.env.GCLOUD_DATASET_ID; + +before(tools.checkCredentials); + +it('should lookup a dataset entry', async () => { + const output = await tools.runAsync( + `node lookupEntry.js ${projectId} ${datasetId}`, + cwd + ); + const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}` + assert.ok(output.includes(expectedLinkedResource)); +}); \ No newline at end of file From 3261f5bcfe83b6a1be90575be728dd9dd50eb3d5 Mon Sep 17 00:00:00 2001 From: mesmacosta Date: Wed, 14 Aug 2019 09:54:59 -0300 Subject: [PATCH 2/6] ADD .koroko config --- .kokoro/datacatalog/cloud-client/lookup-entry.cfg | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .kokoro/datacatalog/cloud-client/lookup-entry.cfg diff --git a/.kokoro/datacatalog/cloud-client/lookup-entry.cfg b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg new file mode 100644 index 0000000000..422aeeaec4 --- /dev/null +++ b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Set the folder in which the tests are run +env_vars: { + key: "PROJECT" + value: "datacatalog/cloud-client" +} + +# Tell the trampoline which build file to use. +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/nodejs-docs-samples/.kokoro/build.sh" +} From 8958d642d751a4c326d4c398d613fa7a3b1ad629 Mon Sep 17 00:00:00 2001 From: mesmacosta Date: Wed, 14 Aug 2019 11:44:27 -0300 Subject: [PATCH 3/6] Set a public project and dataset to be used in system-tests --- .kokoro/datacatalog/cloud-client/lookup-entry.cfg | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.kokoro/datacatalog/cloud-client/lookup-entry.cfg b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg index 422aeeaec4..717a758bd4 100644 --- a/.kokoro/datacatalog/cloud-client/lookup-entry.cfg +++ b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg @@ -11,3 +11,15 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/nodejs-docs-samples/.kokoro/build.sh" } + +# Specify the project the contains a valid dataset +env_vars: { + key: "GCLOUD_PROJECT" + value: "bigquery-public-data" +} + +# Specify the dataset related to the project +env_vars: { + key: "GCLOUD_DATASET_ID" + value: "new_york_taxi_trips" +} \ No newline at end of file From 1c3e5ee0f49e649710a1a362275f74fc4db70fb9 Mon Sep 17 00:00:00 2001 From: mesmacosta Date: Wed, 14 Aug 2019 11:45:54 -0300 Subject: [PATCH 4/6] FIX typo --- .kokoro/datacatalog/cloud-client/lookup-entry.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.kokoro/datacatalog/cloud-client/lookup-entry.cfg b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg index 717a758bd4..e7dae3099d 100644 --- a/.kokoro/datacatalog/cloud-client/lookup-entry.cfg +++ b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg @@ -12,13 +12,13 @@ env_vars: { value: "github/nodejs-docs-samples/.kokoro/build.sh" } -# Specify the project the contains a valid dataset +# Specify the project that contains a valid dataset. env_vars: { key: "GCLOUD_PROJECT" value: "bigquery-public-data" } -# Specify the dataset related to the project +# Specify the dataset related to the project. env_vars: { key: "GCLOUD_DATASET_ID" value: "new_york_taxi_trips" From c34fbe3f54f04b13d3afa19d2662191831c15a31 Mon Sep 17 00:00:00 2001 From: mesmacosta Date: Wed, 14 Aug 2019 13:03:38 -0300 Subject: [PATCH 5/6] FIX eslint errors --- datacatalog/cloud-client/lookupEntry.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/datacatalog/cloud-client/lookupEntry.js b/datacatalog/cloud-client/lookupEntry.js index 8c30b91872..52c59f2820 100644 --- a/datacatalog/cloud-client/lookupEntry.js +++ b/datacatalog/cloud-client/lookupEntry.js @@ -1,4 +1,4 @@ -/** +/** * Copyright 2019 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,12 +26,11 @@ function main( projectId = process.env.GCLOUD_PROJECT, datasetId = process.env.GCLOUD_DATASET_ID ) { - // [START datacatalog_lookup_dataset] // ------------------------------- // Import required modules. // ------------------------------- - const { DataCatalogClient } = require('@google-cloud/datacatalog').v1beta1; + const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; const datacatalog = new DataCatalogClient(); async function lookup() { @@ -39,12 +38,14 @@ function main( // const projectId = 'my-project' // const datasetId = 'my_dataset' const resourceName = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; - const request = { linkedResource: resourceName }; + const request = {linkedResource: resourceName}; const [result] = await datacatalog.lookupEntry(request); return result; } - lookup().then(response => { console.log(response) }); + lookup().then(response => { + console.log(response); + }); // [END datacatalog_lookup_dataset] } From 45ffdca1ff8da7687ee2b018a5a2c8f193370e90 Mon Sep 17 00:00:00 2001 From: mesmacosta Date: Wed, 14 Aug 2019 13:13:40 -0300 Subject: [PATCH 6/6] FIX eslint issues on test file --- datacatalog/cloud-client/system-test/datacatalog.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datacatalog/cloud-client/system-test/datacatalog.test.js b/datacatalog/cloud-client/system-test/datacatalog.test.js index 910e787645..621c61d9f5 100644 --- a/datacatalog/cloud-client/system-test/datacatalog.test.js +++ b/datacatalog/cloud-client/system-test/datacatalog.test.js @@ -1,4 +1,4 @@ -/** +/** * Copyright 2019 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,6 @@ it('should lookup a dataset entry', async () => { `node lookupEntry.js ${projectId} ${datasetId}`, cwd ); - const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}` + const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; assert.ok(output.includes(expectedLinkedResource)); -}); \ No newline at end of file +});