
                            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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dZ e	j*                  e	j,                  j.                  e	j,                  j0                  e	j,                  j2                        e	j4                   G d de	j6                                      Zy)z7Advances a Cloud Deploy rollout to the specified phase.    )rollout)apis)
exceptions)base)delivery_pipeline_util)deploy_policy_util)flags)resource_args)log)
console_ioz{description}a        To advance a rollout `test-rollout` to phase `test-phase` for delivery pipeline `test-pipeline`, release `test-release` in region `us-central1`, run:

      $ {command} test-rollout --phase-id=test-phase --delivery-pipeline=test-pipeline --release=test-release --region=us-central1

)DESCRIPTIONEXAMPLESc                   n    e Zd ZdZeZed        Z ej                  e
j                        d        Zd Zy)AdvancezAdvances a rollout.c                     t        j                  | d       t        j                  | d       t        j                  |        y )NT)
positionalF)required)r
   AddRolloutResourceArgr	   
AddPhaseIdAddOverrideDeployPolicies)parsers    &lib/surface/deploy/rollouts/advance.pyArgszAdvance.Args2   s2    ''4@ 
Ve,	##F+    c                    |j                   j                  j                         }|j                         j                         }t	        j
                  |j                               }dj                  |j                               }t	        j                  ||       |j                  }|| j                  |      }t        j                  j                  dj                  |j                         |             t        j                  ||j                         }t        j"                         j%                  |j                         ||      S )NzCannot advance rollout {}.z"Advancing rollout {} to phase {}.
)override_deploy_policies)CONCEPTSr   ParseParentr   GetPipelineRelativeNameformatThrowIfPipelineSuspendedphase_id_DetermineNextPhaser   statusPrintr   CreateDeployPolicyNamesFromIDsr   RolloutClientAdvanceRollout)selfargsrollout_refpipeline_refpipeline_objfailed_activity_msgr$   policiess           r   RunzAdvance.Run;   s%    --''--/K%%'..0L)55!!#L 7==  " 33) }}H))+6hJJ-44$$&	
 "@@d33H   "11  "!) 2  r   c                    t        j                  dd      }t        j                         j	                  |j                               }|j                  |j                  j                  j                  k7  r$t        j                  |j                               d}t        |j                        D ]6  \  }}|j                  |j                  j                  j                  k(  s4|} n |%t        j                   |j                         d      |dk(  r%t        j                   |j                         d      |j                  j                  j"                  |j                  j                  j$                  g}|j                  |d	z
     }|j                  |vrIt        j                   |j                         d
j'                  |j(                  |j                              dj'                  |j                         |j                  |   j(                        }	t+        j,                  |	d       |j                  |   j(                  S )z?Determines the phase in which the advance command should apply.clouddeployv1)rollout_nameNzNo pending phases.)r6   r0   r   z(Cannot advance first phase of a rollout.   z7Prior phase {} is in {} state which is not advanceable.z8Are you sure you want to advance rollout {} to phase {}?T)cancel_on_no)	core_apisGetMessagesModuler   r)   Getr!   stateRolloutStateValueValuesEnumIN_PROGRESSdeploy_exceptionsRolloutNotInProgressError	enumeratephasesPhasePENDINGRolloutCannotAdvanceError	SUCCEEDEDSKIPPEDr"   idr   PromptContinue)
r+   r-   messagesropending_phase_indexindexphaseadvanceable_prior_phase_statesprior_phaseprompts
             r   r%   zAdvance._DetermineNextPhase^   s   **=$?H				 	$	$[%=%=%?	@B	xx8##88DDD77"//1  !")),u	;;CC	C# - "77"//12  a77"//1H 
 	++55++33&" ))/!34K >>77"//1GNN..+"3"3  HNN  "BII.A$B$E$EF f4899(),,,r   N)__name__
__module____qualname____doc___DETAILED_HELPdetailed_helpstaticmethodr   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionr@   HTTP_ERROR_FORMATr2   r%    r   r   r   r   )   sO    
  -, , 544))@--r   r   N)rV   "googlecloudsdk.api_lib.clouddeployr   googlecloudsdk.api_lib.utilr   r9   r   rZ   googlecloudsdk.callioper   !googlecloudsdk.command_lib.deployr   r   r@   r	   r
   googlecloudsdk.corer   googlecloudsdk.core.consoler   rW   ReleaseTracksReleaseTrackALPHABETAGADefaultUniverseOnlyCreateCommandr   r]   r   r   <module>rk      s    > 7 9 F ( D @ M 3 ; # 2 # T..33T5F5F5I5I ^-d   ^- ^-r   