
    9iUP                        S r SSKrSSK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  \R"                  " \5      r\R(                  S   S:X  a  \\4rO\\4r " S S\R2                  5      rS r SS jrS rSS jrSS jrSS jr SS jr!SS jr"SS jr#SS jr$S r%S r&\" \'\S9SS j5       r(g) z.
This module provides a client class for BMR.
    N)bce_v1_signer)bce_base_client)compat)bce_http_client)handler)http_methods)required)aes128_encrypt_16char_key   c                      \ rS rSrSrSrS S jr\" \\\	S9              S!S j5       r
S"S jr\" \S	9S
 5       r\" \S	9S 5       r\" \S	9S 5       r\" \S	9S 5       r\" \\	S9S 5       r\" \\	S9S S j5       r\" \S	9S"S j5       r\" \\S9S 5       r\" \\S9S 5       r\" \\S9S 5       r\" \S	9S 5       r\" \S	9S 5       r\" \\S9S 5       rS S jr  S#S jrSrg)$	BmrClient)   z
Bmr sdk client
z/v1Nc                 B    [         R                  R                  X5        g N)r   BceBaseClient__init__)selfconfigs     `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/services/bmr/bmr_client.pyr   BmrClient.__init__0   s    %%..t<    )
image_typeimage_versioninstance_groupsc                    SnSnUb  SU0n[         R                  " U5      [         R                  " U5      US.nUb  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   U	b  U	US	'   U
b  U
US
'   Ub  UUS'   Ub<  U R                  b/  U R                  R                  R                  n[        UU5      US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   U R                  [        R                  UU[        R                  " U5      S9$ )a<  
Create cluster

:param image_type: the type of virtual machine image
:type image_type: string

:param image_version: the version of virtual machine image
:type image_version: string

:param instance_groups: instance groups for cluster
:type instance_groups: array

:return:
:rtype baidubce.bce_response.BceResponse
/clusterNclientToken)	imageTypeimageVersioninstanceGroupsapplicationsautoTerminatenamelogUristepsserviceHaEnabledsafeModeEnabledadminPasswordvpcIdsubnetIdsecurityGroupavailabilityZonetemplateTypeparamsbody)r   convert_to_stringr   credentialssecret_access_keyr
   _send_requestr   POSTjsondumps)r   r   r   r   client_tokenr!   auto_terminatelog_urir#   r%   service_ha_enabledsafe_mode_enabled
admin_passvpc_id	subnet_idsecurity_groupavailability_zoner-   pathr/   r0   r3   s                         r   create_clusterBmrClient.create_cluster3   sk   H #|F  11*="44]C-

 ##/D %$2D!DL$DN!DM)'9D#$(&7D"#!dkk&= $ 7 7 I I$=jJ[$\D!"DM (D%$2D!('8D#$##/D !!,"3"3T&tzzZ^O_!``r   c                 r    SnSnUc  Ub  0 nUb  XS'   Ub  X$S'   U R                  [        R                  X4S9$ )z
List clusters

:param marker:
:type marker: string

:param max_keys: max records returned.
:type max_keys: int

:return:
:rtype baidubce.bce_response.BceResponse
r   NmarkermaxKeysr/   )r4   r   GET)r   rF   max_keysrB   r/   s        r   list_clustersBmrClient.list_clusters   sV     !5F%8 (9!!,"2"2D!HHr   )
cluster_idc                 t    S[         R                  " U5      -  nU R                  [        R                  U5      $ )zx
Get cluster

:param cluster_id: cluster id
:type cluster_id: string

:return:
:rtype baidubce.bce_response.BceResponse
/cluster/%sr   r1   r4   r   rI   r   rM   rB   s      r   get_clusterBmrClient.get_cluster   s2     v77
CC!!,"2"2D99r   c                 t    S[         R                  " U5      -  nU R                  [        R                  U5      $ )z}
Get cluster hosts
:param cluster_id: cluster id
:type cluster_id: string

:return:
:rtype baidubce.bce_response.BceResponse
z/cluster/%s/hostsrP   rQ   s      r   list_cluster_hostsBmrClient.list_cluster_hosts   s2     #V%=%=j%II!!,"2"2D99r   c                 t    S[         R                  " U5      -  nU R                  [        R                  U5      $ )z
Get cluster ambari password

:param cluster_id: cluster id
:type cluster_id: string

:return:
:rtype baidubce.bce_response.BceResponse
z/cluster/%s/ambaripasswordrP   rQ   s      r   get_cluster_ambariPassword$BmrClient.get_cluster_ambariPassword   s2     ,f.F.Fz.RR!!,"2"2D99r   c                 t    S[         R                  " U5      -  nU R                  [        R                  U5      $ )z~
Terminate cluster

:param cluster_id: cluster id
:type cluster_id: string

:return:
:rtype baidubce.bce_response.BceResponse
rO   )r   r1   r4   r   DELETErQ   s      r   terminate_clusterBmrClient.terminate_cluster   s2     v77
CC!!,"5"5t<<r   )rM   instance_group_configc                     S[         R                  " U5      -  nSnSU0nU R                  [        R                  X4[
        R                  " U5      S9$ )a  
Scale cluster
:param cluster_id: cluster id
:type cluster_id: string

:param instance_group_id: instance group id
:type instance_group_id: string

:param instance_count: instance count
:type instance_count: int

:return:
:rtype baidubce.bce_response.BceResponse
/cluster/%s/instanceGroupNr    r.   )r   r1   r4   r   PUTr6   r7   )r   rM   r^   rB   r/   r0   s         r   scale_clusterBmrClient.scale_cluster   sU    " +V-E-Ej-QQ3
 !!,"2"2DdjjY]N^!__r   )rM   r%   c                     S[         R                  " U5      -  nSnUb  SU0n[        R                  " SU05      nU R	                  [
        R                  XEUS9$ )z
Add steps

:param cluster_id: cluster id
:type cluster_id: string

:param steps: steps to be added
:type steps: Array

:return:
:rtype baidubce.bce_response.BceResponse
/cluster/%s/stepNr   r%   r.   )r   r1   r6   r7   r4   r   r5   )r   rM   r%   r8   rB   r/   r0   s          r   	add_stepsBmrClient.add_steps   sc     "F$<$<Z$HH#|F zz7E*+!!,"3"3Tt!TTr   c                     S[         R                  " U5      -  nSnUc  Ub  0 nUb  X%S'   Ub  X5S'   U R                  [        R                  XES9$ )z
List step

:param cluster_id: cluster id
:type cluster_id: string

:param marker:
:type marker: string

:param max_keys: max records returned.
:type max_keys: int

:return:
:rtype baidubce.bce_response.BceResponse
re   NpageNopageSizerH   rP   )r   rM   ri   rj   rB   r/   s         r   
list_stepsBmrClient.list_steps   sf    " "F$<$<Z$HH!5F%8!):!!,"2"2D!HHr   )rM   step_idc                     S[         R                  " U5      < S[         R                  " U5      < 3nU R                  [        R                  U5      $ )z
Get step

:param cluster_id: cluster id
:type cluster_id: string

:param step_id: step id
:type step_id: string

:return: baidubce.bce_response.BceResponse
:rtype baidubce.bce_response.BceResponse
	/cluster//step/rP   )r   rM   rm   rB   s       r   get_stepBmrClient.get_step  s@     )/(@(@(L((13!!,"2"2D99r   )	clusterIdstepIdc                 V    SU< SU< 3nU R                  [        R                  U5      $ )z`

:param clusterId:cluster id
:param stepId: step id
:return: baidubce.bce_response.BceResponse
ro   rp   )r4   r   r[   )r   rs   rt   rB   s       r   cancel_stepBmrClient.cancel_step-  s'     )26:!!,"5"5t<<r   )rM   instance_group_idc                     S[         R                  " U5      < S[         R                  " U5      < S3nU R                  [        R                  U5      $ )z
List instances

:param cluster_id: cluster id
:type cluster_id: string

:param instance_group_id: instance group id
:type instance_group_id: string

:return:
:rtype baidubce.bce_response.BceResponse
ro   z/instanceGroup/z	/instancerP   )r   rM   rx   rB   s       r   list_instancesBmrClient.list_instances;  sC     ;A:R:RS]:^(():;=!!,"2"2D99r   c                 t    S[         R                  " U5      -  nU R                  [        R                  U5      $ )z
List instance groups

:param cluster_id: cluster id
:type cluster_id: string

:return:
:rtype: baidubce.bce_response.BceResponse
r`   rP   rQ   s      r   list_instance_groupsBmrClient.list_instance_groupsM  s2     +V-E-Ej-QQ!!,"2"2D99r   c                 x    SnSU0nSnU R                  [        R                  XB[        R                  " U5      S9$ )zc
:param cluster_id: clusterId
:type  cluster_id: string
:return: baidubce.bce_response.BceResponse
Nrs   z/cluster/detailr.   )r4   r   r5   r6   r7   )r   rM   r/   r0   rB   s        r   describe_clusterBmrClient.describe_cluster\  sD     
  !!,"3"3TtzzZ^O_!``r   rs   newNamec                     Ub  [        UR                  S5      5      S:X  a  [        S5      eSnUUS.nSnU R                  [        R
                  XS[        R                  " U5      S9$ )z
rename a cluster
:param clusterId: clusterId
:type  clusterId: string
:param newName: newName
:type  newName: string
:return: baidubce.bce_response.BceResponse
N r   znewName can not be empty.r   z/cluster/renamer.   )lenstrip
ValueErrorr4   r   r5   r6   r7   )r   rs   r   r/   r0   rB   s         r   rename_clusterBmrClient.rename_clusterj  sk     ?c'--"45:899"
 !!!,"3"3TtzzZ^O_!``r   c                     Uc  U R                   $ [        R                  " U R                   5      nUR                  U5        U$ r   )r   copymerge_non_none_values)r   r   
new_configs      r   _merge_configBmrClient._merge_config  s7    >;;4;;/J,,V4r   c           
      L   U R                  U5      nUc  [        R                  n[        R                  " UR
                  5      Ul        [        R                  " U[        SS/5      [        R                  U/U[        R                  " [        R                  U-   5      X4U5      $ )Ns   hosts
   x-bce-date)r   r   
parse_jsonr   convert_to_bytesendpointr   send_requestsign_wrapperparse_errorr   prefix)r   http_methodrB   r0   headersr/   r   body_parsers           r   r4   BmrClient._send_request  s     ##F+!,,K 11&//B++L'=!9:W=P=PR]<^001A1AD1HI4Z`b 	br    r   )NNNNNNNNNNNNNNNN)NNNNN)__name__
__module____qualname____firstlineno____doc__r   r   r	   
value_typelistrC   rK   rR   rU   rX   r\   rb   rf   rk   rq   rv   rz   r}   r   r   r   r4   __static_attributes__r   r   r   r   r   )   s    F= &"$ %)$(&*# !*.)-"&"!%&*)-$(#Ha$HaTI0 $: %: $
: %
: $: %: $= %= $(*`*`. 40U 1U, $I %I6 Z8: 9:  =	= zB: C:" $: %: $a %a 
 "a"a( 7;/3
br   r   c                    ^  U 4S jnU$ )z!wrapper the bce_v1_signer.sign().c           	        > [         R                  " U R                  5      U l        [         R                  " U R                  5      U l        [        R
                  " U [         R                  " U5      [         R                  " U5      X4TS9$ )N)headers_to_sign)r   r   access_key_idr3   r   sign)r2   r   rB   r   r/   r   s        r   _wrappersign_wrapper.<locals>._wrapper  sm    $*$;$;K<U<U$V!(.(?(?@]@](^%!!+"("9"9+"F"("9"9$"?2AC 	Cr   r   )r   r   s   ` r   r   r     s    C Or   c                 &    U UUUUUS.nUb  X7S'   U$ )aF  
Construct instance group

:param group_type: instance group type
:type group_type: ENUM {'Master', 'Core', 'Task'}

:param instance_type
:type instance_type: ENUM {'g.small', 'c.large', 'm.medium', 's.medium', 'c.2xlarge'}

:param instance_count
:type instance_count: int

:param name: instance group name
:type name: string
)typeinstanceCountinstanceTyperootDiskSizeInGBrootDiskMediumTypecdsr#   r   )
group_typeinstance_typeinstance_countr#   r   root_DiskSizeInGBroot_DiskMediumTypeinstance_groups           r   r   r     s3    $ '%-1N !%vr   c                     U US.nU$ )zw
:param sizeInGB: sizeInGB
:type string
:param mediumType: mediumType
:type string ssd, sata, premium_ssd
:return: cds
)sizeInGB
mediumTyper   )r   r   r   s      r   cdsitemr     s      C Jr   c                     U US.nUb  X#S'   U$ )a  
Construct application

:param name: application type
:type name: ENUM {'hadoop', 'spark', 'hive', 'pig', 'hbase', 'hue', 'zeppelin', 'kafka', 'mahout'}

:param version: application version
:type version: string

:param properties: application properties
:type properties: dict
)r#   version
propertiesr   )r#   r   r   applications       r   r   r     s'     K $.L!r   c                 L    UU US.nUb  X5S'   Ub  [        U5      S:  a  XES'   U$ )a  
Create step

:param step_type: the type of step
:type step_type: Enum {'Java','Streaming','Hive','Pig', 'Spark'}

:param action_on_failure
:type actionOnFailure: Enum {'Continue','TerminateCluster','CancelAndWait'}

:param properties: step properties
:type properties: dict

:param name: the name of the step
:type name: string

:param additional_files: list of step additional file
:type additional_files: list
)actionOnFailurer   r   r#   r   additionalFiles)r   )	step_typeaction_on_failurer   r#   additional_filessteps         r   r   r     sD    ( - D
 V#,<(=(A"2Kr   c                     U US.nUb  X#S'   U$ )z
Create java step properties

:param jar: the path of .jar file
:type jar: string

:param main_class: the package path for main class
:type main_class: string

:param arguments: arguments for the step
:type arguments: string

:return:
:rtype map
)jar	mainClass	argumentsr   )r   
main_classr   	java_steps       r   java_step_propertiesr     s'    " I !*+r   c                 0    USU US.nUb  X5S'   Ub  XES'   U$ )as  
Create streaming step properties

:param input: the input path of step
:type input: string

:param output: the output path of step
:type output: string

:param mapper: the mapper program of step
:type mapper: string

:param reducer: the reducer program of step
:type reducer: string

:param arguments: arguments for the step
:type arguments: string

:return:
:rtype map
 )mapperreducerinputoutputr   r   r   )r   r   r   r   r   streaming_steps         r   streaming_step_propertiesr     s;    . 	N $+y!&/{#r   c                 8    SU 0nUb  XS'   Ub  X$S'   Ub  X4S'   U$ )a'  
Create pig step properties

:param script: the script path of step
:type script: string

:param arguments: arguments for the step
:type arguments: string

:param input: the input path of step
:type input: string

:param output: the output path of step
:type output: string

:return:
:rtype map
scriptr   r   r   r   )r   r   r   r   pig_steps        r   pig_step_propertiesr   ?  sA    ( 	&H  )!#Or   c                 8    SU 0nUb  XS'   Ub  X$S'   Ub  X4S'   U$ )a(  
Create hive step properties

:param script: the script path of step
:type script: string

:param arguments: arguments for the step
:type arguments: string

:param input: the input path of step
:type input: string

:param output: the output path of step
:type output: string

:return:
:rtype map
r   r   r   r   r   )r   r   r   r   	hive_steps        r   hive_step_propertiesr   ^  sB    ( 	&I !*+"'$(r   c                     U US.nUb  X#S'   U$ )z
Create spark step properties

:param jar: the path of .jar file
:type jar: string

:param main_class: the package path for main class
:type main_class: string

:param arguments: arguments for the step
:type arguments: string

:return:
:rtype map
)r   submitOptionsr   r   )r   r   r   
spark_steps       r   spark_step_propertiesr   }  s'    " &J "+;r   c                     U US.$ )z
Create step additional file

:param remote: the remote file of the additional file
:type remote: string

:param local: the local file of the additional file
:type local: string

:return:
:rtype map
remotelocalr   r   s     r   additional_filer     s      r   c                     U US.nU$ )z
create instance_group
:param id: id
:type id: string
:param instanceCount: instanceCount
:type instanceCount: int
:return: instancegroup_config
)idr   r   )r   r   instancegroup_configs      r   r   r     s     &  r   period
periodUnitc                 ,    U US.nUb  X$S'   Ub  X4S'   U$ )z
:param period: period
:type id: int
:param periodUnit: periodUnit
:type id: string
:param startTime: startTime
:param endTime: endTime
:return: schedule
r   	startTimeendTimer   )r   r   r   r   schedules        r   schedule_propertiesr     s4      H  )%Or   )NN(   ssdr   r   )NNN))r   r   loggingr6   sysbaidubce.authr   baidubcer   r   baidubce.httpr   r   r   baidubce.utilsr	   r
   	getLoggerr   _loggerversion_infostrunicoder   bytesr   r   r   r   r   r   r   r   r   r   r   r   r   r   intr   r   r   r   <module>r     s       
 ( $  ) ! & # 4 

H
%A!wJuJib-- ibX
 SX>,>2 F>>2"  
	r   