
    P                         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r " S S\R(                  5      r " S S\5      rg)z.Database Migration Service migration jobs API.    )encoding)
list_pager)api_util)conversion_workspaces)filter_rewrite)storage_util)base)
exceptions)labels_util)resource_propertyNc                       \ rS rSrSrSrg)Error    z.Class for errors raised by container commands. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       ?lib/googlecloudsdk/api_lib/database_migration/migration_jobs.pyr   r       s    6r   r   c                   X   \ rS rSrSr/ SQr/ SQrS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S) r+S* r,S+ r-S, r.    S5S. jr/S6S/ jr0 S6S0 jr1 S6S1 jr2S2 r3S3 r4S4r5g-)7MigrationJobsClient$   z-Client for migration jobs service in the API.)display_nametype	dump_pathsourcedestination
dump_flags)vm_ipvm_portvmvpcc                 j   [         R                  " U5      U l        [         R                  " U5      U l        U R                  R
                  U l        U[        R                  R                  :X  a  U R                  R                  U l        OS U l        [         R                  " U5      U l        Xl        g N)r   GetClientInstanceclientGetMessagesModulemessages projects_locations_migrationJobs_servicer	   ReleaseTrackGA(projects_locations_migrationJobs_objects_service_objectsGetResourceParserresource_parserrelease_track)selfr4   s     r   __init__MigrationJobsClient.__init__2   s    ,,];DK..}=DMKK@@DM)),,,
++
>
>  #d#55mDD&r   c                 &    U R                  U5        g r'   )_ValidateDumpPathr5   argss     r   _ValidateArgs!MigrationJobsClient._ValidateArgs?   s    4 r   c                     UR                   c  g  [        R                  R                  UR                   SS9  g ! [         a0  n[
        R                  " S[        R                  " U5      5      eS nAff = f)NF)allow_empty_objectz	dump-path)	r   r   ObjectReferenceFromArgument	Exceptionr
   InvalidArgumentExceptionsix	text_type)r5   r;   es      r   r9   %MigrationJobsClient._ValidateDumpPathB   sg    ~~O""//
..U 0   O//S]]1=MNNOs   (9 
A3+A..A3c                     Uc[  UR                  S5      (       a  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      egg)aC  Validate flags for conversion workspace.

Args:
  conversion_workspace_ref: str, the reference of the conversion workspace.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Raises:
  BadArgumentException: commit-id or filter field is provided without
  specifying the conversion workspace
N	commit_id	commit-idoConversion workspace commit-id can only be specified for migration jobs associated with a conversion workspace.filterWFilter can only be specified for migration jobs associated with a conversion workspace.)IsKnownAndSpecifiedr
   BadArgumentException)r5   conversion_workspace_refr;   s      r    _ValidateConversionWorkspaceArgs4MigrationJobsClient._ValidateConversionWorkspaceArgsL   so      '		!	!+	.	.--J
 	
 
	!	!(	+	+--0
 	
 
, (r   c                     UR                   c[  UR                  S5      (       a  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      egg)aQ  Validate flags for conversion workspace.

Args:
  conversion_workspace: str, the internal migration job conversion workspace
    message.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Raises:
  BadArgumentException: commit-id or filter field is provided without
  specifying the conversion workspace
NrI   rJ   rK   rL   rM   )namerN   r
   rO   )r5   conversion_workspacer;   s      r   '_ValidateConversionWorkspaceMessageArgs;MigrationJobsClient._ValidateConversionWorkspaceMessageArgsj   su       (		!	!+	.	.--J
 	
 
	!	!(	+	+--0
 	
 
, )r   c                 8    UR                   R                  U5      $ r'   )TypeValueValuesEnumlookup_by_name)r5   mj_type
type_values      r   _GetTypeMigrationJobsClient._GetType   s    &&55jAAr   c                 8    UR                   R                  U5      $ r'   )DumpTypeValueValuesEnumrZ   )r5   	dump_typedump_type_values      r   _GetDumpType MigrationJobsClient._GetDumpType   s    ,,;;OLLr   c                 H    U R                   R                  UR                  S9$ )N)r%   )r+   VpcPeeringConnectivitypeer_vpcr:   s     r   _GetVpcPeeringConnectivity.MigrationJobsClient._GetVpcPeeringConnectivity   s    ==//DMM/BBr   c                     U R                   R                  UR                  UR                  UR                  UR
                  S9$ )N)r$   vmIpvmPortr%   )r+   ReverseSshConnectivityr$   r"   r#   r%   r:   s     r   _GetReverseSshConnectivity.MigrationJobsClient._GetReverseSshConnectivity   s7    ==//77DLLdhh 0  r   c                 6    U R                   R                  5       $ r'   )r+   StaticIpConnectivityr5   s    r   _GetStaticIpConnectivity,MigrationJobsClient._GetStaticIpConnectivity   s    ==--//r   c                 b   [         R                  " U5      n[         R                  " U5      nU R                  R                  R
                  n[         R                  " UUUR                  S9R                  U5      nUR                  (       a#  UR                  Ul
        UR                  S5        gg)z$Updates labels of the migration job.)	additionssubtractionsclearlabelsN)r   GetUpdateLabelsDictFromArgsGetRemoveLabelsListFromArgsr+   MigrationJobLabelsValueDiffclear_labelsApplyneeds_updatery   append)r5   r;   migration_jobupdate_fields
add_labelsremove_labels
value_typeupdate_results           r   _UpdateLabels!MigrationJobsClient._UpdateLabels   s    88>J;;DAM++77J$$" eJ	 
 !!*11m8$ "r   c                     [         R                  " U R                  S9nUR                  R	                  US9nUR
                  c  [        R                  " SS5      eU$ )zReturns the conversion workspace.

Args:
  conversion_workspace_name: str, the reference of the conversion workspace.

Raises:
  BadArgumentException: Unable to fetch latest commit for the specified
  conversion workspace.
r4   rT   conversion-workspacerUnable to fetch latest commit for the specified conversion workspace. Conversion Workspace might not be committed.)r   ConversionWorkspacesClientr4   crudReadlatestCommitIdr
   rO   )r5   conversion_workspace_name	cw_clientrU   s       r   _GetConversionWorkspace+MigrationJobsClient._GetConversionWorkspace   sn     &@@((I %>>..& /  **2++
 I   r   c                     U R                   R                  UR                  5       S9nUR                  b  UR                  Ul        U$ U R                  UR                  5       5      nUR                  Ul        U$ )a5  Returns the conversion workspace info.

Args:
  conversion_workspace_ref: str, the reference of the conversion workspace.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Raises:
  BadArgumentException: Unable to fetch latest commit for the specified
  conversion workspace.
r   )r+   ConversionWorkspaceInfoRelativeNamerI   commitIdr   r   )r5   rP   r;   conversion_workspace_objrU   s        r   _GetConversionWorkspaceInfo/MigrationJobsClient._GetConversionWorkspaceInfo   s      $}}DD%224  E   ~~!*...' $#	 "99
"
/
/
1 +?*M*M'##r   c                 z   UR                   c  [        R                  " SS5      eUR                  b  UR                  Ul        U$ [
        R                  " U R                  S9nUR                  R                  UR                   S9nUR                  c  [        R                  " SS5      eUR                  Ul        U$ )a  Returns the conversion workspace info with the supplied or the latest commit id.

Args:
  conversion_workspace: the internal migration job conversion workspace
    message.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Raises:
  BadArgumentException: Unable to fetch latest commit for the specified
  conversion workspace.
  InvalidArgumentException: Invalid conversion workspace message on the
  migration job.
r   zTThe supplied migration job does not have a valid conversion workspace attached to itr   r   r   )rT   r
   rC   rI   r   r   r   r4   r   r   r   rO   )r5   rU   r;   r   cst_conversion_workspaces        r   "_ComplementConversionWorkspaceInfo6MigrationJobsClient._ComplementConversionWorkspaceInfo   s       (//
 *  ~~!&*nn#!!%@@((I  )~~22!&&  3    ..6++
 I  %=$K$K!r   c                     U R                   R                  nU" UR                  R                  UR                  5      S9$ )zReturns the performance config with dump parallel level.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.
)dumpParallelLevel)r+   PerformanceConfig DumpParallelLevelValueValuesEnumrZ   dump_parallel_level)r5   r;   performance_config_objs      r   _GetPerformanceConfig)MigrationJobsClient._GetPerformanceConfig  s>     "]]<<!0QQ``$$
 r   c                    / n/ nU(       a  U H  nUc  [        S5      eUS   U;  a  [        SR                  US   S95      e [        R                  " U R                  R
                  U5      nUR                  US   5        UR                  U5        M     U H2  nXT;   a  M
  UR                  U R                  R                  US95        M4     U$ ! [         a  n[        U5      eSnAff = f)ai  Returns the sqlserver database backups list.

Args:
  sqlserver_databases: The list of databases to be migrated.
  sqlserver_encrypted_databases: JSON/YAML file for encryption settings for
    encrypted databases.

Raises:
  Error: Empty list item in JSON/YAML file.
  Error: Encrypted Database name not found in database list.
  Error: Invalid JSON/YAML file.
Nz"Empty list item in JSON/YAML file.databasez<Encrypted Database name {dbName} not found in database list.)dbName)r   )r   formatr   PyValueToMessager+   SqlServerDatabaseBackuprB   r   )r5   sqlserver_databasessqlserver_encrypted_databasesdatabase_backupsencrypted_databases_listr   database_backuprF   s           r   _GetSqlServerDatabaseBackups0MigrationJobsClient._GetSqlServerDatabaseBackups  s    !$3(:;
;J'::LvXj1v2 	$55mm33/ 	!''(<=0! 4$ (		-
--
/
/
/
B (   	a.	s   +C
C,C''C,c                    U R                   R                  5       nUR                  S5      (       a6  U R                   R                  UR                  UR
                  S9nX2l        U$ UR                  Ul        UR                  S5      (       a  UR                  Ul
        UR                  S5      (       a  UR                  Ul        UR                  S5      (       a+  U R                  UR                  UR                  5      Ul        U$ )zReturns the sqlserver homogeneous migration job config.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.
sqlserver_dag_source_ag)sourceAglinkedServersqlserver_diff_backupsqlserver_promote_when_readyr   )r+   &SqlServerHomogeneousMigrationJobConfigrN   SqlServerDagConfigr   sqlserver_dag_linked_server	dagConfigsqlserver_backup_file_patternbackupFilePatternr   useDiffBackupr   promoteWhenReadyr   r   r   databaseBackups)r5   r;   .sqlserver_homogeneous_migration_job_config_obj
dag_configs       r   *_GetSqlserverHomogeneousMigrationJobConfig>MigrationJobsClient._GetSqlserverHomogeneousMigrationJobConfigC  s
    	<<> 3  9::==33//77 4 j BL>& :9! 
,
, 5F 
	!	!"9	:	:&& 	7D 
	!	!"@	A	A-- 	7G 
	!	!"7	8	8--(($*L*L 	7F
 :9r   c                     U R                   R                  U R                   R                  R                  R                  S9$ )"Returns the source objects config.objectsSelectionType)r+   SourceObjectsConfig#ObjectsSelectionTypeValueValuesEnumALL_OBJECTSrr   s    r   &_GetSourceObjectsConfigForAllDatabases:MigrationJobsClient._GetSourceObjectsConfigForAllDatabasesg  s7    ==,,!]]>>bbnn -  r   c                    U R                   R                  U R                   R                  R                  R                  S9n/ nU Hr  nU R                   R	                  UU R                   R                  R
                  R                  S5      S9nUR                  U R                   R                  US95        Mt     X2l	        U$ )r   r   DATABASE)r   r   objectIdentifier)
r+   r   r   SPECIFIED_OBJECTSSourceObjectIdentifierrY   rZ   r   SourceObjectConfigobjectConfigs)r5   databases_filtersource_objects_conifgsource_object_configsr   source_object_identifiers         r   ,_GetSourceObjectsConfigForSpecifiedDatabases@MigrationJobsClient._GetSourceObjectsConfigForSpecifiedDatabasesm  s     MM==!]]>>bbtt >  $!%!E!E}}33GGVV "F " ""
--
*
*7 +  % +@'  r   c                    U R                   R                  U R                   R                  R                  R                  S9nU H  nUS   nUS   nU R                   R	                  UUU R                   R                  R
                  R                  S5      S9nUR                  c  / Ul        UR                  R                  U R                   R                  US95        M     U$ )r   r   schematableTABLE)r   r   r   r   )
r+   r   r   r   r   rY   rZ   r   r   r   )r5   object_filterssource_objects_configobject_filterschema_name
table_namer   s          r   )_GetSourceObjectsConfigForSpecifiedTables=MigrationJobsClient._GetSourceObjectsConfigForSpecifiedTables  s     MM==!]]>>bbtt >  (!(+k )j!%!E!E}}33GGVV "F " 
	,	,	4.0+))00
--
*
*7 +  (" ! r   c                 |   U R                   R                  5       nUR                  S5      (       a  U R                  5       nOcUR                  S5      (       a  U R	                  UR
                  5      nO1UR                  S5      (       a  U R                  UR                  5      nU R                   R                  US9$ )zReturns the migration job objects config.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.
all_databasesr   r   )sourceObjectsConfig)	r+   r   rN   r   r   r   r   r   MigrationJobObjectsConfig)r5   r;   r   s      r   _GetMigrationJobObjectsConfig1MigrationJobsClient._GetMigrationJobObjectsConfig  s     !MM==?00"IIK		!	!"4	5	5"OO


 
	!	!/	2	2"LL


 ==221 3  r   c                 D   UR                  S5      =(       d    UR                  S5      =(       dq    UR                  S5      =(       dY    UR                  S5      =(       dA    UR                  S5      =(       d)    UR                  S5      =(       d    UR                  S5      $ )zChecks if at least one heterogeneous config flag is specified.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  True if at least one of the heterogeneous config's flags is known and
  specified.
$max_concurrent_full_dump_connectionsmax_concurrent_cdc_connectionsskip_full_dumporacle_cdc_start_positionsqlserver_cdc_start_position&max_concurrent_destination_connectionstransaction_timeout)rN   r:   s     r   '_IsHeterogeneousConfigKnownAndSpecified;MigrationJobsClient._IsHeterogeneousConfigKnownAndSpecified  s     	  !GH 	;##$DE	;##$45	; ##$?@	; ##$BC		;
 ##$LM	; ##$9:r   c                     U R                   R                  5       nUR                  S5      (       a  UR                  Ul        UR                  S5      (       a  [        UR                  5      S-   Ul        U$ )zReturns the postgres destination config.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  PostgresDestinationConfig: The postgres destination config.
r   r   s)r+   PostgresDestinationConfigrN   r   maxConcurrentConnectionsstrr   transactionTimeout)r5   r;   postgres_destination_configs      r   _GetPostgresDestinationConfig1MigrationJobsClient._GetPostgresDestinationConfig  sq     #'--"I"I"K HII

5
5 ":  566
d&&
'#
- "4 '&r   c                     U R                   R                  5       nUR                  S5      (       a  UR                  Ul        U$ )zReturns the postgres source config.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  The postgres source config.
r   )r+   PostgresSourceConfigrN   r   skipFullDump)r5   r;   postgres_source_configs      r   _GetPostgresSourceConfig,MigrationJobsClient._GetPostgresSourceConfig  s>     "]]??A 011,0,?,?)!!r   c                    U R                   R                  5       nUR                  S5      (       a  UR                  Ul        UR                  S5      (       a  UR
                  Ul        UR                  S5      (       a[  UR                  Ul        UR                  S5      (       a  [        UR                  5      nX2l        U$ [        R                  " SS5      eU$ )a  Returns the oracle source config.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  The oracle source config.

Raises:
  RequiredArgumentException: The Oracle CDC start position should be
  specified when skipping full dump.
r   r   r   r   zoracle-cdc-start-positionzJThe Oracle CDC start position should be specified when skipping full dump.)r+   OracleSourceConfigrN   r    maxConcurrentFullDumpConnectionsr   maxConcurrentCdcConnectionsr   r  intr   cdcStartPositionr
   RequiredArgumentException)r5   r;   oracle_source_configtemps       r   _GetOracleSourceConfig*MigrationJobsClient._GetOracleSourceConfig  s      ==;;= FGG

3
3 ;  @AA

-
- 6  011*.*=*='		!	!"=	>	>411204-   22''
 	
  r   c                    U R                   R                  5       nUR                  S5      (       a  UR                  Ul        UR                  S5      (       a  UR
                  Ul        UR                  S5      (       aQ  UR                  Ul        UR                  S5      (       a  UR                  Ul
        U$ [        R                  " SS5      eU$ )a  Returns the sqlserver source config.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  The sqlserver source config.

Raises:
  RequiredArgumentException: The SQL Server CDC start position should be
  specified when skipping full dump.
r   r   r   r   zsqlserver-cdc-start-positionzNThe SQL Server CDC start position should be specified when skipping full dump.)r+   SqlServerSourceConfigrN   r   r  r   r  r   r  r   sqlserverCdcStartPositionr
   r  )r5   r;   sqlserver_source_configs      r   _GetSqlServerSourceConfig-MigrationJobsClient._GetSqlServerSourceConfig  s     #mmAAC FGG

3
3 >  @AA

-
- 9  011-1-@-@*		!	!"@	A	A-- 	 9 #" 22*'
 	
 #"r   c                     U R                   R                  5       nUR                  S5      (       a  UR                  Ul        UR                  S5      (       a  [        UR                  5      S-   Ul        U$ )zReturns the sqlserver destination config.

Args:
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  SqlServerDestinationConfig: The sqlserver destination config.
r   r   r   )r+   SqlServerDestinationConfigrN   r   r   r  r   r  )r5   r;   sqlserver_destination_configs      r   _GetSqlServerDestinationConfig2MigrationJobsClient._GetSqlServerDestinationConfig8  sq     $(==#K#K#M  HII

5
5 #;  566
d&&
'#
- #5 ('r   c                 h   U R                  U5      (       Ga  U R                  U5      nUR                  R                  U R                  R
                  R                  R                  :X  a  U R                  U5      nO,[        SR                  UR                  R                  S95      eUR                  R                  U R                  R
                  R                  R                  :X  a-  U R                  R                  U R                  U5      US9nSU4$ UR                  R                  U R                  R
                  R                  R                  :X  a-  U R                  R!                  U R#                  U5      US9nSU4$ [        SR                  UR                  R                  S95      eg)	a\  Returns the heterogeneous migration job config.

Args:
  conversion_workspace_name: str, the name of the conversion workspace.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  A tuple containing the heterogeneous config key and the config object.

Raises:
  Error: Invalid source or destination engine.
zXCannot create heterogeneous migration job configuration for destination engine: {engine}engine)oracleSourceConfigpostgresDestinationConfigoracleToPostgresConfig)sqlserverSourceConfigr&  sqlserverToPostgresConfigzTCannot create heterogeneous migration job configuration for  source engine: {engine}NN)r   r   r    r$  r+   DatabaseEngineInfoEngineValueValuesEnum
POSTGRESQLr  r   r   r   ORACLEOracleToPostgresConfigr  	SQLSERVERSqlServerToPostgresConfigr  )r5   r   r;   rU   r  oracle_to_postgres_configsqlserver_to_postgres_configs          r   #_GetHeterogeneousMigrationJobConfig7MigrationJobsClient._GetHeterogeneousMigrationJobConfigM  s     33D99!99
# 
*
*
1
1]]--CCNNO '+&H&H'
# ++16+77>> ,2 ,
 	
 
%
%
,
,]]--CCJJK %)MM$H$H#::4@&A %I %! ()BBB

%
%
,
,]]--CCMMN (,}}'N'N"&"@"@"F&A (O ($ +,HHH''-v+2299 (. (
 	
 r   c                    U R                  U5      (       Gav  U R                  U5      nUR                  c  [        SR	                  US95      eU R                  UR                  R                  5      nUR                  R                  U R                  R                  R                  R                  :X  a  U R                  U5      nO,[        SR	                  UR                  R                  S95      eUR                  R                  U R                  R                  R                  R                  :X  a-  U R                  R!                  UU R#                  U5      S9nSU4$ [        SR	                  UR                  R                  S95      eg)	aw  Returns the heterogeneous migration job config for failback migration job.

Args:
  original_migration_name: str, the name of the original migration job.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  A tuple containing the heterogeneous config key and the config object.

Raises:
  Error: Invalid source or destination engine.
zCannot create failback heterogeneous migration job configuration for original migration job: {original_migration_name} does not have conversion workspace.)original_migration_namezaCannot create failback heterogeneous migration job configuration for destination engine: {engine}r#  )postgresSourceConfigsqlserverDestinationConfigpostgresToSqlserverConfigz]Cannot create failback heterogeneous migration job configuration for  source engine: {engine}r*  )r   _GetExistingMigrationJobconversionWorkspacer   r   r   rT   r    r$  r+   r+  r,  r-  r
  r   r0  PostgresToSqlServerConfigr   )r5   r7  r;   original_migration_jobrU   r	  postgres_to_sqlserver_configs          r   +_GetHeterogeneousFailbackMigrationJobConfig?MigrationJobsClient._GetHeterogeneousFailbackMigrationJobConfig  s     33D99#<<
!  
 	3	3	;**0&(? +1 +
 	
 "99
 
4
4
9
9 
*
*
1
1]]--CCNNO "&!>!>t!D006+77>> 17 1
 	
 
%
%
,
,]]--CCMMN (,}}'N'N!7'+'J'J( (O (
$ +,HHH,,2F+2299 -3 -
 	
 r   c                 ^   U R                   R                  n[        R                  " X`R                   R                  R                  5      nU R                  XvR                  5      n	UR                  5       n
UR                  5       n0 nUR                  S5      (       a  U R                  U5      US'   OTUR                  S5      (       a  U R                  U5      US'   O)UR                  S5      (       a  U R                  5       US'   UR                  S5      (       a  U R                  UR                  5      US'   Ub>  U R                  X65      US	'   U R                  UR                  5       U5      u  pUb  XU'   OaUb=  UR                  5       US
'   U R!                  UR                  5       U5      u  pUb  XU'   O!U R#                  U5      (       a  [%        S5      eU" SUUR&                  UR(                  R*                  U	UR,                  U
US.UD6nUb  UR                  5       Ul        UR1                  S5      (       a=  [2        R4                  " 5       R7                  UR8                  5      u  Ul        nUUl        UR1                  S5      (       a  U R;                  U5      Ul        UR1                  S5      (       a5  U R?                  U R                   R                  UR@                  5      Ul!        UR1                  S5      (       d  UR1                  S5      (       a  U RE                  U5      Ul#        [I        USS5      (       a   U R                   RK                  SS9nUUl&        UR1                  S5      (       d  UR1                  S5      (       a  U RO                  U5      Ul(        U$ )aR  Returns a migration job.

Args:
  source_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource.
  destination_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource.
  conversion_workspace_ref: a Resource reference to a
    datamigration.projects.locations.conversionWorkspaces resource.
  original_migration_name_ref: a Resource reference to a
    datamigration.projects.locations.migrationJobs resource.
  cmek_key_ref: a Resource reference to a
    cloudkms.projects.locations.keyRings.cryptoKeys resource.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  MigrationJob: the migration job.

Raises:
  Error: If neither conversion workspace nor original migration job name is
  specified for heterogeneous migration job.
rg   vpcPeeringConnectivityr"   reverseSshConnectivity	static_ipstaticIpConnectivityr!   	dumpFlagsr<  originalMigrationNamez`Conversion workspace or original migration job name is required for heterogeneous migration job.)ry   displayNamestater   dumpPathr   r    rL   r   ra   r   r   use_postgres_nativeFT)isNativeLogicalr   r   r   ))r+   r|   r   ParseCreateArgsr}   r]   r   r   IsSpecifiedrh   rn   rs   _GetDumpFlagsr!   r   r4  r@  r   r   r   StateValueValuesEnumCREATINGr   cmekKeyNamerN   r   RewriterRewriterL   r   performanceConfigrc   ra   dumpTyper   &sqlserverHomogeneousMigrationJobConfiggetattrPostgresHomogeneousConfigpostgresHomogeneousConfigr   objectsConfig)r5   
source_refdestination_refrP   original_migration_name_refcmek_key_refr;   migration_job_typery   r\   r   r    paramsheterogeneous_config_keyheterogeneous_config_objmigration_job_objserver_filterpostgres_homogeneous_configs                     r   _GetMigrationJob$MigrationJobsClient._GetMigrationJob  s   @ 33((mm((44F 199=J$$&F!..0KF
##)-)H)H)Nf%&			'	"	")-)H)H)Nf%&			+	&	&'+'D'D'Ff#$%% ..t?f[+&*&F&F
"'f"# 
2
2&335t 9
 
"	-+C'(	$	0
%
2
2
4 $% 
:
:)668$ 9
 
"	-+C'(		5	5d	;	;8
 	

 + 	%% 55>>	 	 &2&?&?&A#))#1#:#:#<#D#D
++$ dk= "/ 566,0,F,Ft,L),,#'#4#4
--
$
$dnn$   		!	!";	<	<

9
9$
? > t*E22$(MM$K$K %L %! 5P1 233t7O7O8 8 )-(J(J4(P%r   c                 8   SR                  X4R                  5       5      nSR                  XS5      nSR                  XT5      nUR                  S5      (       a   UR                  SR                  U5      5        UR                  S5      (       a   UR                  SR                  U5      5        UR                  S5      (       a   UR                  S	R                  U5      5        UR                  S
5      (       a!  UR                  SR                  U5      5        gg)z<Update the heterogeneous migration job config update fields.z{}To{}Configz{}.{}SourceConfigz{}.{}DestinationConfigr   z#{}.maxConcurrentFullDumpConnectionsr   z{}.maxConcurrentCdcConnectionsr   z&{}.maxConcurrentDestinationConnectionsr   z{}.transactionTimeoutN)r   titlerN   r   )r5   r;   r   source_enginedestination_engine
config_keysource_config_keydestination_config_keys           r   2_UpdateHeterogeneousMigrationJobConfigUpdateFieldsFMigrationJobsClient._UpdateHeterogeneousMigrationJobConfigUpdateFieldsG  s     &&//1J ,22:M5<<  FGG
/
6
67H
I  @AA
*
1
12C
D  HII
2
9
9$
  566
!
(
()?
@ 7r   c                    U R                  UR                  R                  U5      u  pEUS:X  a  XRl        U R	                  UUSS5        gUS:X  a  XRl        U R	                  UUSS5        g[        SR                  UR                  R                  R                  UR                  R                  R                  S95      e)	zDUpdate the heterogeneous migration job config for the migration job.r'  oraclepostgresr)  	sqlserverzCannot update heterogeneous migration job configuration for source engine: {source_engine} and destination engine: {destination_engine})rl  rm  N)r4  r<  rT   r'  rq  r)  r   r   r   r$  r    r5   r;   r   r   rc  rd  s         r   &_UpdateHeterogeneousMigrationJobConfig:MigrationJobsClient._UpdateHeterogeneousMigrationJobConfige  s    
 	00--22D	
 7
  #;;-E*
==



	 
"%@	@0H-
==



	 !!')==DDKK!.!B!B!N!N!U!U "( " r   c                     U R                  UR                  U5      u  pEUS:X  a  XRl        U R                  UUSS5        g[	        SR                  US95      e)zMUpdate the heterogeneous migration job config for the failback migration job.r:  ru  rv  zVUnknown heterogeneous failback migration job configuration: {heterogeneous_config_key})rc  N)r@  rH  r:  rq  r   r   rw  s         r   ._UpdateHeterogeneousFailbackMigrationJobConfigBMigrationJobsClient._UpdateHeterogeneousFailbackMigrationJobConfig  sv    
 	88//	
 7
  #>>0H-
==



	 ((.'? )/ ) r   c                    UR                  S5      (       a$  U R                  5       Ul        SUl        SUl        gUR                  S5      (       a%  U R                  U5      Ul        SUl        SUl        gU R                   H?  nUR                  U5      (       d  M  U R                  U5      Ul        SUl        SUl          g   g)z1Update connectivity method for the migration job.rE  Nrg   )rO  rs   rF  rC  rD  rh   _REVERSE_MAPrn   )r5   r   r;   fields       r   _UpdateConnectivity'MigrationJobsClient._UpdateConnectivity  s    $$+/+H+H+Jm(-1m*-1m*
##-1-L-L
.m* .2m*+/m(""			%	 	 /3/N/N0
, 04,-1* #r   c                    UR                   c  [        S5      eUR                   nUR                  S5      (       a  UR                  Ul        UR                  S5      (       a  UR
                  Ul        UR                  S5      (       a  UR                  Ul        UR                  S5      (       d  UR                  S5      (       a  UR                  c  U R                  R                  5       Ul	        UR                  S5      (       a  UR                  UR                  l        UR                  S5      (       a  UR                  UR                  l        UR                  S5      (       a,  U R!                  UR"                  UR$                  5      Ul        gUR                  S	5      (       a  [(        R*                  " S
S5      eg)zLUpdate the sqlserver homogeneous migration job config for the migration job.NzrCannot update sqlserver homogeneous migration job config when it was not set during creation of the migration job.r   r   r   r   r   r   r   z--sqlserver-encrypted-databasesz^--sqlserver-encrypted-databases can only be specified when --sqlserver-databases is specified.)rX  r   rN   r   r   r   r   r   r   r   r+   r   r   r   r   r   r   r   r   r   r
   rC   )r5   r;   r   r   s       r   -_UpdateSqlserverHomogeneousMigrationJobConfigAMigrationJobsClient._UpdateSqlserverHomogeneousMigrationJobConfig  s    ;;C;  	<< 3  ?@@

,
, 5F  788

$
$ 5B  >??

+
+ 5E ! 		!	!"?	@	@	7	A	A	IMM,,. 	7@ 
	!	!";	<	<(( 	7@@I 
	!	!"?	@	@ ,, ;DDQ 566

+
+&&(J(J 5D
 
	!	!"A	B	B//
+1  
Cr   c                     UR                  S5      (       d  UR                  S5      (       a  U R                  U5      Ul        gg)z>Update the migration job objects config for the migration job.r   r   N)rN   r   r\  )r5   r;   r   s      r    _UpdateMigrationJobObjectsConfig4MigrationJobsClient._UpdateMigrationJobObjectsConfig  sE      233t7O7O8 8 %)$F$Ft$Lm!8r   c           
         [        U R                  5       Vs/ s H1  nUR                  U5      (       d  M  [        R                  " U5      PM3     nnUR                  [        U R                  5       Vs/ s H@  nUR                  U5      (       d  M  SR                  [        R                  " U5      5      PMB     sn5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S	5      (       d  UR                  S5      (       a  UR                  S
5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       d  UR                  S5      (       a  UR                  S5        UR                  S5      (       d  UR                  S5      (       a  UR                  S5        U$ s  snf s  snf )z)Returns update mask for specified fields.zreverseSshConnectivity.{0}rg   zvpcPeeringConnectivity.vpcr   z#performanceConfig.dumpParallelLevelra   rW  rL   rI   zconversionWorkspace.commitIdr   z8sqlserverHomogeneousMigrationJobConfig.backupFilePatternr   z4sqlserverHomogeneousMigrationJobConfig.useDiffBackupr   z7sqlserverHomogeneousMigrationJobConfig.promoteWhenReadyr   z9sqlserverHomogeneousMigrationJobConfig.dagConfig.sourceAgr   z=sqlserverHomogeneousMigrationJobConfig.dagConfig.linkedServerr   r   z6sqlserverHomogeneousMigrationJobConfig.databaseBackupsr   r   z!objectsConfig.sourceObjectsConfig)
sorted_FIELDS_MAPrO  r   ConvertToCamelCaseextendr~  r   r   rN   )r5   r;   r  r   s       r   _GetUpdateMask"MigrationJobsClient._GetUpdateMask  s    D,,--EE" 	4,,U3-  
  D--.	 /EE"		
$++007	
 /	  
##78 566@A,,:&))8$,,0H0H1 1 9: ?@@
D  788
@  >??
C  9::
E  =>>
I  		!	!"A	B	B
B  233t7O7O8 8 >?o
s   KK4K)Kc                     / nUR                  5        H.  u  p4UR                  U R                  R                  UUS95        M0     U R                  R	                  US9$ )z-Returns the dump flags for the migration job.)rT   value)rG  )itemsr   r+   DumpFlag	DumpFlags)r5   r!   dump_flags_listrT   r  s        r   rP  !MigrationJobsClient._GetDumpFlags2  sa    O!'')
--
 
  !  * ==""_"==r   c                 X   U R                  U5      nUR                  S5      (       a  UR                  Ul        UR                  S5      (       a5  U R	                  U R
                  R                  UR                  5      Ul        UR                  S5      (       a5  U R                  U R
                  R                  UR                  5      Ul        UR                  S5      (       a  UR                  Ul        UR                  S5      (       a   U R                  UR                  5      Ul        UR                  S5      (       a  UR#                  5       Ul        UR                  S5      (       a  UR#                  5       Ul        UR                  S5      (       a  U R)                  U5      Ul        UR                  S	5      (       a<  [,        R.                  " 5       R1                  UR2                  5      u  Ul        nXal        U R5                  X5        U R7                  XAU5        UR                  S
5      (       d  UR                  S5      (       dn  UR                  S5      (       dX  UR                  S5      (       dB  UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  U R9                  XA5        U R;                  XA5        U R=                  U5      (       a4  UR>                  c  U RA                  XAU5        X4$ U RC                  XAU5        X4$ )z9Returns updated migration job and list of updated fields.r   r   ra   r   r!   r   r    r   rL   r   r   r   r   r   r   r   )"r  rO  r   rI  r]   r+   r|   r   rN   rc   ra   rW  r   rK  rP  r!   rG  r   r   r    r   rV  r   rT  rU  rL   r  r   r  r  r   rH  rx  r{  )r5   r   r]  r^  r;   r   rf  s          r   _GetUpdatedMigrationJob+MigrationJobsClient._GetUpdatedMigrationJob>  s    ''-M''"&"3"3m==)C)CTYYOm,,#00
--
$
$dnn m $$#~~m%% $ 2 24?? Cm!!'446m&&"1">">"@m 566(,(B(B4(Hm%))#1#:#:#<#D#D
++$ dk= +]1tM:  !@AA##$;<<##$BCC##$9::##$CDD##$=>>##$ABB
88M))$>33D99		,	,	433	
 ''	 	;;	
 ''r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )Nr   )r+   5DatamigrationProjectsLocationsMigrationJobsGetRequestr-   Get)r5   rT   get_reqs      r   r;  ,MigrationJobsClient._GetExistingMigrationJobu  s9    KK 	L 	
 
 ==W%%r   Nc	                    U R                  U5        U R                  XX5        U R                  UUUUUU5      n	[        R                  " 5       n
U R
                  R                  nU" U	UUU
S9nU R                  R                  U5      $ )a  Creates a migration job.

Args:
  parent_ref: a Resource reference to a parent
    datamigration.projects.locations resource for this migration job.
  migration_job_id: str, the name of the resource to create.
  source_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource.
  destination_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource.
  conversion_workspace_ref: a Resource reference to a
    datamigration.projects.locations.conversionWorkspaces resource.
  original_migration_name_ref: a Resource reference to a
    datamigration.projects.locations.migrationJobs resource.
  cmek_key_ref: a Resource reference to a
    cloudkms.projects.locations.keyRings.cryptoKeys resource.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for creating the migration job.
)migrationJobmigrationJobIdparent	requestId)	r<   rQ   rh  r   GenerateRequestIdr+   8DatamigrationProjectsLocationsMigrationJobsCreateRequestr-   Create)r5   
parent_refmigration_job_idr]  r^  rP   r_  r`  r;   r   
request_idcreate_req_type
create_reqs                r   r  MigrationJobsClient.Create}  s    B 	t))*BI)) #M ++-JNN  !"'	J ==
++r   c                    U R                  U5        U R                  U5      n[        US5      (       aJ  UR                  b=  U R	                  UR                  U5        U R                  UR                  U5      Ul        U R                  XRX45      u  pg[        R                  " 5       nU R                  R                  n	U	" UUUSR                  U5      S9n
U R                  R                  U
5      $ )a  Updates a migration job.

Args:
  name: str, the reference of the migration job to update.
  source_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource.
  destination_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for updating the migration job.678888888
r<  ,)r  rT   r  
updateMask)r<   r;  hasattrr<  rV   r   r  r   r  r+   7DatamigrationProjectsLocationsMigrationJobsPatchRequestjoinr-   Patch)r5   rT   r]  r^  r;   
current_mjr   r   r  update_req_type
update_reqs              r   UpdateMigrationJobsClient.Update  s     	t..t4J 	
122**6
22

(
($ (,'N'N

(
($(j$ $(#?#?$ M ++-JMM  !"88M*	J ==z**r   c                     U R                   R                  5       nUR                  S5      (       a  U R                  U5      Ul        U R                   R                  UUS9nU R                  R                  U5      $ )zPromotes a migration job.

Args:
  name: str, the name of the resource to promote.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for promoting the migration job.
r   )rT   promoteMigrationJobRequest)r+   PromoteMigrationJobRequestrN   r   objectsFilter9DatamigrationProjectsLocationsMigrationJobsPromoteRequestr-   Promote)r5   rT   r;   promote_mj_reqpromote_reqs        r   r  MigrationJobsClient.Promote  sw     ]]==?N 233%)%G%G%Mn" 	OO'5 	P 	
  ==  --r   c                    U R                   R                  5       nUR                  S5      (       d  UR                  S5      (       a  U R                  U5      Ul        UR                  S5      (       a  SUl        UR                  S5      (       a  SUl        U R                   R                  UUS9nU R                  R                  U5      $ )zRestarts a migration job.

Args:
  name: str, the name of the resource to restart.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for promoting the migration job.
r   r   skip_validationTrestart_failed_objects)rT   restartMigrationJobRequest)
r+   RestartMigrationJobRequestrN   r   r  skipValidationrestartFailedObjects9DatamigrationProjectsLocationsMigrationJobsRestartRequestr-   Restart)r5   rT   r;   restart_mj_reqrestart_reqs        r   r  MigrationJobsClient.Restart  s     ]]==?N 233t7O7O8 8 &*%G%G%Mn" 122&*n# 899,0n) 	OO'5 	P 	
  ==  --r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )zFetches source objects of a migration job.

Args:
  name: str, the name of the resource to fetch source objects for.

Returns:
  Operation: the operation for fetching source objects of the migration job.
r   )r+   DDatamigrationProjectsLocationsMigrationJobsFetchSourceObjectsRequestr-   FetchSourceObjects)r5   rT   fetch_source_objects_reqs      r   r  &MigrationJobsClient.FetchSourceObjects&  s:      $}}qq  r   ==++,DEEr   c           	          U R                   R                  nU" UR                  5       S9n[        R                  " U R
                  USSSSS9$ )zGet the list of objects in a migration job.

Args:
  migration_job_ref: The migration job for which to list objects.

Returns:
  An iterator over all the matching migration job objects.
)r  NmigrationJobObjects)servicerequestlimit
batch_sizer  batch_size_attribute)r+   =DatamigrationProjectsLocationsMigrationJobsObjectsListRequestr   r   YieldFromListr1   )r5   migration_job_reflist_req_typelist_reqs       r   ListObjectsMigrationJobsClient.ListObjects8  sW     	SS  $5$B$B$DEH##%%#! r   )r-   r1   r)   r+   r4   r3   )NNNNr'   )6r   r   r   r   r   r  r~  r6   r<   r9   rQ   rV   r]   rc   rh   rn   rs   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r   r4  r@  rh  rq  rx  r{  r  r  r  r  rP  r  r;  r  r  r  r  r  r  r   r   r   r   r   r   $   s'   5+ 3,'!O
<
>BMC
0% 4$4* X+Z":H!*!00*'*"$ L%#N(*;z=~||<!F223jM9v
>5(n&  $"&8,t/+h .>  .DF$r   r   )r   apitools.base.pyr   r   )googlecloudsdk.api_lib.database_migrationr   r   r   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper	   r
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corecore_exceptionsgooglecloudsdk.core.resourcer   rD   r   objectr   r   r   r   <module>r     sP    5 & ' > K D 7 ( . < = : 
7O!! 7i& ir   