
                            d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ ej                  j                   fd	Zej                  j                   fd
Zej                  j                   fdZej(                  ej                  j                   fdZej                  j                   fdZ G d de
j.                        Zy)z2Utilities for calling the Composer Operations API.    )absolute_import)division)unicode_literalsN)util)waiter)basec                 B    t        j                  |       j                  S )Nrelease_track)api_utilGetClientInstanceprojects_locations_operationsr
   s    6lib/googlecloudsdk/api_lib/composer/operations_util.py
GetServicer      s    		#	#!
##@#@A    c                     t        |      j                  t        j                  |      j	                  | j                                     S )a(  Calls the Composer Operations.Delete method.

  Args:
    operation_resource: Resource, the Composer operation resource to
        delete.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
        which Composer client library will be used.

  Returns:
    Empty
  r
   name)r   Deleter   GetMessagesModule0ComposerProjectsLocationsOperationsDeleteRequestRelativeNameoperation_resourcer   s     r   r   r   #   sF     
-	0	7	7  }=77!..0 8 2
3 3r   c                     t        |      j                  t        j                  |      j	                  | j                                     S )aD  Calls the Composer Operations.Get method.

  Args:
    operation_resource: Resource, the Composer operation resource to
        retrieve.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
        which Composer client library will be used.

  Returns:
    Operation: the requested operation
  r
   r   )r   Getr   r   -ComposerProjectsLocationsOperationsGetRequestr   r   s     r   r   r   5   sF     
-	0	4	4  }=44!..0 5 2
3 3r   c           	          t        j                  t        j                  |      j                  t	        |      | d||d      S )aH  Lists Composer Operations across all locations.

  Uses a hardcoded list of locations, as there is way to dynamically
  discover the list of supported locations. Support for new locations
  will be aligned with Cloud SDK releases.

  Args:
    location_refs: [core.resources.Resource], a list of resource reference to
        locations in which to list operations.
    page_size: An integer specifying the maximum number of resources to be
      returned in a single list call.
    limit: An integer specifying the maximum number of operations to list.
        None if all available operations should be returned.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
        which Composer client library will be used.

  Returns:
    list: a generator over Operations within the locations in `location_refs`.
  r
   
operationsr   )limitlocation_attribute)r   AggregateListResultsr   .ComposerProjectsLocationsOperationsListRequestr   )location_refs	page_sizer    r   s       r   Listr&   G   sB    . 
	&	&  }=55}-
! !r   c                 `    t        j                  t        |      | j                  |dd       y)a  Waits for an operation to complete.

  Polls the operation at least every 15 seconds, showing a progress indicator.
  Returns when the operation has completed.

  Args:
    operation: Operation Message, the operation to poll
    message: str, a message to display with the progress indicator. For
        example, 'Waiting for deletion of [some resource]'.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
        which Composer client library will be used.
  r
   i6 i:  )max_wait_mswait_ceiling_msN)r   WaitFor_OperationPollerr   )	operationmessager   s      r   WaitForOperationr.   i   s(     	..]3nn!r   c                   T     e Zd ZdZej
                  j                  f fd	Zd Z xZ	S )r+   z4 Class for polling Composer longrunning Operations. c                 D    t         t        |   t        |      d        y )Nr
   c                     | S )N )xs    r   <lambda>z+_OperationPoller.__init__.<locals>.<lambda>   s    1r   )superr+   __init__r   )selfr   	__class__s     r   r6   z_OperationPoller.__init__   s    	
D*/>r   c                     |j                   rA|j                  r4t        j                  |j                  |j                  j
                        yy)NTF)doneerrorcommand_utilOperationErrorr   r-   )r7   r,   s     r   IsDonez_OperationPoller.IsDone   s>    ~~	)))..*3//*A*AC 	Cr   )
__name__
__module____qualname____doc__r   ReleaseTrackGAr6   r>   __classcell__)r8   s   @r   r+   r+   ~   s    <#'#4#4#7#7 >r   r+   )rB   
__future__r   r   r   sysgooglecloudsdk.api_lib.composerr   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   #googlecloudsdk.command_lib.composerr<   rC   rD   r   r   r   maxsizer&   r.   CloudOperationPollerNoResourcesr+   r2   r   r   <module>rN      s    9 &  ' 
 < . ( D "..11 A
 .2->->-A-A 3$ +/*;*;*>*> 3( {{((++!D 8<7H7H7K7K !*v== r   