
    h1                        S 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  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  0 r\R8                  R:                  R<                  \R>                  RA                  SSSS5      \R8                  RB                  R<                  S\R8                  RD                  R<                  S0r#\RH                  RJ                  S\RH                  RL                  S\RH                  RN                  S0r(Sr)Sr* " S S\RV                  5      r, " S S\RV                  5      r-S r.S)S  jr/S! r0 S)S" jr1S# r2S*S$ jr3S% r4S& r5 " S' S(\Rl                  5      r7g)+z9Flink command library functions for the Flink cli binary.    N)parse)transfer)storage_api)storage_util)base)
exceptions)requests)java)binary_operations)config)	resources)
transports)	platformsz	%APPDATA%googleflinkzconfig.yamlz.~/Library/Preferences/google/flink/config.yamlz"~/.config/google/flink/config.yamlv1alphav1betav1zCould not locate managed flink client executable [{binary}] on the system PATH. Please ensure gcloud managed-flink-client component is properly installed. See https://cloud.google.com/sdk/docs/components for more details.i  0 c                       \ rS rSrSrSrg)FileUploadErrorB   z*Exception raised when a file upload fails. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       =lib/googlecloudsdk/command_lib/managed_flink/flink_backend.pyr   r   B   s    2r    r   c                       \ rS rSrSrSrg)FileDownloadErrorF   z,Exception raised when a file download fails.r   Nr   r   r    r!   r#   r#   F   s    4r    r#   c                      [         R                  R                  [        R                  " 5       R
                  SSSS5      $ )zGet flink python jar location.platformmanaged-flink-clientlibzflink-python-1.19.0.jarospathjoinr   Pathssdk_rootr   r    r!   DummyJarr/   J   s2    	lln
 r    c           	         U=(       d    [         R                  " 5       n[        5       nU  Hv  n[        R                  R                  U5      n[        R                  R                  X5      n[        R                  R                  U5      n UR                  XX5        XtU'   Mx     U$ ! [        R                   a/  n	[        SR                  SR                  U 5      X5      5      eSn	A	ff = f)zDUploads a list of files passed as strings to a Cloud Storage bucket.z(Failed to upload file ["{}"] to "{}": {},N)r   StorageClientdictr*   r+   basenamer,   r   ObjectReferenceFromUrlCopyFileToGCSr   BadFileExceptionr   format)
filesdestinationstorage_clientclientdestinationsfile_to_upload	file_namedest_urldest_objectes
             r!   UploadrD   U   s    8[668&,n  0Iww||K3H..66x@K>7%->"  
 && 
4
;
;hhuo{ s   B''C*;*C%%C*c           	          [         R                  " U 5      nUR
                  R                  S5      nU Vs/ s H  o3(       d  M  UPM     nnUR                  (       a  UR                  /U-   n[        U5      S:  d  US   R                  S5      (       d&  [        R                  " SSR	                  U 5      5      eSR                  USS 5      nUR                  SS	5      R                  S
S5      R                  SS5      nU[        R                  R                  SUS   US   US   US94$ !   [        R                  " SSR	                  U 5      5      e= fs  snf )zCreates a registry from an artifact URI.

Args:
  artifact_uri:
    ar://<project>/<location>/<repository>/<file/path/version/file.jar>.

Returns:
  Jar file name, The registry resource.
z
JAR|PY|SQLz|Artifact URI [{0}] is invalid. Must be in the format of ar://<project>/<location>/<repository>/<file/path/version/file.jar>./   z.jar   Nz%2F+z%2B^z%5Ez6artifactregistry.projects.locations.repositories.filesr         )
projectsIdlocationsIdrepositoriesIdfilesId)r   urlparser   InvalidArgumentExceptionr9   r+   splitnetloclenendswithr,   replacer   REGISTRYCreate)artifact_uri
parsed_url
split_pathr+   cleaned_split_pathjar_filecleaned_jar_files          r!   CreateRegistryFromArtifactUrira   i   sg   -J $$S)*)3<t<$++,/AA	q (:2(>(G(G(O(O

-
-	P			  XX(,-(sE"**36>>sEJ  
9%%,,>#A&$Q''* -  
 /

-
-	P			  =s   D. 
EE.(Ec                     U=(       d    [         R                  " 5       n[         R                  " 5       nUR                  US9n[        R
                  R                  U S[        S9n[        R                  " SS9Ul
         UR                  R                  XVS9   UR                  R!                  5         g! [         a  n[        SR                  U5      5      eSnAff = f! UR                  R!                  5         f = f)z3Downloads a JAR file from Google Artifact Registry.)nameT)	chunksizeN)response_encoding)downloadz1Failed to download JAR from Artifact Registry: {})r	   	GetClientGetMessagesAArtifactregistryProjectsLocationsRepositoriesFilesDownloadRequestr   DownloadFromFileDEFAULT_CHUNK_SIZEr   GetApitoolsTransport
bytes_http%projects_locations_repositories_files	Exceptionr#   r9   streamclose)	dest_pathartifact_jar_pathartifact_clientr=   messagesrequestdrC   s           r!   DownloadJarFromArtifactRegistryry      s     2h002&!!#( VV W '   D<N O!004H!,
0099'9N HHNN 
 
;BB1E 
 HHNNs$    B5 5
C?CCC! !C=c                     [         R                  R                  U S5      n[         R                  " UR                  5        [
        R                  " 5       R                  UR                  5        g )NT)r   r5   r6   ValidateBucketUrlbucketr   r2   	GetBucket)staging_locationdests     r!   CheckStagingLocationr      sH    		%	%	-	-.>	E$  -''4r    c                     [         R                  " [        R                  5      nUR	                  [
        5        U (       a  UR	                  U 5        U(       a  U H  nUR                  US5        M     U$ )zDHelper function to add our environment variables to the environment.N)copydeepcopyr*   environupdateDEFAULT_ENV_ARGSpop)
extra_varsexclude_varsenvvars       r!   GetEnvArgsForCommandr      sP    bjj!#**JJz	ggc4 	*r    c                      [         R                  R                  [        R                  " 5       R
                  SSSS5      $ )z%Get the platform executable location.r&   r'   binr)   r   r    r!   PlatformExecutabler      s2    	lln
 r    c                    U S:X  aw  U(       a  [         R                  " SS5      eU(       d  [         R                  " SS5      eU(       d  [         R                  " SS5      eX:  a  [         R                  " SS5      egU(       d  [         R                  " SS	5      eU(       a  [         R                  " SS
5      eU(       a  [         R                  " SS5      eg)z#Validate autotuning configurations.elasticparallelismz8Parallelism must NOT be set for elastic autotuning mode.zmin-parallelismz8Min parallelism must be set for elastic autotuning mode.zmax-parallelismz8Max parallelism must be set for elastic autotuning mode.z>Min parallelism must be less than or equal to max parallelism.zMParallelism must be set to a value of 1 or greater for fixed autotuning mode.z:Min parallelism must NOT be set for fixed autotuning mode.z:Max parallelism must NOT be set for fixed autotuning mode.N)r   rS   )autotuning_modemin_parallelismmax_parallelismr   s       r!   ValidateAutotuningr      s     	!//

D  //

D  //

D  (//

J  ) //
 
 //

F  //

F  r    c                   |   ^  \ rS rSrSrSrU 4S jrS\R                  R                  SSSSSSSSSSS4S jr
SrU =r$ )FlinkClientWrapper   z$Wrapper for the Flink client binary.Nc                 ^  > S[         R                  SS90n[        [        U ]  " SSUS.UD6  [
        R                  " SS5      U l        [        R                  R                  U R                  5      (       d6  [        5       n[        R                  R                  U5      (       a  X0l        g g g )NMISSING_EXECr'   )binary)r   custom_errorszManaged Flink Client   r   )MISSING_BINARYr9   superr   __init__r
   RequireJavaInstalled
_java_pathr*   r+   exists_executabler   )selfkwargsr   component_executable	__class__s       r!   r   FlinkClientWrapper.__init__   s    --5K-LM 

d, %]FL //0FKDO
 77>>$**++/1	,	-	-/ 
. ,r    localc                 f   US:w  a%  [         R                  " SR                  U5      5      e[        5       nU
(       a   UR	                  SR                  U
5      5        U(       a   UR	                  SR                  U5      5        U(       a   UR	                  SR                  U5      5        U	(       a   UR	                  SR                  U	5      5        U(       a   UR	                  SR                  U5      5        U(       d  / n[        5       nU H=  nUR                  S5      (       a  UR	                  U5        M,  UR	                  U5        M?     US	:X  ab  / nU(       a+  U H%  nUR	                  S
5        UR	                  U5        M'     USSR                  U5      SR                  U5      SU/-   U-   U-   $ US:X  a  / nU(       a/  UR	                  SR                  SR                  U5      5      5        UR                  S5      S   nSR                  U5      /nU(       a+  U H%  nUR	                  S5        UR	                  U5        M'     USU/U-   SR                  U5      SR                  U5      SR                  U5      SR                  U5      SR                  U5      /-   U-   U-   SU/-   U-   $ / nU(       a  SU/n/ nU(       a/  UR	                  SR                  SR                  U5      5      5        USU/U-   U-   SR                  U5      SR                  U5      /-   U-   U/-   U-   $ )z+Parses the arguments for the given command.runz%Invalid operation [{}] for Flink CLI.z-Dgcloud.network={0}z-Dgcloud.subnetwork={0}z-Dgcloud.region={0}z-Dgcloud.deployment={0}z-Dgcloud.job.display-name={0}z-Dsqlz--jarz-Dexecution.target=gcloudz-Dgcloud.output-path={0}z!-Dgcloud.api.staging-location={0}z--filepythonz-Dgcloud.pipeline.jars={0}r1   rF   rH   z-Dpython.archives={0}z--targetz*-Dpython.client.executable={0}/bin/python3z#-Dpython.executable={0}/bin/python3z5-Dpython.pythonpath={0}/lib/python3.10/site-packages/z--pythonz--class)r   InvalidOperationForBinaryr9   listappend
startswithr,   rT   )r   commandjob_typejarr~   temp_dirtargetrelease_tracklocation
deploymentnetwork
subnetworkrc   
extra_jarsmanaged_kafka_clusters
main_class
extra_argsextra_archivespython_venvr   argsjob_argsargudfsj
env_folderarchivesarchive	class_args                                r!   _ParseArgsForCommand'FlinkClientWrapper._ParseArgsForCommand  sO   0 %77
1
8
8
A  6D
kk(//89
kk+22:>?
kk'..x89
kk+22:>?
kk188>? jvH			C	  5d	A
++g

++a. 
 )(//91889IJ  	 
X	d	0778LMN$$S)"-j)00=>h	%G
//#

//'
" &
 
  )//91889IJ:AA*M3:::FELL   !$ #* +2 i	
+	d	0778LMN J
' )//91889IJ  
 r    )r   r   )r   r   r   r   r   r   r   r   ReleaseTrackALPHAr   r   __classcell__)r   s   @r!   r   r      sQ    ,*00 %%++!'F Fr    r   )N)NN)8r   r   r*   urllibr   apitools.base.pyr   googlecloudsdk.api_lib.storager   r   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.artifactsr	   googlecloudsdk.command_lib.utilr
   &googlecloudsdk.command_lib.util.anthosr   googlecloudsdk.corer   core_exceptionsr   googlecloudsdk.core.credentialsr   googlecloudsdk.core.utilr   r   OperatingSystemWINDOWSidr+   r,   MACOSXLINUXDEFAULT_CONFIG_LOCATIONr   r   BETAGA_RELEASE_TRACK_TO_VERSIONr   rl   Errorr   r#   r/   rD   ra   ry   r   r   r   r   BinaryBackedOperationr   r   r    r!   <module>r      sa   @  	  % 6 7 ( . 9 0 D & = ) 6 .  %%(("'',,Xw+ $$''8##&&(L  	YH$   % 3o++ 35-- 5()Z 3745	)X\*@@ \r    