lib/services/batch/lib/operations/pool.js
/**
 * @summary Lists the usage metrics, aggregated by pool across individual time
 * intervals, for the specified account.
 *
 * If you do not specify a $filter clause including a poolId, the response
 * includes all pools that existed in the account in the time range of the
 * returned aggregation intervals. If you do not specify a $filter clause
 * including a startTime or endTime these filters default to the start and end
 * times of the last aggregation interval currently available; that is, only
 * the last aggregation interval is returned.
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.poolListUsageMetricsNextOptions] Additional
 * parameters for the operation
 *
 * @param {uuid} [options.poolListUsageMetricsNextOptions.clientRequestId] The
 * caller-generated request identity, in the form of a GUID with no decoration
 * such as curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
 *
 * @param {boolean}
 * [options.poolListUsageMetricsNextOptions.returnClientRequestId] Whether the
 * server should return the client-request-id in the response.
 *
 * @param {date} [options.poolListUsageMetricsNextOptions.ocpDate] The time the
 * request was issued. Client libraries typically set this to the current
 * system clock time; set it explicitly if you are calling the REST API
 * directly.
 *
 * @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 PoolListUsageMetricsResult} 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.
 */
@summary Lists the usage metrics, aggregated by pool across individual time
intervals, for the specified account.

If you do not specify a $filter clause including a poolId, the response
includes all pools that existed in the account in the time range of the
returned aggregation intervals. If you do not specify a $filter clause
including a startTime or endTime these filters default to the start and end
times of the last aggregation interval currently available; that is, only
the last aggregation interval is returned.

@param {string} nextPageLink The NextLink from the previous successful call
to List operation.

@param {object} [options] Optional Parameters.

@param {object} [options.poolListUsageMetricsNextOptions] Additional
parameters for the operation

@param {uuid} [options.poolListUsageMetricsNextOptions.clientRequestId] The
caller-generated request identity, in the form of a GUID with no decoration
such as curly braces, e.g.

@param {boolean}
[options.poolListUsageMetricsNextOptions.returnClientRequestId] Whether the
server should return the client-request-id in the response.

@param {date} [options.poolListUsageMetricsNextOptions.ocpDate] The time the
request was issued. Client libraries typically set this to the current
system clock time; set it explicitly if you are calling the REST API
directly.

@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  PoolListUsageMetricsResult 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.
@summary Lists the usage metrics aggregated by pool across individual time intervals for the specified account . If you do not specify a $filter clause including a poolId the response includes all pools that existed in the account in the time range of the returned aggregation intervals . If you do not specify a $filter clause including a startTime or endTime these filters default to the start and end times of the last aggregation interval currently available ; that is only the last aggregation interval is returned . @param { string } nextPageLink The NextLink from the previous successful call to List operation . @param { object } [ options ] Optional Parameters . @param { object } [ options . poolListUsageMetricsNextOptions ] Additional parameters for the operation @param { uuid } [ options . poolListUsageMetricsNextOptions . clientRequestId ] The caller - generated request identity in the form of a GUID with no decoration such as curly braces e . g . @param { boolean } [ options . poolListUsageMetricsNextOptions . returnClientRequestId ] Whether the server should return the client - request - id in the response . @param { date } [ options . poolListUsageMetricsNextOptions . ocpDate ] The time the request was issued . Client libraries typically set this to the current system clock time ; set it explicitly if you are calling the REST API directly . @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 PoolListUsageMetricsResult 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 _listUsageMetricsNext(nextPageLink, options, callback) {
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let poolListUsageMetricsNextOptions = (options && options.poolListUsageMetricsNextOptions !== undefined) ? options.poolListUsageMetricsNextOptions : undefined;
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink 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);
  }
  let clientRequestId;
  let returnClientRequestId;
  let ocpDate;
  try {
    if (poolListUsageMetricsNextOptions !== null && poolListUsageMetricsNextOptions !== undefined)
    {
      clientRequestId = poolListUsageMetricsNextOptions.clientRequestId;
      if (clientRequestId !== null && clientRequestId !== undefined && !(typeof clientRequestId.valueOf() === 'string' && msRest.isValidUuid(clientRequestId))) {
        throw new Error('clientRequestId must be of type string and must be a valid uuid.');
      }
    }
    if (poolListUsageMetricsNextOptions !== null && poolListUsageMetricsNextOptions !== undefined)
    {
      returnClientRequestId = poolListUsageMetricsNextOptions.returnClientRequestId;
      if (returnClientRequestId !== null && returnClientRequestId !== undefined && typeof returnClientRequestId !== 'boolean') {
        throw new Error('returnClientRequestId must be of type boolean.');
      }
    }
    if (poolListUsageMetricsNextOptions !== null && poolListUsageMetricsNextOptions !== undefined)
    {
      ocpDate = poolListUsageMetricsNextOptions.ocpDate;
      if (ocpDate && !(ocpDate instanceof Date ||
          (typeof ocpDate.valueOf() === 'string' && !isNaN(Date.parse(ocpDate))))) {
            throw new Error('ocpDate must be of type date.');
          }
    }
  } catch (error) {
    return callback(error);
  }
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if (clientRequestId !== undefined && clientRequestId !== null) {
    httpRequest.headers['client-request-id'] = clientRequestId.toString();
  }
  if (returnClientRequestId !== undefined && returnClientRequestId !== null) {
    httpRequest.headers['return-client-request-id'] = returnClientRequestId.toString();
  }
  if (ocpDate !== undefined && ocpDate !== null) {
    httpRequest.headers['ocp-date'] = ocpDate.toUTCString();
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  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['BatchError']().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);
    }
    let result = null;
    if (responseBody === '') responseBody = null;
    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['PoolListUsageMetricsResult']().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);
  });
}
function _listUsageMetricsNext ( nextPageLink , options , callback ) { let client = this . client ; if ( ! callback && typeof options === 'function' ) { callback = options ; options = null ; } if ( ! callback ) { throw new Error ( 'callback cannot be null.' ) ; } let poolListUsageMetricsNextOptions = ( options && options . poolListUsageMetricsNextOptions !== undefined ) ? options . poolListUsageMetricsNextOptions : undefined ; try { if ( nextPageLink === null || nextPageLink === undefined || typeof nextPageLink . valueOf ( ) !== 'string' ) { throw new Error ( 'nextPageLink 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 ) ; } let clientRequestId ; let returnClientRequestId ; let ocpDate ; try { if ( poolListUsageMetricsNextOptions !== null && poolListUsageMetricsNextOptions !== undefined ) { clientRequestId = poolListUsageMetricsNextOptions . clientRequestId ; if ( clientRequestId !== null && clientRequestId !== undefined && ! ( typeof clientRequestId . valueOf ( ) === 'string' && msRest . isValidUuid ( clientRequestId ) ) ) { throw new Error ( 'clientRequestId must be of type string and must be a valid uuid.' ) ; } } if ( poolListUsageMetricsNextOptions !== null && poolListUsageMetricsNextOptions !== undefined ) { returnClientRequestId = poolListUsageMetricsNextOptions . returnClientRequestId ; if ( returnClientRequestId !== null && returnClientRequestId !== undefined && typeof returnClientRequestId !== 'boolean' ) { throw new Error ( 'returnClientRequestId must be of type boolean.' ) ; } } if ( poolListUsageMetricsNextOptions !== null && poolListUsageMetricsNextOptions !== undefined ) { ocpDate = poolListUsageMetricsNextOptions . ocpDate ; if ( ocpDate && ! ( ocpDate instanceof Date || ( typeof ocpDate . valueOf ( ) === 'string' && ! isNaN ( Date . parse ( ocpDate ) ) ) ) ) { throw new Error ( 'ocpDate must be of type date.' ) ; } } } catch ( error ) { return callback ( error ) ; } let requestUrl = '{nextLink}' ; requestUrl = requestUrl . replace ( '{nextLink}' , nextPageLink ) ; let httpRequest = new WebResource ( ) ; httpRequest . method = 'GET' ; httpRequest . url = requestUrl ; httpRequest . headers = { } ; httpRequest . headers [ 'Content-Type' ] = 'application/json; charset=utf-8' ; if ( this . client . generateClientRequestId ) { httpRequest . headers [ 'client-request-id' ] = msRestAzure . generateUuid ( ) ; } if ( this . client . acceptLanguage !== undefined && this . client . acceptLanguage !== null ) { httpRequest . headers [ 'accept-language' ] = this . client . acceptLanguage ; } if ( clientRequestId !== undefined && clientRequestId !== null ) { httpRequest . headers [ 'client-request-id' ] = clientRequestId . toString ( ) ; } if ( returnClientRequestId !== undefined && returnClientRequestId !== null ) { httpRequest . headers [ 'return-client-request-id' ] = returnClientRequestId . toString ( ) ; } if ( ocpDate !== undefined && ocpDate !== null ) { httpRequest . headers [ 'ocp-date' ] = ocpDate . toUTCString ( ) ; } if ( options ) { for ( let headerName in options [ 'customHeaders' ] ) { if ( options [ 'customHeaders' ] . hasOwnProperty ( headerName ) ) { httpRequest . headers [ headerName ] = options [ 'customHeaders' ] [ headerName ] ; } } } httpRequest . body = null ; 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 [ 'BatchError' ] ( ) . mapper ( ) ; error . body = client . deserialize ( resultMapper , parsedErrorResponse , 'error.body' ) ; } } catch ( defaultError ) { error . message = ` ${ defaultError . message } ` + ` ${ responseBody } ` ; return callback ( error ) ; } return callback ( error ) ; } let result = null ; if ( responseBody === '' ) responseBody = null ; 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 [ 'PoolListUsageMetricsResult' ] ( ) . mapper ( ) ; result = client . deserialize ( resultMapper , parsedResponse , 'result' ) ; } } catch ( error ) { let deserializationError = new Error ( ` ${ error } ${ responseBody } ` ) ; deserializationError . request = msRest . stripRequest ( httpRequest ) ; deserializationError . response = msRest . stripResponse ( response ) ; return callback ( deserializationError ) ; } } return callback ( null , result , httpRequest , response ) ; } ) ; }
@summary Lists the usage metrics, aggregated by pool across individual time
 intervals, for the specified account.
@summary Lists the usage metrics aggregated by pool across individual time intervals for the specified account .
/* jshint validthis: true */ // Validate // Construct URL // Create HTTP transport objects // Set Headers // Send Request // Create Result // Deserialize Response