
    43                     j   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r\
R(                  \
R*                  \
R,                  " \
R.                  R0                  \
R.                  R2                  5       " S S\
R4                  5      5       5       5       rg)z"Command to migrate an environment.    )environments_util)operations_util)util)arg_parsers)base)flags)image_versions_util)resource_args)logNc                   @    \ rS rSrSr\S 5       rS rS rS r	S r
Srg	)
Migrate   zMigrates an environment from Composer 2 to Composer 3 in-place.

If run asynchronously with `--async`, exits after printing an operation
that can be used to poll the status of the creation operation via:

  {top_command} composer operations describe
c           
      ,   [         R                  " US5        [        R                  R	                  U5        [
        R                  " SS5      nUR                  SUSSSS9  UR                  S	SS
9nUR                  SSSS9  UR                  SSSS9  UR                  SS9n[        R                  R	                  U5        [        R                  R	                  U5        [        R                  R	                  U5        UR                  SSS9nUR                  S[        SSS9  UR                  S[
        R                  " SSSS/SS9SSS9  UR                  S [
        R                  " SS!9SS"S9  UR                  S#[         SS$S9  UR                  S%S9n[        R"                  R	                  U5        [        R$                  R	                  U5        [        R&                  R	                  U5        [        R(                  R	                  U5        UR                  S&S9n[        R*                  R	                  U5        [        R,                  R	                  U5        [        R.                  R	                  U5        [        R0                  R	                  U5        [        R2                  R	                  U5        UR                  S'S9n[        R4                  R	                  U5        [        R6                  R	                  U5        [        R8                  R	                  U5        UR                  S(S9n	[        R:                  R	                  U	5        [        R<                  R	                  U	5        [        R>                  R	                  U	5        g ))Nz
to migratez=^composer-3-airflow-(\d+(?:\.\d+(?:\.\d+(?:-build\.\d+)?)?)?)zmust be in the form 'composer-3-airflow-X[.Y[.Z]]' For example: 'composer-3-airflow-2.3.4-build.5'. Only migrations to Composer 3 are supported.z--image-versionIMAGE_VERSIONTap          Migrate the Composer 2 environment to this Composer 3 version in-place.

        The image version encapsulates the versions of both Cloud Composer and
        Apache Airflow. Must be of the form
        `composer-3-airflow-X[.Y[.Z[-build.N]]]`, where `[]` denotes optional
        fragments.

        Examples: `composer-3-airflow-2`, `composer-3-airflow-2.2`,
        `composer-3-airflow-2.3.4`, `composer-3-airflow-2.3.4-build.5`.

        The Cloud Composer portion of the image version must be a Composer 3
        version. The Apache Airflow portion of the image version can be a
        semantic version or an alias in the form of major or major.minor
        version numbers, resolved to the latest matching Apache Airflow version
        supported in the given Cloud Composer version. The resolved versions are
        stored in the migrated environment.
        )typemetavarrequiredhelpzSpecify what should happen to the Composer 2 GKE cluster after migration. If cluster is retained, until deleted manually it will contribute to enviornment's cost.)r   r   z--retain-gke-cluster
store_truez.Retain Composer 2 GKE cluster after migration.)actionr   z--delete-gke-clusterz.Delete Composer 2 GKE cluster after migration.a  Specify the maintenance window for the migrated environment. It will override the current maintenance window. If not specified, and the enviornment uses Composer 2 default maintenance window, the migrated environment will use the Composer 3 default maintenance window.)r   zJSpecify the configuration of DAG processor for the Composer 3 environment.)r   r   z--dag-processor-cpuz&CPU allocated to Airflow dag processor)r   r   r   z--dag-processor-memory1GB128GBMBGBG)lower_boundupper_boundsuggested_binary_size_scalesdefault_unitzfMemory allocated to Airflow dag processor, ex. 1GB, 3GB, 2. If units are not provided, defaults to GB.z--dag-processor-storage)r   ziStorage allocated to Airflow dag processor, ex. 600MB, 3GB, 2. If units are not provided, defaults to GB.z--dag-processor-countzNumber of dag processorszGroup of arguments for setting scheduler configuration in migrated Composer environment. If not specified, the current scheduler configuration will be preserved.zGroup of arguments for setting worker configuration in migrated Composer environment. If not specified, the current worker configuration will be preserved.zGroup of arguments for setting web server configuration in migrated Composer environment. If not specified, the current web server configuration will be preserved.zGroup of arguments for setting triggerer configuration in migrated Composer environment. If not specified, the current triggerer configuration will be preserved.) r
   AddEnvironmentResourceArgr   
ASYNC_FLAGAddToParserr   RegexpValidatoradd_argumentadd_mutually_exclusive_groupadd_argument_groupr   MAINTENANCE_WINDOW_START_FLAGMAINTENANCE_WINDOW_END_FLAG"MAINTENANCE_WINDOW_RECURRENCE_FLAGfloat
BinarySizeintSCHEDULER_CPUSCHEDULER_MEMORYSCHEDULER_STORAGENUM_SCHEDULERS
WORKER_CPUWORKER_MEMORYWORKER_STORAGEMIN_WORKERSMAX_WORKERSWEB_SERVER_CPUWEB_SERVER_MEMORYWEB_SERVER_STORAGETRIGGERER_CPUTRIGGERER_MEMORYTRIGGERER_COUNT)
clsparsertarget_version_type"gke_cluster_retention_policy_groupmaintenance_window_groupdag_processor_groupscheduler_groupworker_groupweb_server_grouptriggerer_groups
             ,lib/surface/composer/environments/migrate.pyArgsMigrate.Args*   s   ++FLAOO'%55H	    2 *0)L)L2  *M *& '33= 4 
 '33= 4   &88#  9   
''334LM	%%112JK	,,88  !33' 4  $$5	 %  $$ ##*.	
 7 %  $$!##
 7 % 
 $$'	 %  //0 0 O 
##O4	&&7	''8	$$_5,,0 - L 
  .	##L1	$$\2	!!,/	!!,/007 1  
$$%56	''(89	(()9://0 0 O 
##O4	&&7	%%o6    c                     [         R                  " UR                  R                  R                  5      (       a%  [         R
                  " UR                  5      (       d  [        R                  " S5      eg )Nz:Migration is only supported from Composer 2 to Composer 3.)	image_versions_command_utilIsImageVersionStringComposerV2configsoftwareConfigimageVersionIsImageVersionStringComposerV3image_versioncommand_utilInvalidUserInputError)selfenv_objargss      rF   	_ValidateMigrate._Validate   sa    &EE%%22 (GG  ..
F rI   c                    [         R                  " US9nUR                  (       a   UR                  R                  R
                  $ UR                  (       a   UR                  R                  R                  $ [        R                  " S5      e)Nrelease_trackzFOne of --retain-gke-cluster or --delete-gke-cluster must be specified.)
api_utilGetMessagesModuleretain_gke_clusterMigrateEnvironmentRequest(GkeClusterRetentionPolicyValueValuesEnumRETAIN_GKE_CLUSTERdelete_gke_clusterDELETE_GKE_CLUSTERrR   rS   )rT   rV   r[   messagess       rF   #_ConstructGkeClusterRetentionPolicy+Migrate._ConstructGkeClusterRetentionPolicy   st    ))FH

,
,
U
U
h
h 
	 	 

,
,
U
U
h
h .. rI   c           	      r   [         R                  " US9n[        UR                  UR                  [
        R                  " UR                  5      [
        R                  " UR                  5      UR                  S9S9nUR                  (       d3  UR                  (       d"  UR                  (       d  UR                  (       ae  UR                  UR                  [
        R                  " UR                  5      [
        R                  " UR                  5      UR                  S9US'   UR                  (       dD  UR                   (       d3  UR"                  (       d"  UR$                  (       d  UR&                  (       ap  UR)                  UR                  [
        R                  " UR                   5      [
        R                  " UR"                  5      UR$                  UR&                  S9US'   UR*                  (       d"  UR,                  (       d  UR.                  (       aZ  UR1                  UR*                  [
        R                  " UR,                  5      [
        R                  " UR.                  5      S9US'   UR2                  (       d"  UR4                  (       d  UR6                  (       aF  UR9                  UR2                  [
        R                  " UR4                  5      UR6                  S	9US
'   [        UR:                  UR<                  " S0 UD6U R?                  X5      S9nUR@                  (       ap  URB                  (       a_  URD                  (       aN  URG                  UR@                  RI                  5       URB                  RI                  5       URD                  S9US'   URJ                  " S0 UD6$ )NrZ   )cpumemoryGb	storageGbcount)dagProcessor	scheduler)rh   ri   rj   minCountmaxCountworker)rh   ri   rj   	webServer)rh   ri   rk   	triggerer)rO   workloadsConfiggkeClusterRetentionPolicy)	startTimeendTime
recurrencemaintenanceWindow )&r\   r]   dictDagProcessorResourcedag_processor_cpuenvironments_api_utilMemorySizeBytesToGBdag_processor_memorydag_processor_storagedag_processor_countscheduler_cpuscheduler_memoryscheduler_storagescheduler_countSchedulerResource
worker_cpuworker_memoryworker_storagemin_workersmax_workersWorkerResourceweb_server_cpuweb_server_memoryweb_server_storageWebServerResourcetriggerer_cputriggerer_memorytriggerer_countTriggererResourcerQ   WorkloadsConfigre   maintenance_window_startmaintenance_window_endmaintenance_window_recurrenceMaintenanceWindow	isoformatr_   )rT   rV   r[   rd   workloads_configmigrate_requests         rF   #_ConstructMigrateEnvironmentRequest+Migrate._ConstructMigrateEnvironmentRequest   s   ))FH22&&*>>)) ,??** ** 3 	
 	  !!&.&@&@  (<<## *==$$ $$ 'A 	'{# 	#+#:#:oo(<<   *==!! #### $; 
$x  d448O8O&.&@&@!!(<<$$ *==%% 'A '{# T22d6J6J&.&@&@  (<<## $$ 'A '{# '' 00D3CD"&"J"J#
O 	%%''..-5-G-G11;;=--77977 .H .o)*
 --@@@rI   c           	      <   UR                   R                  R                  5       n[        R                  " X R                  5       S9nU R                  X15        U R                  XR                  5       5      n[        R                  " UUU R                  5       S9nUR                  (       a@  [        R                  " UR                  5       SSSR                  UR                  5      S9  U$  [        R                   " USR                  UR                  5       UR                  5      U R                  5       S9  g ! ["        R$                   aM  n["        R$                  " SR                  UR                  5       [&        R(                  " U5      5      5      eS nAff = f)	NrZ   )environment_refrequestr[   environmentTzwith operation [{0}])kindis_asyncdetailsz(Waiting for [{}] to be updated with [{}]zError updating [{}]: {})CONCEPTSr   Parser}   GetReleaseTrackrW   r   r   async_r   UpdatedResourceRelativeNameformatnameoperations_api_utilWaitForOperationrR   Errorsix	text_type)rT   rV   env_refrU   r   	operationes          rF   RunMigrate.Run=  sW   mm''--/G#''0024GNN7!66!G &--'')I {{	



 (//	?	 5**

4
;
;""$inn6))+	-
  58??



 #--"2 4 5 55s   -AD: :FAFFry   N)__name__
__module____qualname____firstlineno____doc__classmethodrG   rW   re   r   r   __static_attributes__ry   rI   rF   r   r      s5     `7 `7D TAl5rI   r   )r   googlecloudsdk.api_lib.composerr   r}   r   r   r   r\   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.composerr   r	   rK   r
   rR   googlecloudsdk.corer   r   DefaultUniverseOnlyHiddenReleaseTracksr   ALPHABETACommandr   ry   rI   rF   <module>r      s    ) V R < / ( 5 b = D # 
 D%%++T->->-C-CD{5dll {5 E  {5rI   