18
18
* IBM OpenAPI SDK Code Generator Version: 3.66.0-d6c2d7e0-20230215-221247
19
19
*/
20
20
21
+ /* eslint-disable max-classes-per-file */
22
+ /* eslint-disable no-await-in-loop */
23
+
21
24
import * as extend from 'extend' ;
22
25
import { IncomingHttpHeaders , OutgoingHttpHeaders } from 'http' ;
23
26
import {
@@ -713,6 +716,8 @@ class IbmAnalyticsEngineApiV3 extends BaseService {
713
716
* @param {string } params.instanceId - The identifier of the Analytics Engine instance associated with the Spark
714
717
* application(s).
715
718
* @param {string[] } [params.state] - List of Spark application states that will be used to filter the response.
719
+ * @param {number } [params.limit] - Number of application entries to be included in the response.
720
+ * @param {string } [params.start] - Token used to fetch the next or the previous page of the applications list.
716
721
* @param {OutgoingHttpHeaders } [params.headers] - Custom request headers
717
722
* @returns {Promise<IbmAnalyticsEngineApiV3.Response<IbmAnalyticsEngineApiV3.ApplicationCollection>> }
718
723
*/
@@ -721,14 +726,16 @@ class IbmAnalyticsEngineApiV3 extends BaseService {
721
726
) : Promise < IbmAnalyticsEngineApiV3 . Response < IbmAnalyticsEngineApiV3 . ApplicationCollection > > {
722
727
const _params = { ...params } ;
723
728
const _requiredParams = [ 'instanceId' ] ;
724
- const _validParams = [ 'instanceId' , 'state' , 'headers' ] ;
729
+ const _validParams = [ 'instanceId' , 'state' , 'limit' , 'start' , ' headers'] ;
725
730
const _validationErrors = validateParams ( _params , _requiredParams , _validParams ) ;
726
731
if ( _validationErrors ) {
727
732
return Promise . reject ( _validationErrors ) ;
728
733
}
729
734
730
735
const query = {
731
736
'state' : _params . state ,
737
+ 'limit' : _params . limit ,
738
+ 'start' : _params . start ,
732
739
} ;
733
740
734
741
const path = {
@@ -1560,6 +1567,10 @@ namespace IbmAnalyticsEngineApiV3 {
1560
1567
instanceId : string ;
1561
1568
/** List of Spark application states that will be used to filter the response. */
1562
1569
state ?: ListApplicationsConstants . State [ ] | string [ ] ;
1570
+ /** Number of application entries to be included in the response. */
1571
+ limit ?: number ;
1572
+ /** Token used to fetch the next or the previous page of the applications list. */
1573
+ start ?: string ;
1563
1574
headers ?: OutgoingHttpHeaders ;
1564
1575
}
1565
1576
@@ -1709,10 +1720,18 @@ namespace IbmAnalyticsEngineApiV3 {
1709
1720
auto_termination_time ?: string ;
1710
1721
}
1711
1722
1712
- /** An array of application details . */
1723
+ /** A paginated collection of applications . */
1713
1724
export interface ApplicationCollection {
1714
1725
/** List of applications. */
1715
- applications ?: Application [ ] ;
1726
+ applications : Application [ ] ;
1727
+ /** A reference to a page in a paginated collection. */
1728
+ first ?: PageLink ;
1729
+ /** A reference to a page in a paginated collection. */
1730
+ next ?: PageLink ;
1731
+ /** A reference to a page in a paginated collection. */
1732
+ previous ?: PageLink ;
1733
+ /** The maximum number of results in this page of the collection. */
1734
+ limit : number ;
1716
1735
}
1717
1736
1718
1737
/** Application details. */
@@ -1963,6 +1982,14 @@ namespace IbmAnalyticsEngineApiV3 {
1963
1982
type ?: string ;
1964
1983
}
1965
1984
1985
+ /** A reference to a page in a paginated collection. */
1986
+ export interface PageLink {
1987
+ /** A url which returns a specific page of a collection. */
1988
+ href : string ;
1989
+ /** A token which loads a specific page of a collection when it is provided the url of the collection. */
1990
+ start ?: string ;
1991
+ }
1992
+
1966
1993
/** Resource consumption limits for the instance. */
1967
1994
export interface ResourceConsumptionLimitsResponse {
1968
1995
/** Maximum number of virtual processor cores that be used in the instance. */
@@ -1992,6 +2019,92 @@ namespace IbmAnalyticsEngineApiV3 {
1992
2019
/** Time when the Spark history server will be stopped automatically. */
1993
2020
auto_termination_time ?: string ;
1994
2021
}
2022
+
2023
+ /*************************
2024
+ * pager classes
2025
+ ************************/
2026
+
2027
+ /**
2028
+ * ApplicationsPager can be used to simplify the use of listApplications().
2029
+ */
2030
+ export class ApplicationsPager {
2031
+ protected _hasNext : boolean ;
2032
+
2033
+ protected pageContext : any ;
2034
+
2035
+ protected client : IbmAnalyticsEngineApiV3 ;
2036
+
2037
+ protected params : IbmAnalyticsEngineApiV3 . ListApplicationsParams ;
2038
+
2039
+ /**
2040
+ * Construct a ApplicationsPager object.
2041
+ *
2042
+ * @param {IbmAnalyticsEngineApiV3 } client - The service client instance used to invoke listApplications()
2043
+ * @param {Object } params - The parameters to be passed to listApplications()
2044
+ * @constructor
2045
+ * @returns {ApplicationsPager }
2046
+ */
2047
+ constructor (
2048
+ client : IbmAnalyticsEngineApiV3 ,
2049
+ params : IbmAnalyticsEngineApiV3 . ListApplicationsParams
2050
+ ) {
2051
+ if ( params && params . start ) {
2052
+ throw new Error ( `the params.start field should not be set` ) ;
2053
+ }
2054
+
2055
+ this . _hasNext = true ;
2056
+ this . pageContext = { next : undefined } ;
2057
+ this . client = client ;
2058
+ this . params = JSON . parse ( JSON . stringify ( params || { } ) ) ;
2059
+ }
2060
+
2061
+ /**
2062
+ * Returns true if there are potentially more results to be retrieved by invoking getNext().
2063
+ * @returns {boolean }
2064
+ */
2065
+ public hasNext ( ) : boolean {
2066
+ return this . _hasNext ;
2067
+ }
2068
+
2069
+ /**
2070
+ * Returns the next page of results by invoking listApplications().
2071
+ * @returns {Promise<IbmAnalyticsEngineApiV3.Application[]> }
2072
+ */
2073
+ public async getNext ( ) : Promise < IbmAnalyticsEngineApiV3 . Application [ ] > {
2074
+ if ( ! this . hasNext ( ) ) {
2075
+ throw new Error ( 'No more results available' ) ;
2076
+ }
2077
+
2078
+ if ( this . pageContext . next ) {
2079
+ this . params . start = this . pageContext . next ;
2080
+ }
2081
+ const response = await this . client . listApplications ( this . params ) ;
2082
+ const { result } = response ;
2083
+
2084
+ let next = null ;
2085
+ if ( result && result . next ) {
2086
+ next = result . next . start ;
2087
+ }
2088
+ this . pageContext . next = next ;
2089
+ if ( ! this . pageContext . next ) {
2090
+ this . _hasNext = false ;
2091
+ }
2092
+ return result . applications ;
2093
+ }
2094
+
2095
+ /**
2096
+ * Returns all results by invoking listApplications() repeatedly until all pages of results have been retrieved.
2097
+ * @returns {Promise<IbmAnalyticsEngineApiV3.Application[]> }
2098
+ */
2099
+ public async getAll ( ) : Promise < IbmAnalyticsEngineApiV3 . Application [ ] > {
2100
+ const results : Application [ ] = [ ] ;
2101
+ while ( this . hasNext ( ) ) {
2102
+ const nextPage = await this . getNext ( ) ;
2103
+ results . push ( ...nextPage ) ;
2104
+ }
2105
+ return results ;
2106
+ }
2107
+ }
1995
2108
}
1996
2109
1997
2110
export = IbmAnalyticsEngineApiV3 ;
0 commit comments