Node.js용 Azure SDK를 사용하여 Azure 데이터 레이크 분석 관리Manage Azure Data Lake Analytics using Azure SDK for Node.js

이 문서에서는 Node.js용 Azure SDK를 사용하여 작성된 앱을 사용하여 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 분석 클라이언트 만들기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 분석 계정 만들기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 분석 카탈로그에서 데이터베이스 목록 가져오기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