
                         \   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  SSK
Jr  SS	KJr  SS
KJr  SSKJr  \R"                  " S5      r\R&                  r\R"                  " S5      rSrSR-                  \5      rS rSS jrSS jr        SS jrS rS rS rg)z(Utilities for building the dataflow CLI.    )absolute_import)division)unicode_literalsN)
exceptions)
list_pager)apis)log)
properties)	resourcesz	^dataflowz^(.*)-windmill-(.*)-watermarkz dataflow.projects.locations.jobszDefaults to '{0}'.c                      [         R                  " U R                  5      nUR                  S0 5      R                  SS5      $ ! [         a,    [
        R                  R                  U R                  5         gf = f)zExtract the error message from an HTTPError.

Args:
  error: The error exceptions.HttpError thrown by the API client.

Returns:
  A string describing the error.
errormessage zUnknown error)	jsonloadscontentget
ValueErrorr	   errPrintresponse)r   content_objs     8lib/googlecloudsdk/command_lib/dataflow/dataflow_util.pyGetErrorMessager   2   s]    **U]]+K??7B'++Ir::	 GGMM%..!s   AA 3A:9A:c                     U(       a  SR                  U5      nU(       a  SR                  U5      nU(       a  SR                  U5      nSR                  XU[        U 5      5      $ )aL  Create a standard error message across commands.

Args:
  error: The error exceptions.HttpError thrown by the API client.
  job_id: The job ID that was used in the command.
  project_id: The project ID that was used in the command.
  region_id: The region ID that was used in the command.

Returns:
  str, a standard error message.
z with job ID [{0}]z in project [{0}]z in regional endpoint [{0}]zFailed operation{0}{1}{2}: {3})formatr   )r   job_id
project_id	region_ids       r   MakeErrorMessager    C   s^     !((0F$++J7J-44Y?I	)	0	0Y1@1G
I I    c           	   #      #     U  H  nUv   M	     g! [         R                   a%  n[        R                  " [	        XQX#5      5      eSnAff = f7f)a  Wraps a generator to catch any exceptions.

Args:
  generator: The error exceptions.HttpError thrown by the API client.
  job_id: The job ID that was used in the command.
  project_id: The project ID that was used in the command.
  region_id: The region ID that was used in the command.

Yields:
  The generated object.

Raises:
  dataflow_exceptions.ServiceException: An exception for errors raised by
    the service.
N)r   	HttpErrordataflow_exceptionsServiceExceptionr    )	generatorr   r   r   xes         r   YieldExceptionWrapperr)   Y   sK      <g 			 <

.
.J:< <<s$   A AA AAAc
                 f    Sn
U	(       d  Sn
[         R                  " U UUUUUUU
S9n[        XX5      $ )ag  Returns a wrapped list_page.YieldFromList to catch any exceptions.

Args:
  service: apitools_base.BaseApiService, A service with a .List() method.
  request: protorpc.messages.Message, The request message corresponding to the
    service's .List() method, with all the attributes populated except the
    .maxResults and .pageToken attributes.
  limit: int, The maximum number of records to yield. None if all available
    records should be yielded.
  batch_size: int, The number of items to retrieve per request.
  field: str, The field in the response that will be a list of items.
  batch_size_attribute: str, The name of the attribute in a response message
    holding the maximum number of results to be returned. None if
    caller-specified batch size is unsupported.
  predicate: lambda, A function that returns true for items to be yielded.
  job_id: The job ID that was used in the command.
  project_id: The project ID that was used in the command.
  region_id: The region ID that was used in the command.

Returns:
  The wrapped generator.

Raises:
  dataflow_exceptions.ServiceException: if list request failed.
List
Aggregated)servicerequestlimit
batch_sizefieldbatch_size_attribute	predicatemethod)r   YieldFromListr)   )r-   r.   r/   r0   r1   r2   r3   r   r   r   r4   pagers               r   r5   r5   q   sI    F &	F

"
"/% 
uj	DDr!   c                     [         R                  R                  U R                  [        R
                  R                  R                  R                  U R                  S.[        S9nUR                  5       $ )zuTransform a job resource into a URL string.

Args:
  resource: The DisplayInfo job object

Returns:
  URL to the job
	projectIdlocationparams
collection)r   REGISTRYParseidr
   VALUEScoreproject	GetOrFailr:   JOBS_COLLECTIONSelfLink)resourcerefs     r   JobsUriFuncrI      sb     	  kk!((--55??'' ! 	! 	"# 
r!   c                     [         R                  R                  U [        R                  R
                  R                  R                  US.[        S9nUR                  5       $ )zTransform a job ID into a URL string.

Args:
  job_id: The job ID
  region_id: Region ID of the job's regional endpoint.

Returns:
  URL to the job
r8   r;   )
r   r>   r?   r
   rA   rB   rC   rD   rE   rF   )r   r   rH   s      r   JobsUriFromIdrK      sX     	  !((--55?? ! 	! 	"# 
r!   c                     U R                   nU(       d1  [        nSR                  [        5      n[        R                  " U5        U$ )zGet region to be used in Dataflow services.

Args:
  args: Argument passed in when running gcloud dataflow command

Returns:
  Region specified by user from --region flag in args, then fall back to
  'us-central1'.
z`--region` not set; defaulting to '{0}'. In an upcoming release, users must specify a region explicitly. See https://cloud.google.com/dataflow/docs/concepts/regional-endpoints for additional details.)regionDATAFLOW_API_DEFAULT_REGIONr   r	   warning)argsrM   msgs      r   	GetRegionrR      s?     ;;&	(F% F./	 
 KK	-r!   )r   r   r   )Nd   items
maxResultsNr   r   r   )__doc__
__future__r   r   r   r   reapitools.base.pyr   r   googlecloudsdk.api_lib.dataflowr   r$   googlecloudsdk.corer	   r
   r   compileDATAFLOW_METRICS_RErN   WINDMILL_WATERMARK_RErE   r   DEFAULT_REGION_MESSAGEr   r    r)   r5   rI   rK   rR    r!   r   <module>ra      s    / &  '  	 ' ' 0 M # * )
 jj- ">>  

#BC 4/66! "I,<4  '3 0Ef(*r!   