@@ -570,7 +570,15 @@ def create_application(
570
570
response = self .send (request , ** kwargs )
571
571
return response
572
572
573
- def list_applications (self , instance_id : str , * , state : List [str ] = None , ** kwargs ) -> DetailedResponse :
573
+
574
+ def list_applications (self ,
575
+ instance_id : str ,
576
+ * ,
577
+ state : List [str ] = None ,
578
+ limit : int = None ,
579
+ start : str = None ,
580
+ ** kwargs
581
+ ) -> DetailedResponse :
574
582
"""
575
583
List all Spark applications.
576
584
@@ -581,6 +589,10 @@ def list_applications(self, instance_id: str, *, state: List[str] = None, **kwar
581
589
associated with the Spark application(s).
582
590
:param List[str] state: (optional) List of Spark application states that
583
591
will be used to filter the response.
592
+ :param int limit: (optional) Number of application entries to be included
593
+ in the response.
594
+ :param str start: (optional) Token used to fetch the next or the previous
595
+ page of the applications list.
584
596
:param dict headers: A `dict` containing the request headers
585
597
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
586
598
:rtype: DetailedResponse with `dict` result representing a `ApplicationCollection` object
@@ -597,7 +609,9 @@ def list_applications(self, instance_id: str, *, state: List[str] = None, **kwar
597
609
headers .update (sdk_headers )
598
610
599
611
params = {
600
- "state" : convert_list (state ),
612
+ 'state' : convert_list (state ),
613
+ 'limit' : limit ,
614
+ 'start' : start
601
615
}
602
616
603
617
if "headers" in kwargs :
@@ -1318,25 +1332,61 @@ class StateEnum(str, Enum):
1318
1332
1319
1333
class ApplicationCollection :
1320
1334
"""
1321
- An array of application details.
1322
-
1323
- :attr List[Application] applications: (optional) List of applications.
1335
+ A paginated collection of applications.
1336
+
1337
+ :attr List[Application] applications: List of applications.
1338
+ :attr PageLink first: (optional) A reference to a page in a paginated
1339
+ collection.
1340
+ :attr PageLink next: (optional) A reference to a page in a paginated collection.
1341
+ :attr PageLink previous: (optional) A reference to a page in a paginated
1342
+ collection.
1343
+ :attr int limit: The maximum number of results in this page of the collection.
1324
1344
"""
1325
1345
1326
- def __init__ (self , * , applications : List ["Application" ] = None ) -> None :
1346
+ def __init__ (self ,
1347
+ applications : List ['Application' ],
1348
+ limit : int ,
1349
+ * ,
1350
+ first : 'PageLink' = None ,
1351
+ next : 'PageLink' = None ,
1352
+ previous : 'PageLink' = None ) -> None :
1327
1353
"""
1328
1354
Initialize a ApplicationCollection object.
1329
1355
1330
- :param List[Application] applications: (optional) List of applications.
1356
+ :param List[Application] applications: List of applications.
1357
+ :param int limit: The maximum number of results in this page of the
1358
+ collection.
1359
+ :param PageLink first: (optional) A reference to a page in a paginated
1360
+ collection.
1361
+ :param PageLink next: (optional) A reference to a page in a paginated
1362
+ collection.
1363
+ :param PageLink previous: (optional) A reference to a page in a paginated
1364
+ collection.
1331
1365
"""
1332
1366
self .applications = applications
1367
+ self .first = first
1368
+ self .next = next
1369
+ self .previous = previous
1370
+ self .limit = limit
1333
1371
1334
1372
@classmethod
1335
1373
def from_dict (cls , _dict : Dict ) -> "ApplicationCollection" :
1336
1374
"""Initialize a ApplicationCollection object from a json dictionary."""
1337
1375
args = {}
1338
- if "applications" in _dict :
1339
- args ["applications" ] = [Application .from_dict (v ) for v in _dict .get ("applications" )]
1376
+ if 'applications' in _dict :
1377
+ args ['applications' ] = [Application .from_dict (x ) for x in _dict .get ('applications' )]
1378
+ else :
1379
+ raise ValueError ('Required property \' applications\' not present in ApplicationCollection JSON' )
1380
+ if 'first' in _dict :
1381
+ args ['first' ] = PageLink .from_dict (_dict .get ('first' ))
1382
+ if 'next' in _dict :
1383
+ args ['next' ] = PageLink .from_dict (_dict .get ('next' ))
1384
+ if 'previous' in _dict :
1385
+ args ['previous' ] = PageLink .from_dict (_dict .get ('previous' ))
1386
+ if 'limit' in _dict :
1387
+ args ['limit' ] = _dict .get ('limit' )
1388
+ else :
1389
+ raise ValueError ('Required property \' limit\' not present in ApplicationCollection JSON' )
1340
1390
return cls (** args )
1341
1391
1342
1392
@classmethod
@@ -1347,14 +1397,16 @@ def _from_dict(cls, _dict):
1347
1397
def to_dict (self ) -> Dict :
1348
1398
"""Return a json dictionary representing this model."""
1349
1399
_dict = {}
1350
- if hasattr (self , "applications" ) and self .applications is not None :
1351
- applications_list = []
1352
- for v in self .applications :
1353
- if isinstance (v , dict ):
1354
- applications_list .append (v )
1355
- else :
1356
- applications_list .append (v .to_dict ())
1357
- _dict ["applications" ] = applications_list
1400
+ if hasattr (self , 'applications' ) and self .applications is not None :
1401
+ _dict ['applications' ] = [x .to_dict () for x in self .applications ]
1402
+ if hasattr (self , 'first' ) and self .first is not None :
1403
+ _dict ['first' ] = self .first .to_dict ()
1404
+ if hasattr (self , 'next' ) and self .next is not None :
1405
+ _dict ['next' ] = self .next .to_dict ()
1406
+ if hasattr (self , 'previous' ) and self .previous is not None :
1407
+ _dict ['previous' ] = self .previous .to_dict ()
1408
+ if hasattr (self , 'limit' ) and self .limit is not None :
1409
+ _dict ['limit' ] = self .limit
1358
1410
return _dict
1359
1411
1360
1412
def _to_dict (self ):
@@ -3014,8 +3066,74 @@ def __ne__(self, other: "LoggingConfigurationResponseLogServer") -> bool:
3014
3066
"""Return `true` when self and other are not equal, false otherwise."""
3015
3067
return not self == other
3016
3068
3069
+ class PageLink ():
3070
+ """
3071
+ A reference to a page in a paginated collection.
3072
+
3073
+ :attr str href: A url which returns a specific page of a collection.
3074
+ :attr str start: (optional) A token which loads a specific page of a collection
3075
+ when it is provided the url of the collection.
3076
+ """
3077
+
3078
+ def __init__ (self ,
3079
+ href : str ,
3080
+ * ,
3081
+ start : str = None ) -> None :
3082
+ """
3083
+ Initialize a PageLink object.
3084
+
3085
+ :param str href: A url which returns a specific page of a collection.
3086
+ :param str start: (optional) A token which loads a specific page of a
3087
+ collection when it is provided the url of the collection.
3088
+ """
3089
+ self .href = href
3090
+ self .start = start
3091
+
3092
+ @classmethod
3093
+ def from_dict (cls , _dict : Dict ) -> 'PageLink' :
3094
+ """Initialize a PageLink object from a json dictionary."""
3095
+ args = {}
3096
+ if 'href' in _dict :
3097
+ args ['href' ] = _dict .get ('href' )
3098
+ else :
3099
+ raise ValueError ('Required property \' href\' not present in PageLink JSON' )
3100
+ if 'start' in _dict :
3101
+ args ['start' ] = _dict .get ('start' )
3102
+ return cls (** args )
3103
+
3104
+ @classmethod
3105
+ def _from_dict (cls , _dict ):
3106
+ """Initialize a PageLink object from a json dictionary."""
3107
+ return cls .from_dict (_dict )
3108
+
3109
+ def to_dict (self ) -> Dict :
3110
+ """Return a json dictionary representing this model."""
3111
+ _dict = {}
3112
+ if hasattr (self , 'href' ) and self .href is not None :
3113
+ _dict ['href' ] = self .href
3114
+ if hasattr (self , 'start' ) and self .start is not None :
3115
+ _dict ['start' ] = self .start
3116
+ return _dict
3117
+
3118
+ def _to_dict (self ):
3119
+ """Return a json dictionary representing this model."""
3120
+ return self .to_dict ()
3121
+
3122
+ def __str__ (self ) -> str :
3123
+ """Return a `str` version of this PageLink object."""
3124
+ return json .dumps (self .to_dict (), indent = 2 )
3125
+
3126
+ def __eq__ (self , other : 'PageLink' ) -> bool :
3127
+ """Return `true` when self and other are equal, false otherwise."""
3128
+ if not isinstance (other , self .__class__ ):
3129
+ return False
3130
+ return self .__dict__ == other .__dict__
3017
3131
3018
- class ResourceConsumptionLimitsResponse :
3132
+ def __ne__ (self , other : 'PageLink' ) -> bool :
3133
+ """Return `true` when self and other are not equal, false otherwise."""
3134
+ return not self == other
3135
+
3136
+ class ResourceConsumptionLimitsResponse ():
3019
3137
"""
3020
3138
Resource consumption limits for the instance.
3021
3139
@@ -3245,6 +3363,84 @@ class StateEnum(str, Enum):
3245
3363
"""
3246
3364
State of the Spark history server.
3247
3365
"""
3248
-
3366
+
3249
3367
STARTED = "started"
3250
3368
STOPPED = "stopped"
3369
+
3370
+
3371
+ ##############################################################################
3372
+ # Pagers
3373
+ ##############################################################################
3374
+
3375
+ class ApplicationsPager ():
3376
+ """
3377
+ ApplicationsPager can be used to simplify the use of the "list_applications" method.
3378
+ """
3379
+
3380
+ def __init__ (self ,
3381
+ * ,
3382
+ client : IbmAnalyticsEngineApiV3 ,
3383
+ instance_id : str ,
3384
+ state : List [str ] = None ,
3385
+ limit : int = None ,
3386
+ ) -> None :
3387
+ """
3388
+ Initialize a ApplicationsPager object.
3389
+ :param str instance_id: The identifier of the Analytics Engine instance
3390
+ associated with the Spark application(s).
3391
+ :param List[str] state: (optional) List of Spark application states that
3392
+ will be used to filter the response.
3393
+ :param int limit: (optional) Number of application entries to be included
3394
+ in the response.
3395
+ """
3396
+ self ._has_next = True
3397
+ self ._client = client
3398
+ self ._page_context = { 'next' : None }
3399
+ self ._instance_id = instance_id
3400
+ self ._state = state
3401
+ self ._limit = limit
3402
+
3403
+ def has_next (self ) -> bool :
3404
+ """
3405
+ Returns true if there are potentially more results to be retrieved.
3406
+ """
3407
+ return self ._has_next
3408
+
3409
+ def get_next (self ) -> List [dict ]:
3410
+ """
3411
+ Returns the next page of results.
3412
+ :return: A List[dict], where each element is a dict that represents an instance of Application.
3413
+ :rtype: List[dict]
3414
+ """
3415
+ if not self .has_next ():
3416
+ raise StopIteration (message = 'No more results available' )
3417
+
3418
+ result = self ._client .list_applications (
3419
+ instance_id = self ._instance_id ,
3420
+ state = self ._state ,
3421
+ limit = self ._limit ,
3422
+ start = self ._page_context .get ('next' ),
3423
+ ).get_result ()
3424
+
3425
+ next = None
3426
+ next_page_link = result .get ('next' )
3427
+ if next_page_link is not None :
3428
+ next = next_page_link .get ('start' )
3429
+ self ._page_context ['next' ] = next
3430
+ if next is None :
3431
+ self ._has_next = False
3432
+
3433
+ return result .get ('applications' )
3434
+
3435
+ def get_all (self ) -> List [dict ]:
3436
+ """
3437
+ Returns all results by invoking get_next() repeatedly
3438
+ until all pages of results have been retrieved.
3439
+ :return: A List[dict], where each element is a dict that represents an instance of Application.
3440
+ :rtype: List[dict]
3441
+ """
3442
+ results = []
3443
+ while self .has_next ():
3444
+ next_page = self .get_next ()
3445
+ results .extend (next_page )
3446
+ return results
0 commit comments