
                             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Jr  SSKr " S S\R0                  5      r " S S\5      rg)z.Database Migration Service migration jobs API.    )absolute_import)division)unicode_literals)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)selfr7   s     r   __init__MigrationJobsClient.__init__5   s    ,,];DK..}=DMKK@@DM)),,,
++
>
>  #d#55mDD&r   c                 &    U R                  U5        g r*   )_ValidateDumpPathr8   argss     r   _ValidateArgs!MigrationJobsClient._ValidateArgsB   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)r8   r>   es      r   r<   %MigrationJobsClient._ValidateDumpPathE   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)r8   conversion_workspace_refr>   s      r    _ValidateConversionWorkspaceArgs4MigrationJobsClient._ValidateConversionWorkspaceArgsO   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
NrL   rM   rN   rO   rP   )namerQ   r   rR   )r8   conversion_workspacer>   s      r   '_ValidateConversionWorkspaceMessageArgs;MigrationJobsClient._ValidateConversionWorkspaceMessageArgsm   su       (		!	!+	.	.--J
 	
 
	!	!(	+	+--0
 	
 
, )r   c                 8    UR                   R                  U5      $ r*   )TypeValueValuesEnumlookup_by_name)r8   mj_type
type_values      r   _GetTypeMigrationJobsClient._GetType   s    &&55jAAr   c                 8    UR                   R                  U5      $ r*   )DumpTypeValueValuesEnumr]   )r8   	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r8   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_updater|   append)r8   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.
r7   rW   conversion-workspacerUnable to fetch latest commit for the specified conversion workspace. Conversion Workspace might not be committed.)r	   ConversionWorkspacesClientr7   crudReadlatestCommitIdr   rR   )r8   conversion_workspace_name	cw_clientrX   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RelativeNamerL   commitIdr   r   )r8   rS   r>   conversion_workspace_objrX   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   )rW   r   rF   rL   r   r	   r   r7   r   r   r   rR   )r8   rX   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 DumpParallelLevelValueValuesEnumr]   dump_parallel_level)r8   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.   SqlServerDatabaseBackuprE   r   )r8   sqlserver_databasessqlserver_encrypted_databasesdatabase_backupsencrypted_databases_listr   database_backuprI   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.   &SqlServerHomogeneousMigrationJobConfigrQ   SqlServerDagConfigr   sqlserver_dag_linked_server	dagConfigsqlserver_backup_file_patternbackupFilePatternr   useDiffBackupr   promoteWhenReadyr   r   r   databaseBackups)r8   r>   .sqlserver_homogeneous_migration_job_config_obj
dag_configs       r   *_GetSqlserverHomogeneousMigrationJobConfig>MigrationJobsClient._GetSqlserverHomogeneousMigrationJobConfigF  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_OBJECTSru   s    r   &_GetSourceObjectsConfigForAllDatabases:MigrationJobsClient._GetSourceObjectsConfigForAllDatabasesj  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SourceObjectIdentifierr\   r]   r   SourceObjectConfigobjectConfigs)r8   databases_filtersource_objects_conifgsource_object_configsr   source_object_identifiers         r   ,_GetSourceObjectsConfigForSpecifiedDatabases@MigrationJobsClient._GetSourceObjectsConfigForSpecifiedDatabasesp  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   r\   r]   r   r   r   )r8   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   rQ   r   r   r   r   r   MigrationJobObjectsConfig)r8   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)rQ   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.   PostgresDestinationConfigrQ   r   maxConcurrentConnectionsstrr   transactionTimeout)r8   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.   PostgresSourceConfigrQ   r   skipFullDump)r8   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.   OracleSourceConfigrQ   r    maxConcurrentFullDumpConnectionsr   maxConcurrentCdcConnectionsr   r  intr   cdcStartPositionr   RequiredArgumentException)r8   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.   SqlServerSourceConfigrQ   r   r  r   r  r   r  r   sqlserverCdcStartPositionr   r  )r8   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.   SqlServerDestinationConfigrQ   r   r  r  r   r  )r8   r>   sqlserver_destination_configs      r   _GetSqlServerDestinationConfig2MigrationJobsClient._GetSqlServerDestinationConfig;  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  )r8   r   r>   rX   r  oracle_to_postgres_configsqlserver_to_postgres_configs          r   #_GetHeterogeneousMigrationJobConfig7MigrationJobsClient._GetHeterogeneousMigrationJobConfigP  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   rW   r#   r'  r.   r.  r/  r0  r  r"   r3  PostgresToSqlServerConfigr#  )r8   r:  r>   original_migration_jobrX   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#        UR1                  S5      (       d  UR1                  S5      (       a  U RI                  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.
rj   vpcPeeringConnectivityr%   reverseSshConnectivity	static_ipstaticIpConnectivityr$   	dumpFlagsr?  originalMigrationNamez`Conversion workspace or original migration job name is required for heterogeneous migration job.)r|   displayNamestater    dumpPathr"   r#   rO   r   rd   r   r   r   r   r   )&r.   r   r   ParseCreateArgsr   r`   r    r   IsSpecifiedrk   rq   rv   _GetDumpFlagsr$   r   r7  rC  r   r   r   StateValueValuesEnumCREATINGr!   cmekKeyNamerQ   r
   RewriterRewriterO   r   performanceConfigrf   rd   dumpTyper   &sqlserverHomogeneousMigrationJobConfigr   objectsConfig)r8   
source_refdestination_refrS   original_migration_name_refcmek_key_refr>   migration_job_typer|   r_   r"   r#   paramsheterogeneous_config_keyheterogeneous_config_objmigration_job_objserver_filters                    r   _GetMigrationJob$MigrationJobsClient._GetMigrationJob  sa   @ 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$
? >  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   titlerQ   r   )r8   r>   r   source_enginedestination_engine
config_keysource_config_keydestination_config_keys           r   2_UpdateHeterogeneousMigrationJobConfigUpdateFieldsFMigrationJobsClient._UpdateHeterogeneousMigrationJobConfigUpdateFieldsD  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})ri  rj  N)r7  r?  rW   r*  rn  r,  r   r   r"   r'  r#   r8   r>   r   r   ra  rb  s         r   &_UpdateHeterogeneousMigrationJobConfig:MigrationJobsClient._UpdateHeterogeneousMigrationJobConfigb  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=  rr  rs  zVUnknown heterogeneous failback migration job configuration: {heterogeneous_config_key})ra  N)rC  rK  r=  rn  r   r   rt  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.rH  Nrj   )rP  rv   rI  rF  rG  rk   _REVERSE_MAPrq   )r8   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.)rY  r   rQ   r   r   r   r   r   r   r   r.   r   r   r   r   r   r   r   r   r   r   rF   )r8   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)rQ   r   rZ  )r8   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}rj   zvpcPeeringConnectivity.vpcr   z#performanceConfig.dumpParallelLevelrd   rX  rO   rL   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_MAPrP  r   ConvertToCamelCaseextendr{  r   r   rQ   )r8   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.)rW   value)rJ  )itemsr   r.   DumpFlag	DumpFlags)r8   r$   dump_flags_listrW   r  s        r   rQ  !MigrationJobsClient._GetDumpFlags/  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    rd   r!   r$   r"   r#   r   rO   r   r   r   r   r   r   r   )"r  rP  r   rL  r`   r.   r   r    rQ   rf   rd   rX  r!   rN  rQ  r$   rJ  r   r"   r#   r   rW  r
   rU  rV  rO   r}  r   r  r  r   rK  ru  rx  )r8   r   r[  r\  r>   r   rd  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.   5DatamigrationProjectsLocationsMigrationJobsGetRequestr0   Get)r8   rW   get_reqs      r   r>  ,MigrationJobsClient._GetExistingMigrationJobr  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?   rT   re  r   GenerateRequestIdr.   8DatamigrationProjectsLocationsMigrationJobsCreateRequestr0   Create)r8   
parent_refmigration_job_idr[  r\  rS   r]  r^  r>   r   
request_idcreate_req_type
create_reqs                r   r  MigrationJobsClient.Createz  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  rW   r  
updateMask)r?   r>  hasattrr?  rY   r   r  r   r  r.   7DatamigrationProjectsLocationsMigrationJobsPatchRequestjoinr0   Patch)r8   rW   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   )rW   promoteMigrationJobRequest)r.   PromoteMigrationJobRequestrQ   r   objectsFilter9DatamigrationProjectsLocationsMigrationJobsPromoteRequestr0   Promote)r8   rW   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)rW   restartMigrationJobRequest)
r.   RestartMigrationJobRequestrQ   r   r  skipValidationrestartFailedObjects9DatamigrationProjectsLocationsMigrationJobsRestartRequestr0   Restart)r8   rW   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.   DDatamigrationProjectsLocationsMigrationJobsFetchSourceObjectsRequestr0   FetchSourceObjects)r8   rW   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   YieldFromListr4   )r8   migration_job_reflist_req_typelist_reqs       r   ListObjectsMigrationJobsClient.ListObjects5  sW     	SS  $5$B$B$DEH##%%#! r   )r0   r4   r,   r.   r7   r6   )NNNNr*   )6r   r   r   r   r   r  r{  r9   r?   r<   rT   rY   r`   rf   rk   rq   rv   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r#  r7  rC  re  rn  ru  rx  r}  r  r  r  rQ  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=~vp<!F223jM9v
>5(n&  $"&8,t/+h .>  .DF$r   r   )r   
__future__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   rG   r   objectr   r   r   r   <module>r     sW    5 &  ' % ' > K D 7 ( . < = : 
7O!! 7c& cr   