
    b                     v    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dZd	d
ddZ G d de      Zy)z2Utilities for Edge ML API long-running operations.    )absolute_import)division)unicode_literals)util)waiter)	resourcesi'	 z+Analyzing Edge machine learning model. [{}]z9Optimizing Edge machine learning model for Edge TPU. [{}]z,Converting SavedModel to TF Lite model. [{}])analyzecompileconvertc                   $    e Zd ZdZddZd Zd Zy)OperationsClientzClient for the Edge ML operations API.

  Attributes:
    client: Generated Edge ML API client.
    messages: Generated Edge ML API messages.
  Nc                     |xs t        j                         | _        |xs t        j                  |      | _        | j                  j
                  | _        y )N)r   GetClientInstanceclientGetMessagesModulemessages
operations_service)selfr   r   s      /lib/googlecloudsdk/api_lib/edgeml/operations.py__init__zOperationsClient.__init__+   s?    4D224DK> 6 6v >DMKK**DM    c                     | j                   j                  j                  | j                  j	                  |j                                     S )zCalls get method for long-running operations.

    Args:
      operation_ref: Ref to long-running operation.

    Returns:
      edgeml.Operation message.
    )name)r   projects_operationsGetr   EdgemlOperationsGetRequestRelativeName)r   operation_refs     r   r   zOperationsClient.Get0   sD     ;;**..00++- 	1 	/0 0r   c                 J   t        j                  | j                        }t        j                  j                  |j                  d      }|j                         j                  d      d   }t        j                  |d      }t        j                  |||dt        dddd		      S )
aJ  Wait until the operation is complete or times out.

    Args:
      operation: The operation resource to wait on.

    Returns:
      The operation resource when it has completed.

    Raises:
      OperationTimeoutError: When the operation polling times out.
      OperationError: When the operation completed with an error.
    zedgeml.operations)
collection/r   zWaiting for operation [{}]i  Ni  )pre_start_sleep_msmax_wait_msexponential_sleep_multiplier	jitter_mswait_ceiling_mssleep_ms)r   CloudOperationPollerNoResourcesr   r   REGISTRYParser   Namesplit_WAITING_MESSAGEgetWaitFor_MAX_WAIT_TIME_MS)r   	operationpollerr   operation_typemessages         r   WaitForOperationz!OperationsClient.WaitForOperation=   s     33DMMBF&&,,#6 - 8M"'')//4Q7N"">3OPG>>%%)	 	r   )NN)__name__
__module____qualname____doc__r   r   r6    r   r   r   r   #   s    +
0r   r   N)r:   
__future__r   r   r   googlecloudsdk.api_lib.edgemlr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r1   r.   objectr   r;   r   r   <module>rA      sC    9 &  ' . . ) #  =J= 5v 5r   