Azure SDK for Node.js を使用して Azure Data Lake Analytics を管理するManage Azure Data Lake Analytics using Azure SDK for Node.js

この記事では、Azure SDK for Node.js を使用して記述されたアプリを使用して、Azure Data Lake Analytics のアカウント、データ ソース、ユーザー、ジョブを管理する方法について説明します。This article describes how to manage Azure Data Lake Analytics accounts, data sources, users, and jobs using an app written using the Azure SDK for Node.js.

サポートされるバージョンは次のとおりです。The following versions are supported:

  • Node.js バージョン:0.10.0 以降Node.js version: 0.10.0 or higher
  • アカウント用の REST API のバージョン:2015-10-01-previewREST API version for Account: 2015-10-01-preview
  • カタログ用の REST API のバージョン:2015-10-01-previewREST API version for Catalog: 2015-10-01-preview
  • ジョブ用の REST API のバージョン:2016-03-20-previewREST API version for Job: 2016-03-20-preview

機能Features

  • アカウント管理: 作成、取得、一覧表示、更新、および削除。Account management: create, get, list, update, and delete.
  • ジョブ管理: 送信、取得、一覧表示、および取り消し。Job management: submit, get, list, and cancel.
  • カタログ管理: 取得および一覧表示。Catalog management: get and list.

インストール方法How to Install

npm install azure-arm-datalake-analytics

Azure Active Directory を使用して認証するAuthenticate using Azure Active Directory

var msrestAzure = require('ms-rest-azure');
//user authentication
var credentials = new msRestAzure.UserTokenCredentials('your-client-id', 'your-domain', 'your-username', 'your-password', 'your-redirect-uri');
//service principal authentication
var credentials = new msRestAzure.ApplicationTokenCredentials('your-client-id', 'your-domain', 'your-secret');

Data Lake Analytics クライアントを作成するCreate the Data Lake Analytics client

var adlaManagement = require("azure-arm-datalake-analytics");
var accountClient = new adlaManagement.DataLakeAnalyticsAccountClient(credentials, 'your-subscription-id');
var jobClient = new adlaManagement.DataLakeAnalyticsJobClient(credentials, 'azuredatalakeanalytics.net');
var catalogClient = new adlaManagement.DataLakeAnalyticsCatalogClient(credentials, 'azuredatalakeanalytics.net');

Data Lake Analytics アカウントを作成するCreate a Data Lake Analytics account

var util = require('util');
var resourceGroupName = 'testrg';
var accountName = 'testadlaacct';
var location = 'eastus2';

// A Data Lake Store account must already have been created to create
// a Data Lake Analytics account. See the Data Lake Store readme for
// information on doing so. For now, we assume one exists already.
var datalakeStoreAccountName = 'existingadlsaccount';

// account object to create
var accountToCreate = {
  tags: {
    testtag1: 'testvalue1',
    testtag2: 'testvalue2'
  },
  name: accountName,
  location: location,
  properties: {
    defaultDataLakeStoreAccount: datalakeStoreAccountName,
    dataLakeStoreAccounts: [
      {
        name: datalakeStoreAccountName
      }
    ]
  }
};

client.account.create(resourceGroupName, accountName, accountToCreate, function (err, result, request, response) {
  if (err) {
    console.log(err);
    /*err has reference to the actual request and response, so you can see what was sent and received on the wire.
      The structure of err looks like this:
      err: {
        code: 'Error Code',
        message: 'Error Message',
        body: 'The response body if any',
        request: reference to a stripped version of http request
        response: reference to a stripped version of the response
      }
    */
  } else {
    console.log('result is: ' + util.inspect(result, {depth: null}));
  }
});

ジョブの一覧を取得するGet a list of jobs

var util = require('util');
var accountName = 'testadlaacct';
jobClient.job.list(accountName, function (err, result, request, response) {
  if (err) {
    console.log(err);
  } else {
    console.log('result is: ' + util.inspect(result, {depth: null}));
  }
});

Data Lake Analytics カタログ内のデータベースの一覧を取得するGet a list of databases in the Data Lake Analytics Catalog

var util = require('util');
var accountName = 'testadlaacct';
catalogClient.catalog.listDatabases(accountName, function (err, result, request, response) {
  if (err) {
    console.log(err);
  } else {
    console.log('result is: ' + util.inspect(result, {depth: null}));
  }
});

関連項目See also