azure-arm-datalake-store
Version:
Microsoft Azure Data Lake Store Management Client Library for node
1,117 lines (1,088 loc) • 248 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
*/
'use strict';
const msRest = require('ms-rest');
const msRestAzure = require('ms-rest-azure');
const WebResource = msRest.WebResource;
/**
* Sets or removes the expiration time on the specified file. This operation
* can only be executed against files. Folders are not supported.
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* file on which to set or remove the expiration time.
*
* @param {string} expiryOption Indicates the type of expiration to use for the
* file: 1. NeverExpire: ExpireTime is ignored. 2. RelativeToNow: ExpireTime is
* an integer in milliseconds representing the expiration date relative to when
* file expiration is updated. 3. RelativeToCreationDate: ExpireTime is an
* integer in milliseconds representing the expiration date relative to file
* creation. 4. Absolute: ExpireTime is an integer in milliseconds, as a Unix
* timestamp relative to 1/1/1970 00:00:00. Possible values include:
* 'NeverExpire', 'RelativeToNow', 'RelativeToCreationDate', 'Absolute'
*
* @param {object} [options] Optional Parameters.
*
* @param {number} [options.expireTime] The time that the file will expire,
* corresponding to the ExpiryOption that was set.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {null} [result] - The deserialized result object if an error did not occur.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _setFileExpiry(accountName, path, expiryOption, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let expireTime = (options && options.expireTime !== undefined) ? options.expireTime : undefined;
let op = 'SETEXPIRY';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (expiryOption) {
let allowedValues = [ 'NeverExpire', 'RelativeToNow', 'RelativeToCreationDate', 'Absolute' ];
if (!allowedValues.some( function(item) { return item === expiryOption; })) {
throw new Error(expiryOption + ' is not a valid value. The valid values are: ' + allowedValues);
}
} else {
throw new Error('expiryOption cannot be null or undefined.');
}
if (expireTime !== null && expireTime !== undefined && typeof expireTime !== 'number') {
throw new Error('expireTime must be of type number.');
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'WebHdfsExt/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
queryParameters.push('expiryOption=' + encodeURIComponent(expiryOption));
if (expireTime !== null && expireTime !== undefined) {
queryParameters.push('expireTime=' + encodeURIComponent(expireTime.toString()));
}
queryParameters.push('op=' + encodeURIComponent(op));
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'PUT';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
let internalError = null;
if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
error.code = internalError ? internalError.code : parsedErrorResponse.code;
error.message = internalError ? internalError.message : parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['AdlsError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Appends to the specified file, optionally first creating the file if it does
* not yet exist. This method supports multiple concurrent appends to the file.
* NOTE: The target must not contain data added by Create or normal (serial)
* Append. ConcurrentAppend and Append cannot be used interchangeably; once a
* target file has been modified using either of these append options, the
* other append option cannot be used on the target file. ConcurrentAppend does
* not guarantee order and can result in duplicated data landing in the target
* file.
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* file to which to append using concurrent append.
*
* @param {object} streamContents The file contents to include when appending
* to the file. The maximum content size is 4MB. For content larger than 4MB
* you must append the content in 4MB chunks.
*
* @param {object} [options] Optional Parameters.
*
* @param {string} [options.appendMode] Indicates the concurrent append call
* should create the file if it doesn't exist or just open the existing file
* for append. Possible values include: 'autocreate'
*
* @param {string} [options.syncFlag] Optionally indicates what to do after
* completion of the concurrent append. DATA indicates that more data will be
* sent immediately by the client, the file handle should remain open/locked,
* and file metadata (including file length, last modified time) should NOT get
* updated. METADATA indicates that more data will be sent immediately by the
* client, the file handle should remain open/locked, and file metadata should
* get updated. CLOSE indicates that the client is done sending data, the file
* handle should be closed/unlocked, and file metadata should get updated.
* Possible values include: 'DATA', 'METADATA', 'CLOSE'
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {null} [result] - The deserialized result object if an error did not occur.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _concurrentAppend(accountName, path, streamContents, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let appendMode = (options && options.appendMode !== undefined) ? options.appendMode : undefined;
let syncFlag = (options && options.syncFlag !== undefined) ? options.syncFlag : 'DATA';
let op = 'CONCURRENTAPPEND';
let transferEncoding = 'chunked';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (streamContents === null || streamContents === undefined) {
throw new Error('streamContents cannot be null or undefined and it must be of type object.');
}
if (appendMode) {
let allowedValues = [ 'autocreate' ];
if (!allowedValues.some( function(item) { return item === appendMode; })) {
throw new Error(appendMode + ' is not a valid value. The valid values are: ' + allowedValues);
}
}
if (syncFlag) {
let allowedValues1 = [ 'DATA', 'METADATA', 'CLOSE' ];
if (!allowedValues1.some( function(item) { return item === syncFlag; })) {
throw new Error(syncFlag + ' is not a valid value. The valid values are: ' + allowedValues1);
}
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'WebHdfsExt/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
if (appendMode !== null && appendMode !== undefined) {
queryParameters.push('appendMode=' + encodeURIComponent(appendMode));
}
queryParameters.push('op=' + encodeURIComponent(op));
if (syncFlag !== null && syncFlag !== undefined) {
queryParameters.push('syncFlag=' + encodeURIComponent(syncFlag));
}
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'POST';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/octet-stream';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (transferEncoding !== undefined && transferEncoding !== null) {
httpRequest.headers['Transfer-Encoding'] = transferEncoding;
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
// Serialize Request
let requestContent = streamContents;
httpRequest.body = requestContent;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
let internalError = null;
if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
error.code = internalError ? internalError.code : parsedErrorResponse.code;
error.message = internalError ? internalError.message : parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['AdlsError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Checks if the specified access is available at the given path.
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* file or directory for which to check access.
*
* @param {string} fsaction File system operation read/write/execute in string
* form, matching regex pattern '[rwx-]{3}'
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {null} [result] - The deserialized result object if an error did not occur.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _checkAccess(accountName, path, fsaction, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let op = 'CHECKACCESS';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (fsaction === null || fsaction === undefined || typeof fsaction.valueOf() !== 'string') {
throw new Error('fsaction cannot be null or undefined and it must be of type string.');
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'webhdfs/v1/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
queryParameters.push('fsaction=' + encodeURIComponent(fsaction));
queryParameters.push('op=' + encodeURIComponent(op));
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
let internalError = null;
if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
error.code = internalError ? internalError.code : parsedErrorResponse.code;
error.message = internalError ? internalError.message : parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['AdlsError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Creates a directory.
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* directory to create.
*
* @param {object} [options] Optional Parameters.
*
* @param {number} [options.permission] Optional octal permission with which
* the directory should be created.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link FileOperationResult} for more information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _mkdirs(accountName, path, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let permission = (options && options.permission !== undefined) ? options.permission : undefined;
let op = 'MKDIRS';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (permission !== null && permission !== undefined && typeof permission !== 'number') {
throw new Error('permission must be of type number.');
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'webhdfs/v1/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
if (permission !== null && permission !== undefined) {
queryParameters.push('permission=' + encodeURIComponent(permission.toString()));
}
queryParameters.push('op=' + encodeURIComponent(op));
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'PUT';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
let internalError = null;
if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
error.code = internalError ? internalError.code : parsedErrorResponse.code;
error.message = internalError ? internalError.message : parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['AdlsError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
// Deserialize Response
if (statusCode === 200) {
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['FileOperationResult']().mapper();
result = client.deserialize(resultMapper, parsedResponse, 'result');
}
} catch (error) {
let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
deserializationError.request = msRest.stripRequest(httpRequest);
deserializationError.response = msRest.stripResponse(response);
return callback(deserializationError);
}
}
return callback(null, result, httpRequest, response);
});
}
/**
* Concatenates the list of source files into the destination file, removing
* all source files upon success.
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* destination file resulting from the concatenation.
*
* @param {array} sources A list of comma separated Data Lake Store paths
* (starting with '/') of the files to concatenate, in the order in which they
* should be concatenated.
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {null} [result] - The deserialized result object if an error did not occur.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _concat(accountName, path, sources, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let op = 'CONCAT';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (!Array.isArray(sources)) {
throw new Error('sources cannot be null or undefined and it must be of type array.');
}
for (let i = 0; i < sources.length; i++) {
if (sources[i] !== null && sources[i] !== undefined && typeof sources[i].valueOf() !== 'string') {
throw new Error('sources[i] must be of type string.');
}
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'webhdfs/v1/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
queryParameters.push('sources=' + encodeURIComponent(sources.join(',')));
queryParameters.push('op=' + encodeURIComponent(op));
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'POST';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
let internalError = null;
if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
error.code = internalError ? internalError.code : parsedErrorResponse.code;
error.message = internalError ? internalError.message : parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['AdlsError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Concatenates the list of source files into the destination file, deleting
* all source files upon success. This method accepts more source file paths
* than the Concat method. This method and the parameters it accepts are
* subject to change for usability in an upcoming version.
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* destination file resulting from the concatenation.
*
* @param {object} streamContents A list of Data Lake Store paths (starting
* with '/') of the source files. Must be a comma-separated path list in the
* format: sources=/file/path/1.txt,/file/path/2.txt,/file/path/lastfile.csv
*
* @param {object} [options] Optional Parameters.
*
* @param {boolean} [options.deleteSourceDirectory] Indicates that as an
* optimization instead of deleting each individual source stream, delete the
* source stream folder if all streams are in the same folder instead. This
* results in a substantial performance improvement when the only streams in
* the folder are part of the concatenation operation. WARNING: This includes
* the deletion of any other files that are not source files. Only set this to
* true when source files are the only files in the source directory.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {null} [result] - The deserialized result object if an error did not occur.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _msConcat(accountName, path, streamContents, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let deleteSourceDirectory = (options && options.deleteSourceDirectory !== undefined) ? options.deleteSourceDirectory : undefined;
let op = 'MSCONCAT';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (deleteSourceDirectory !== null && deleteSourceDirectory !== undefined && typeof deleteSourceDirectory !== 'boolean') {
throw new Error('deleteSourceDirectory must be of type boolean.');
}
if (streamContents === null || streamContents === undefined) {
throw new Error('streamContents cannot be null or undefined and it must be of type object.');
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'webhdfs/v1/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
if (deleteSourceDirectory !== null && deleteSourceDirectory !== undefined) {
queryParameters.push('deleteSourceDirectory=' + encodeURIComponent(deleteSourceDirectory.toString()));
}
queryParameters.push('op=' + encodeURIComponent(op));
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'POST';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/octet-stream';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
// Serialize Request
let requestContent = streamContents;
httpRequest.body = requestContent;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
let internalError = null;
if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
error.code = internalError ? internalError.code : parsedErrorResponse.code;
error.message = internalError ? internalError.message : parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['AdlsError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Get the list of file status objects specified by the file path, with
* optional pagination parameters
*
* @param {string} accountName The Azure Data Lake Store account to execute
* filesystem operations on.
*
* @param {string} path The Data Lake Store path (starting with '/') of the
* directory to list.
*
* @param {object} [options] Optional Parameters.
*
* @param {number} [options.listSize] Gets or sets the number of items to
* return. Optional.
*
* @param {string} [options.listAfter] Gets or sets the item or lexographical
* index after which to begin returning results. For example, a file list of
* 'a','b','d' and listAfter='b' will return 'd', and a listAfter='c' will also
* return 'd'. Optional.
*
* @param {string} [options.listBefore] Gets or sets the item or lexographical
* index before which to begin returning results. For example, a file list of
* 'a','b','d' and listBefore='d' will return 'a','b', and a listBefore='c'
* will also return 'a','b'. Optional.
*
* @param {boolean} [options.tooId] An optional switch to return friendly names
* in place of owner and group. tooid=false returns friendly names instead of
* the AAD Object ID. Default value is true, returning AAD object IDs.
*
* @param {object} [options.customHeaders] Headers that will be added to the
* request
*
* @param {function} callback - The callback.
*
* @returns {function} callback(err, result, request, response)
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {object} [result] - The deserialized result object if an error did not occur.
* See {@link FileStatusesResult} for more information.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
* {stream} [response] - The HTTP Response stream if an error did not occur.
*/
function _listFileStatus(accountName, path, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
let listSize = (options && options.listSize !== undefined) ? options.listSize : undefined;
let listAfter = (options && options.listAfter !== undefined) ? options.listAfter : undefined;
let listBefore = (options && options.listBefore !== undefined) ? options.listBefore : undefined;
let tooId = (options && options.tooId !== undefined) ? options.tooId : undefined;
let op = 'LISTSTATUS';
// Validate
try {
if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
throw new Error('accountName cannot be null or undefined and it must be of type string.');
}
if (this.client.adlsFileSystemDnsSuffix === null || this.client.adlsFileSystemDnsSuffix === undefined || typeof this.client.adlsFileSystemDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlsFileSystemDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (path === null || path === undefined || typeof path.valueOf() !== 'string') {
throw new Error('path cannot be null or undefined and it must be of type string.');
}
if (listSize !== null && listSize !== undefined && typeof listSize !== 'number') {
throw new Error('listSize must be of type number.');
}
if (listAfter !== null && listAfter !== undefined && typeof listAfter.valueOf() !== 'string') {
throw new Error('listAfter must be of type string.');
}
if (listBefore !== null && listBefore !== undefined && typeof listBefore.valueOf() !== 'string') {
throw new Error('listBefore must be of type string.');
}
if (tooId !== null && tooId !== undefined && typeof tooId !== 'boolean') {
throw new Error('tooId must be of type boolean.');
}
if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
}
if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.client.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
// Construct URL
let baseUrl = this.client.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'webhdfs/v1/{path}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlsFileSystemDnsSuffix}', this.client.adlsFileSystemDnsSuffix);
requestUrl = requestUrl.replace('{path}', encodeURIComponent(path));
let queryParameters = [];
if (listSize !== null && listSize !== undefined) {
queryParameters.push('listSize=' + encodeURIComponent(listSize.toString()));
}
if (listAfter !== null && listAfter !== undefined) {
queryParameters.push('listAfter=' + encodeURIComponent(listAfter));
}
if (listBefore !== null && listBefore !== undefined) {
queryParameters.push('listBefore=' + encodeURIComponent(listBefore));
}
if (tooId !== null && tooId !== undefined) {
queryParameters.push('tooId=' + encodeURIComponent(tooId.toString()));
}
queryParameters.push('op=' + encodeURIComponent(op));
queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
if (queryParameters.length > 0) {
requestUrl += '?' + queryParameters.join('&');
}
// Create HTTP transport objects
let httpRequest = new WebResource();
httpRequest.method = 'GET';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(