
    x]                        S 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r\R0                   " S S\R2                  5      5       rS rS rS\4S jrS rg)zUpdate cluster command.    )	constants)dataproc)
exceptions)util)actions)arg_parsers)base)clusters)flags)user_sa_mapping_util)labels_util)log)timesNc                   .    \ rS rSrSr\S 5       rS rSrg)Update"   a  Update labels and/or the number of worker nodes in a cluster.

Update the number of worker nodes and/or the labels in a cluster.

## EXAMPLES

To resize a cluster, run:

  $ {command} my-cluster --region=us-central1 --num-workers=5

To change the number preemptible workers in a cluster, run:

  $ {command} my-cluster --region=us-central1 --num-preemptible-workers=5

To add the label 'customer=acme' to a cluster, run:

  $ {command} my-cluster --region=us-central1 --update-labels=customer=acme

To update the label 'customer=ackme' to 'customer=acme', run:

  $ {command} my-cluster --region=us-central1 --update-labels=customer=acme

To remove the label whose key is 'customer', run:

  $ {command} my-cluster --region=us-central1 --remove-labels=customer

c                 "   [         R                  " U R                  5       5      n[        R                  R                  U5        [        R                  " U5        [        R                  " USS9  [        R                  " USUR                  5        UR                  S[        SS9  UR                  SS9nUR                  S	[        R                   " S	S
S9[        SSS9  UR                  S[        SS9  UR                  S["        R$                  " SSS9SS9  UR                  SS[&        S9  [)        XR                  5       5        UR+                  5       nUR                  S["        R$                  " 5       SSS9  UR                  SSSSS9  UR                  S["        R$                  " 5       SS9  UR                  S SS!S"9  UR+                  5       nUR                  S#["        R$                  " 5       SS$S9  UR                  S%["        R,                  R.                  SS&S9  UR                  S'SSS(S9  UR                  S)["        R$                  " 5       S*S9  UR                  S+["        R,                  R.                  S&S9  UR                  S,SS-S"9  UR+                  5       nUR                  S.["        R$                  " 5       S/S9  UR                  S0SS1S"9  UR+                  5       nUR                  S2["        R$                  " 5       S3S9  UR                  S4["        R,                  R.                  S5S9  UR                  S6SS7S"9  UR+                  5       n[        R0                  " US8S99  UR                  S:SS;S"9  [2        R4                  " U5        g )<N25h)defaultupdatez--num-workersz.The new number of worker nodes in the cluster.typehelpT)mutexz--num-preemptible-workerszcThe `--num-preemptible-workers` flag is deprecated. Use the `--num-secondary-workers` flag instead.)warnz:The new number of preemptible worker nodes in the cluster.)actionr   hiddenr   z--num-secondary-workersz8The new number of secondary worker nodes in the cluster.z--graceful-decommission-timeout0s1d)lower_boundupper_bounda  
              The graceful decommission timeout for decommissioning Node Managers
              in the cluster, used when removing nodes. Graceful decommissioning
              allows removing nodes from the cluster without interrupting jobs in
              progress. Timeout specifies how long to wait for jobs in progress to
              finish before forcefully removing nodes (and potentially
              interrupting jobs). Timeout defaults to 0 if not set (for forceful
              decommission), and the maximum allowed timeout is 1 day.
              See $ gcloud topic datetimes for information on duration formats.
              z--min-secondary-worker-fractiona  Minimum fraction of new secondary worker nodes added in a scale up update operation, required to update the cluster. If it is not met, cluster updation will rollback the addition of secondary workers. Must be a decimal value between 0 and 1. Defaults to 0.0001.)r   r   z
--max-idlez        The duration after the last job completes to auto-delete the cluster,
        such as "2h" or "1d".
        See $ gcloud topic datetimes for information on duration formats.
        )r   r   r   z--no-max-idle
store_truezt        Cancels the cluster auto-deletion by cluster idle duration (configured
         by --max-idle flag)
        )r   r   r   z--delete-max-idlez--no-delete-max-idlezz        Cancels the cluster auto-deletion by cluster idle duration (configured
        by --delete-max-idle flag)
        )r   r   z	--max-agez        The lifespan of the cluster, with auto-deletion upon completion,
        "2h" or "1d".
        See $ gcloud topic datetimes for information on duration formats.
        z--expiration-timez        The time when the cluster will be auto-deleted, such as
        "2017-08-29T18:52:51.142Z". See $ gcloud topic datetimes for
        information on time formats.
        z--no-max-agez        Cancels the cluster auto-deletion by maximum cluster age (configured by
         --max-age or --expiration-time flags)
        z--delete-max-agez        The lifespan of the cluster with auto-deletion upon completion,
        such as "2h" or "1d".
        See $ gcloud topic datetimes for information on duration formats.
        z--delete-expiration-timez--no-delete-max-agez        Cancels the cluster auto-deletion by maximum cluster age (configured
        by --delete-max-age or --delete-expiration-time flags)
        z--stop-max-idlez        The duration after the last job completes to auto-stop the cluster,
        such as "2h" or "1d".
        See $ gcloud topic datetimes for information on duration formats.
        z--no-stop-max-idlezt        Cancels the cluster auto-stop by cluster idle duration (configured
        by --stop-max-idle flag)
        z--stop-max-agez        The lifespan of the cluster, with auto-stop upon completion,
        such as "2h" or "1d".
        See $ gcloud topic datetimes for information on duration formats.
        z--stop-expiration-timez        The time when the cluster will be auto-stopped, such as
        "2017-08-29T18:52:51.142Z". See $ gcloud topic datetimes for
        information on time formats.
        z--no-stop-max-agez        Cancels the cluster auto-stop by maximum cluster age (configured by
        --stop-max-age or --stop-expiration-time flags)
        v1)api_versionz--disable-autoscalingz        Disable autoscaling, if it is enabled. This is an alias for passing the
        empty string to --autoscaling-policy'.
        )dpDataprocReleaseTrackr	   
ASYNC_FLAGAddToParserr   AddUpdateLabelsFlagsr   AddTimeoutFlagAddClusterResourceArgr$   add_argumentintadd_argument_groupr   DeprecationActionr   Durationfloat_AddAlphaArgumentsadd_mutually_exclusive_groupDatetimeParse)AddAutoscalingPolicyResourceArgForClusterr   AddUpdateUserSaMappingFlags)	clsparserr   num_secondary_workersidle_delete_groupauto_delete_groupidle_stop_groupauto_stop_groupautoscaling_groups	            'lib/surface/dataproc/clusters/update.pyArgsUpdate.Args@   s#   {{3++-.HOO'$$V, 
/	(2F2FG
=  ? #55D5A&&#(('DF I ' K &&!G ' I
 )!!dE	   )   
 v//12;;=""!!#	 #  ""	 #  ""!!# #  "" #  ;;=""!!#	 #  ""!!''	 #  ""	 #  ""!!# #  """!!'' #  "" #  99;O  !!# !     !  99;O  !!# !     !!'' !     !  ;;=	33t-"" #  44V<    c           
      P  ^^ [         R                  " U R                  5       5      mUR                  R                  R                  5       mTR                  R                  5       n/ nSnSnUR                  b<  TR                  R                  UR                  S9nXbl
        UR                  S5        Sn[        UR                  UR                  5      nUb2  TR                  R                  US9nXbl        UR                  S5        SnUR                   b  UR                  c;  TR                  R                  TR                  R#                  UR                   S9S9nO;TR                  R                  UTR                  R#                  UR                   S9S	9nXbl        UR                  S
5        SnU R                  5       [$        R                  R&                  :X  a  UR(                  b  UR                  cR  TR                  R                  TR                  R+                  TR                  R-                  UR(                  S9S9S9nOgTR                  R                  UUR                  R.                  TR                  R+                  TR                  R-                  UR(                  S9S9S9nXbl        UR                  S5        SnUR0                  (       ab  TR                  R3                  UR                  R0                  R                  5       R5                  5       S9Ul        UR                  S5        SnO4UR0                  S:X  d  UR8                  (       a  UR                  S5        SnTR                  R;                  5       nSn	UR<                  b;  [>        R@                  " UR<                  5      S-   Ul!        UR                  S5        Sn	URD                  b8  [F        RH                  " URD                  5      Ul%        UR                  S5        Sn	URL                  b;  [>        R@                  " URL                  5      S-   Ul'        UR                  S5        Sn	URP                  (       a  S Ul!        UR                  S5        Sn	URR                  (       a  S Ul'        UR                  S5        Sn	URT                  b;  [>        R@                  " URT                  5      S-   Ul!        UR                  S5        Sn	URV                  b8  [F        RH                  " URV                  5      Ul%        UR                  S5        Sn	URX                  b;  [>        R@                  " URX                  5      S-   Ul'        UR                  S5        Sn	URZ                  (       a  S Ul!        UR                  S5        Sn	UR\                  (       a  S Ul'        UR                  S5        Sn	UR^                  b;  [>        R@                  " UR^                  5      S-   Ul0        UR                  S5        Sn	URb                  b8  [F        RH                  " URb                  5      Ul2        UR                  S5        Sn	URf                  b;  [>        R@                  " URf                  5      S-   Ul4        UR                  S5        Sn	URj                  (       a  S Ul0        UR                  S5        Sn	URl                  (       a  S Ul4        UR                  S5        Sn	U	(       a  Xl7        SnUU4S jn
[p        Rr                  " UTR                  Rt                  Rv                  U
S9nURx                  (       a  SnUR                  S5        UR{                  5       nUU4S jnU4S jnUR|                  (       d  UR~                  (       a  [        [        TT5      5      (       d  [        R                  " S5      e[        Rr                  " UTR                  R                  R                  US 9nURx                  (       a  UR                  S!5        SnO,UR|                  (       a  US"-  nUR~                  (       a  US#-  nUR{                  5       nU(       a	  U" UU5        OUR                  (       a  [        [        TT5      5      (       d  [        R                  " S5      eUR                  c  TR                  R                  5       UlH        [        R                  " TUR                  5      UR                  lL        UR                  S!5        SnU(       d  [        R                  " U5      eTR                  Ru                  UTR                  UTR                  S$9nTR                  R                  TR                  TR                  TR                  US%R                  U5      [        R                  " 5       S&9nUR                  b(  [>        R@                  " UR                  5      S-   UlU        TR                  R                  R                  U5      nUR                  (       a:  [        R                  R                  S'R                  TUR                  5      5        g [        R                  " TUS(UR                  S)9  TR                  R                  TR                  TR                  TR                  S*9nTR                  R                  R                  U5      n[        R                  " T5        U$ )+NFz6Must specify at least one cluster parameter to update.)numInstancesz"config.worker_config.num_instancesTz,config.secondary_worker_config.num_instances)requiredRegistrationFraction)startupConfig)rF   rH   zLconfig.secondary_worker_config.startup_config.required_registration_fraction)standardCapacityBase)provisioningModelMix)instanceFlexibilityPolicy)rF   rH   rK   zhconfig.secondary_worker_config.instance_flexibility_policy.provisioning_model_mix.standard_capacity_base)	policyUriz$config.autoscaling_config.policy_uri sz'config.lifecycle_config.auto_delete_ttlz(config.lifecycle_config.auto_delete_timez'config.lifecycle_config.idle_delete_ttlz%config.lifecycle_config.auto_stop_ttlz&config.lifecycle_config.auto_stop_timez%config.lifecycle_config.idle_stop_ttlc                  4   > [        TT5      n U R                  $ N)_GetCurrentClusterlabelscurrent_clustercluster_refr   s    rA   _GetCurrentLabels%Update.Run.<locals>._GetCurrentLabels  s     +8[Ao###rD   )orig_labels_thunkrR   c                     > [        TT5      n U R                  R                  (       aO  U R                  R                  R                  (       a*  U R                  R                  R                  R                  $ g rP   )rQ   configsecurityConfigidentityConfiguserServiceAccountMappingrS   s    rA   $_GetCurrentUserServiceAccountMapping8Update.Run.<locals>._GetCurrentUserServiceAccountMapping  sZ    *8[Ao

 
 
/
/$$33BB ""11@@ZZ	
 rD   c                   > U R                   c  TR                  R                  5       U l         U R                   R                  c)  TR                  R	                  5       U R                   l        UU R                   R                  l        g rP   )r[   messagesSecurityConfigr\   IdentityConfigr]   )cluster_configuser_sa_mappingr   s     rA   _UpdateSecurityConfig)Update.Run.<locals>._UpdateSecurityConfig  sq    		&	&	.(0(9(9(H(H(J%		&	&	5	5	=,,. 	%%4
  ##22LrD   zKUser service account mapping can only be updated for multi-tenant clusters.)orig_user_sa_mapping_thunkzCconfig.security_config.identity_config.user_service_account_mappingz; User to add is already present in service account mapping.z: User to remove is not present in service account mapping.)rZ   clusterNamerR   	projectId,)ri   regionrj   cluster
updateMask	requestIdz$Updating [{0}] with operation [{1}].z$Waiting for cluster update operation)message	timeout_srj   rl   ri   )dr%   r&   r'   CONCEPTSrm   r6   ra   ClusterConfignum_workersInstanceGroupConfigworkerConfigappend_FirstNonNonenum_preemptible_workersr;   secondaryWorkerConfigmin_secondary_worker_fractionStartupConfigr	   ALPHA'secondary_worker_standard_capacity_baseInstanceFlexibilityPolicyProvisioningModelMixrH   autoscaling_policyAutoscalingConfigRelativeNameautoscalingConfigdisable_autoscalingLifecycleConfigmax_agesix	text_typeautoDeleteTtlexpiration_timer   FormatDateTimeautoDeleteTimemax_idleidleDeleteTtl
no_max_ageno_max_idledelete_max_agedelete_expiration_timedelete_max_idleno_delete_max_ageno_delete_max_idlestop_max_ageautoStopTtlstop_expiration_timeautoStopTimestop_max_idleidleStopTtlno_stop_max_ageno_stop_max_idlelifecycleConfigr   ProcessUpdateArgsLazyClusterLabelsValueneeds_update	GetOrNoneadd_user_mappingsremove_user_mappings_IsMultitenancyClusterrQ   r   ArgumentErrorr   rc   UserServiceAccountMappingValueidentity_config_filer[   rb   r
   ParseIdentityConfigFiler\   ri   rj   +DataprocProjectsRegionsClustersPatchRequestrl   joinr   GetUniqueIdgraceful_decommission_timeoutgracefulDecommissionTimeoutclientprojects_regions_clustersPatchasync_r   statuswriteformatnameWaitForOperationtimeout)DataprocProjectsRegionsClustersGetRequestGetUpdatedResource)selfargsrd   changed_fieldshas_changesno_update_error_msgworker_configr;   lifecycle_configchanged_configrV   labels_updaterR   r^   rf   user_sa_mapping_updatere   rm   request	operationrU   r   s                       @@rA   Run
Update.Run  s	
   {{4,,./H--''--/K&&446NNK@  #'';;'' < )m$1!@Ak)$*F*F*.*D*DF('';;, < .m-:*
8:k))5		-	-	5 ))=="++9966 :  > 
 !))==."++9966 :  > 
 .;*
X kd//555		5	5	A//7"++??(0(9(9(S(S'/'8'8'M'M+/+W+W (N ( )T ) @ - #++??0*@@NN(0(9(9(S(S'/'8'8'M'M+/+W+W (N ( )T ) @ - 0=,v	
 )1):):)L)LMM44::<IIK *M *Mn&BCk		 	 B	&$*B*B BCk((88:N
 ||'*}}T\\'BS'H$EFn'(-(<(<


) %FGn}} '*}}T]]'Cc'I$EFn'+$EFn'+$EFn&
--++
,s
2 $ EFn"".(-(<(<

%
%)% FGn'
--,,
-
3 $ EFn'+$EFn'+$EFn$%(]]43D3D%E%K"CDn  ,&+&:&:

#
#'%#DEn%%(]]43E3E%F%L"CDn%)"CDn%)"CDn'7$k$  55h''33+-M !!kH%$$&F	
 !:!:#$6x$MNN&&
 	
  4II




*
*
I
I%I 
 
 	,	,Q	
 !!
K
 $$
J
 /88:o	no>		"	"#$6x$MNN&&
 	
 
	&	&	.(0(9(9(H(H(J%

*
*8T5N5N
O ##2 
O k$$%899''++''	 ( )G KK++!!''88N+""$ L &G ))5
--::
;c
A ) 99??HI{{	jj
0
7
79>>+, 6,,	  II''!!++ J -G oo77;;GDG$NrD    N)	__name__
__module____qualname____firstlineno____doc__classmethodrB   r   __static_attributes__r   rD   rA   r   r   "   s$    8 E= E=NdrD   r   c                     U b  U $ U$ rP   r   )firstseconds     rA   ry   ry   /  s    #//rD   c                 l    U[         R                  R                  :X  a  U R                  S[        SS9  g g )Nz)--secondary-worker-standard-capacity-basezf
              The number of standard VMs in the Spot and Standard Mix
        feature.
              r   )r	   r'   r~   r-   r.   )r:   release_tracks     rA   r3   r3   3  s9    d''---
3   .rD   returnc                 T   U R                   nU(       a  UR                  (       a  UR                  R                  (       ai  UR                  R                  nUR                   HC  nUR                  [
        R                  :X  d  M#  UR                  R                  5       S:X  d  MC    g   g)zChecks if the cluster is a multi-tenant cluster.

Args:
  cluster: The cluster configuration.

Returns:
  True if the cluster is a multi-tenant cluster, False otherwise.
trueTF)	rZ   softwareConfig
propertiesadditionalPropertieskeydataproc_constants%ENABLE_DYNAMIC_MULTI_TENANCY_PROPERTYvaluelower)rm   rZ   propsprops       rA   r   r   A  sw     >>&%%&*?*?*J*J!!,,E**
(((NN
Njj F* + 
rD   c                     U R                   R                  UR                  UR                  UR                  S9nU R
                  R                  R                  U5      nU$ )zRetrieves the current cluster configuration.

Args:
  dataproc: The Dataproc API client.
  cluster_ref: The reference to the cluster.

Returns:
  The current cluster configuration.
rr   )ra   r   rj   rl   ri   r   r   r   )r   rU   get_cluster_requestrT   s       rA   rQ   rQ   V  se     AA))##!-- B   OO==AA/ 
rD   ) r   googlecloudsdk.api_lib.dataprocr   r   r   r%   r   r   googlecloudsdk.callioper   r   r	   #googlecloudsdk.command_lib.dataprocr
   r   )googlecloudsdk.command_lib.dataproc.utilsr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r   UniverseCompatibleUpdateCommandr   ry   r3   boolr   rQ   r   rD   rA   <module>r      sz      K : 6 0 + / ( 8 5 J < # * 
 IT I IX0t *rD   