Skip to content
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

Add samples for Data Catalog lookupEntry #1449

Merged
merged 6 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .kokoro/datacatalog/cloud-client/lookup-entry.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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"
}

# Specify the project that 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"
}
19 changes: 19 additions & 0 deletions datacatalog/cloud-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# 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 <projectId> <datasetId> Lookup a dataset entry.


For more information, see https://cloud.google.com/data-catalog/docs/
53 changes: 53 additions & 0 deletions datacatalog/cloud-client/lookupEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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 <projectId> <datasetID>
main(...process.argv.slice(2));
34 changes: 34 additions & 0 deletions datacatalog/cloud-client/package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
35 changes: 35 additions & 0 deletions datacatalog/cloud-client/system-test/datacatalog.test.js
Original file line number Diff line number Diff line change
@@ -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));
});