
    7                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZ G d dej0                        Z G d de      Zy)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                       e Zd ZdZy)Errorz.Class for errors raised by container commands.N)__name__
__module____qualname____doc__     ?lib/googlecloudsdk/api_lib/database_migration/migration_jobs.pyr   r   #   s    6r   r   c                   .   e Zd ZdZg dZg dZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)	 	 	 d/d)Z*d0d*Z+	 d0d+Z,	 d0d,Z-d- Z.d. Z/y()1MigrationJobsClientz-Client for migration jobs service in the API.)display_nametype	dump_pathsourcedestination
dump_flags)vm_ipvm_portvmvpcc                 d   t        j                  |      | _        t        j                  |      | _        | j                  j
                  | _        |t        j                  j                  k(  r| j                  j                  | _        nd | _        t        j                  |      | _        || _        y N)r   GetClientInstanceclientGetMessagesModulemessages projects_locations_migrationJobs_servicer   ReleaseTrackGA(projects_locations_migrationJobs_objects_service_objectsGetResourceParserresource_parserrelease_track)selfr3   s     r   __init__zMigrationJobsClient.__init__5   s    ,,];DK..}=DMKK@@DM)),,,
++
>
>  #d#55mDD&Dr   c                 &    | j                  |       y r&   )_ValidateDumpPathr4   argss     r   _ValidateArgsz!MigrationJobsClient._ValidateArgsB   s    4 r   c                     |j                   y 	 t        j                  j                  |j                   d       y # t        $ r.}t        j                  dt        j                  |            d }~ww xY w)NF)allow_empty_objectz	dump-path)	r   r   ObjectReferenceFromArgument	Exceptionr   InvalidArgumentExceptionsix	text_type)r4   r9   es      r   r7   z%MigrationJobsClient._ValidateDumpPathE   sg    ~~O""//
..U 0   O//S]]1=MNNOs   +; 	A2)A--A2c                     |O|j                  d      rt        j                  dd      |j                  d      rt        j                  dd      yy)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)r4   conversion_workspace_refr9   s      r    _ValidateConversionWorkspaceArgsz4MigrationJobsClient._ValidateConversionWorkspaceArgsO   si      '		!	!+	.--J
 	
 
	!	!(	+--0
 	
 
, (r   c                     |j                   O|j                  d      rt        j                  dd      |j                  d      rt        j                  dd      yy)au  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
    NrE   rF   rG   rH   rI   )namerJ   r   rK   )r4   conversion_workspacer9   s      r   '_ValidateConversionWorkspaceMessageArgsz;MigrationJobsClient._ValidateConversionWorkspaceMessageArgsm   so       (		!	!+	.--J
 	
 
	!	!(	+--0
 	
 
, )r   c                 8    |j                   j                  |      S r&   )TypeValueValuesEnumlookup_by_name)r4   mj_type
type_values      r   _GetTypezMigrationJobsClient._GetType   s    &&55jAAr   c                 8    |j                   j                  |      S r&   )DumpTypeValueValuesEnumrT   )r4   	dump_typedump_type_values      r   _GetDumpTypez MigrationJobsClient._GetDumpType   s    ,,;;OLLr   c                 N    | j                   j                  |j                        S )N)r$   )r*   VpcPeeringConnectivitypeer_vpcr8   s     r   _GetVpcPeeringConnectivityz.MigrationJobsClient._GetVpcPeeringConnectivity   s    ==//DMM/BBr   c                     | j                   j                  |j                  |j                  |j                  |j
                        S )N)r#   vmIpvmPortr$   )r*   ReverseSshConnectivityr#   r!   r"   r$   r8   s     r   _GetReverseSshConnectivityz.MigrationJobsClient._GetReverseSshConnectivity   s7    ==//77DLLdhh 0  r   c                 6    | j                   j                         S r&   )r*   StaticIpConnectivityr4   s    r   _GetStaticIpConnectivityz,MigrationJobsClient._GetStaticIpConnectivity   s    ==--//r   c                 X   t        j                  |      }t        j                  |      }| j                  j                  j
                  }t        j                  |||j                        j                  |      }|j                  r#|j                  |_
        |j                  d       yy)z$Updates labels of the migration job.)	additionssubtractionsclearlabelsN)r   GetUpdateLabelsDictFromArgsGetRemoveLabelsListFromArgsr*   MigrationJobLabelsValueDiffclear_labelsApplyneeds_updatern   append)r4   r9   migration_jobupdate_fields
add_labelsremove_labels
value_typeupdate_results           r   _UpdateLabelsz!MigrationJobsClient._UpdateLabels   s    88>J;;DAM++77J$$" eJ	 
 !!*11m8$ "r   c                     t        j                  | j                        }|j                  j	                  |      }|j
                  t        j                  dd      |S )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.
    r3   rO   conversion-workspacerUnable to fetch latest commit for the specified conversion workspace. Conversion Workspace might not be committed.)r	   ConversionWorkspacesClientr3   crudReadlatestCommitIdr   rK   )r4   conversion_workspace_name	cw_clientrP   s       r   _GetConversionWorkspacez+MigrationJobsClient._GetConversionWorkspace   sn     &@@((I %>>..& /  **2++
 I   r   c                     | j                   j                  |j                               }|j                  |j                  |_        |S | j                  |j                               }|j                  |_        |S )aU  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RelativeNamerE   commitIdr   r   )r4   rL   r9   conversion_workspace_objrP   s        r   _GetConversionWorkspaceInfoz/MigrationJobsClient._GetConversionWorkspaceInfo   s      $}}DD%224  E   ~~!*...' $#	 "99
"
/
/
1 +?*M*M'##r   c                 z   |j                   t        j                  dd      |j                  |j                  |_        |S t        j                  | j                        }|j                  j                  |j                         }|j                  t        j                  dd      |j                  |_        |S )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   )rO   r   r@   rE   r   r	   r   r3   r   r   r   rK   )r4   rP   r9   r   cst_conversion_workspaces        r   "_ComplementConversionWorkspaceInfoz6MigrationJobsClient._ComplementConversionWorkspaceInfo   s       (//
 *  ~~!&*nn#!!%@@((I  )~~22!&&  3    ..6++
 I  %=$K$K!r   c                     | j                   j                  } ||j                  j                  |j                              S )zReturns the performance config with dump parallel level.

    Args:
      args: argparse.Namespace, the arguments that this command was invoked
        with.
    )dumpParallelLevel)r*   PerformanceConfig DumpParallelLevelValueValuesEnumrT   dump_parallel_level)r4   r9   performance_config_objs      r   _GetPerformanceConfigz)MigrationJobsClient._GetPerformanceConfig  s>     "]]<<!0QQ``$$
 r   c                    g }g }|r|D ]  }|t        d      |d   |vrt        dj                  |d               	 t        j                  | j                  j
                  |      }|j                  |d          |j                  |        |D ]2  }||v r|j                  | j                  j                  |             4 |S # t        $ r}t        |      d}~ww xY w)a  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*   SqlServerDatabaseBackupr?   rw   )r4   sqlserver_databasessqlserver_encrypted_databasesdatabase_backupsencrypted_databases_listr   database_backuprC   s           r   _GetSqlServerDatabaseBackupsz0MigrationJobsClient._GetSqlServerDatabaseBackups  s    !$3(:;
;J'::LvXj1v2 	$55mm33/ 	!''(<=0! 4$ (	-	-
--
/
/
/
B (   	a.	s   *C			C"CC"c                    | j                   j                         }|j                  d      r:| j                   j                  |j                  |j
                        }||_        |S |j                  |_        |j                  d      r|j                  |_
        |j                  d      r|j                  |_        |j                  d      r+| j                  |j                  |j                        |_        |S )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*   &SqlServerHomogeneousMigrationJobConfigrJ   SqlServerDagConfigr   sqlserver_dag_linked_server	dagConfigsqlserver_backup_file_patternbackupFilePatternr   useDiffBackupr   promoteWhenReadyr   r   r   databaseBackups)r4   r9   .sqlserver_homogeneous_migration_job_config_obj
dag_configs       r   *_GetSqlserverHomogeneousMigrationJobConfigz>MigrationJobsClient._GetSqlserverHomogeneousMigrationJobConfigF  s    	<<> 3  9:==33//77 4 j BL4>& :9! 
,
, 5F 
	!	!"9	:&& 	7D 
	!	!"@	A-- 	7G 
	!	!"7	8--(($*L*L 	7F
 :9r   c                     | j                   j                  | j                   j                  j                  j                        S )"Returns the source objects config.objectsSelectionType)r*   SourceObjectsConfig#ObjectsSelectionTypeValueValuesEnumALL_OBJECTSrh   s    r   &_GetSourceObjectsConfigForAllDatabasesz:MigrationJobsClient._GetSourceObjectsConfigForAllDatabasesj  s7    ==,,!]]>>bbnn -  r   c                    | j                   j                  | j                   j                  j                  j                        }g }|D ]w  }| j                   j	                  || j                   j                  j
                  j                  d            }|j                  | j                   j                  |             y ||_	        |S )r   r   DATABASE)r   r   objectIdentifier)
r*   r   r   SPECIFIED_OBJECTSSourceObjectIdentifierrS   rT   rw   SourceObjectConfigobjectConfigs)r4   databases_filtersource_objects_conifgsource_object_configsr   source_object_identifiers         r   ,_GetSourceObjectsConfigForSpecifiedDatabasesz@MigrationJobsClient._GetSourceObjectsConfigForSpecifiedDatabasesp  s     MM==!]]>>bbtt >  $!%!E!E}}33GGVV "F " ""
--
*
*7 +  % +@'  r   c                    | j                   j                  | j                   j                  j                  j                        }|D ]  }|d   }|d   }| j                   j	                  ||| j                   j                  j
                  j                  d            }|j                  g |_        |j                  j                  | j                   j                  |              |S )r   r   schematableTABLE)r   r   r   r   )
r*   r   r   r   r   rS   rT   r   rw   r   )r4   object_filterssource_objects_configobject_filterschema_name
table_namer   s          r   )_GetSourceObjectsConfigForSpecifiedTablesz=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                 d   | j                   j                         }|j                  d      r| j                         }nY|j                  d      r| j	                  |j
                        }n,|j                  d      r| j                  |j                        }| j                   j                  |      S )zReturns the migration job objects config.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.
    all_databasesr   r   )sourceObjectsConfig)	r*   r   rJ   r   r   r   r   r   MigrationJobObjectsConfig)r4   r9   r   s      r   _GetMigrationJobObjectsConfigz1MigrationJobsClient._GetMigrationJobObjectsConfig  s     !MM==?0"IIK		!	!"4	5"OO


 
	!	!/	2"LL


 ==221 3  r   c                    |j                  d      xsp |j                  d      xs] |j                  d      xsJ |j                  d      xs7 |j                  d      xs$ |j                  d      xs |j                  d      S )a  Checks 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)rJ   r8   s     r   '_IsHeterogeneousConfigKnownAndSpecifiedz;MigrationJobsClient._IsHeterogeneousConfigKnownAndSpecified  s     	  !GH 	;##$DE	;##$45	; ##$?@	; ##$BC		;
 ##$LM	; ##$9:r   c                     | j                   j                         }|j                  d      r|j                  |_        |j                  d      rt        |j                        dz   |_        |S )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*   PostgresDestinationConfigrJ   r   maxConcurrentConnectionsstrr   transactionTimeout)r4   r9   postgres_destination_configs      r   _GetPostgresDestinationConfigz1MigrationJobsClient._GetPostgresDestinationConfig  sk     #'--"I"I"K HI

5
5 ":  56
d&&
'#
- "4 '&r   c                    | j                   j                         }|j                  d      r|j                  |_        |j                  d      r|j
                  |_        |j                  d      rV|j                  |_        |j                  d      rt        |j                        }||_        |S t        j                  dd      |S )a8  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*   OracleSourceConfigrJ   r    maxConcurrentFullDumpConnectionsr   maxConcurrentCdcConnectionsr   skipFullDumpintr   cdcStartPositionr   RequiredArgumentException)r4   r9   oracle_source_configtemps       r   _GetOracleSourceConfigz*MigrationJobsClient._GetOracleSourceConfig  s      ==;;= FG

3
3 ;  @A

-
- 6  01*.*=*='		!	!"=	>411204-   22''
 	
  r   c                 z   | j                   j                         }|j                  d      r|j                  |_        |j                  d      r|j
                  |_        |j                  d      rK|j                  |_        |j                  d      r|j                  |_
        |S t        j                  dd      |S )aB  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*   SqlServerSourceConfigrJ   r   r   r   r   r   r   r   sqlserverCdcStartPositionr   r   )r4   r9   sqlserver_source_configs      r   _GetSqlServerSourceConfigz-MigrationJobsClient._GetSqlServerSourceConfig  s     #mmAAC FG

3
3 >  @A

-
- 9  01-1-@-@*		!	!"@	A-- 	 9 #" 22*'
 	
 #"r   c                 p   | j                  |      r| j                  |      }|j                  j                  | j                  j
                  j                  j                  k(  r| j                  |      }n/t        dj                  |j                  j                              |j                  j                  | j                  j
                  j                  j                  k(  r0| j                  j                  | j                  |      |      }d|fS |j                  j                  | j                  j
                  j                  j                  k(  r0| j                  j!                  | j#                  |      |      }d|fS t        dj                  |j                  j                              y)	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   )r4   r   r9   rP   r   oracle_to_postgres_configsqlserver_to_postgres_configs          r   #_GetHeterogeneousMigrationJobConfigz7MigrationJobsClient._GetHeterogeneousMigrationJobConfig,  s     33D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                    | j                   j                  }t        j                  || j                   j                  j                        }| j                  ||j                        }|j                         }	|j                         }
i }|j                  d      r| j                  |      |d<   nJ|j                  d      r| j                  |      |d<   n$|j                  d      r| j                         |d<   |j                  d      r| j                  |j                        |d<   |@| j                  ||      |d	<   | j                  |j                         |      \  }}|-|||<   n'| j!                  |      rt#        j$                  d
d       |d||j&                  |j(                  j*                  ||j,                  |	|
d|}||j                         |_        |j1                  d      r<t3        j4                         j7                  |j8                        \  |_        }||_        |j1                  d      r| j;                  |      |_        |j1                  d      r5| j?                  | j                   j                  |j@                        |_!        |j1                  d      s|j1                  d      r| jE                  |      |_#        |j1                  d      s|j1                  d      r| jI                  |      |_%        |S )a  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.
      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:
      RequiredArgumentException: If conversion workspace is not specified for
      heterogeneous migration job.
    r_   vpcPeeringConnectivityr!   reverseSshConnectivity	static_ipstaticIpConnectivityr    	dumpFlagsconversionWorkspacer   zAConversion workspace is required for heterogeneous migration job.)rn   displayNamestater   dumpPathr   r   rH   r   rZ   r   r   r   r   r   )&r*   rq   r   ParseCreateArgsrr   rW   r   r   IsSpecifiedr`   re   ri   _GetDumpFlagsr    r   r  r   r   r   r   StateValueValuesEnumCREATINGr   cmekKeyNamerJ   r
   RewriterRewriterH   r   performanceConfigr\   rZ   dumpTyper   &sqlserverHomogeneousMigrationJobConfigr   objectsConfig)r4   
source_refdestination_refrL   cmek_key_refr9   migration_job_typern   rV   r   r   paramsheterogeneous_config_keyheterogeneous_config_objmigration_job_objserver_filters                   r   _GetMigrationJobz$MigrationJobsClient._GetMigrationJobi  s   : 33((dmm((44F 1499=J$$&F!..0KF
#)-)H)H)Nf%&			'	")-)H)H)Nf%&			+	&'+'D'D'Ff#$% ..t?f[+&*&F&F
"D'f"# 
2
2&335t 9 8
 
"	-+C'(		5	5d	;22"
 	
 + 	%% 55>>	 	 &2&?&?&A#)#1#:#:#<#D#D
++$ dk= "/ 56,0,F,Ft,L),#'#4#4
--
$
$dnn$  		!	!";	<

9
9$
? >  23t7O7O8 )-(J(J4(P%r   c                    dj                  ||j                               }dj                  ||      }dj                  ||      }|j                  d      r |j                  dj                  |             |j                  d      r |j                  dj                  |             |j                  d      r |j                  d	j                  |             |j                  d
      r!|j                  dj                  |             yy)z<Update the heterogeneous migration job config update fields.z{}To{}Configz{}.{}SourceConfigz{}.{}DestinationConfigr   z#{}.maxConcurrentFullDumpConnectionsr   z{}.maxConcurrentCdcConnectionsr   z&{}.maxConcurrentDestinationConnectionsr   z{}.transactionTimeoutN)r   titlerJ   rw   )r4   r9   ry   source_enginedestination_engine
config_keysource_config_keydestination_config_keys           r   2_UpdateHeterogeneousMigrationJobConfigUpdateFieldszFMigrationJobsClient._UpdateHeterogeneousMigrationJobConfigUpdateFields  s     &&)//1J ,22:}M5<<&  FG
/
6
67H
I  @A
*
1
12C
D  HI
2
9
9$
  56
!
(
()?
@ 7r   c                    | j                  |j                  j                  |      \  }}|dk(  r||_        | j	                  ||dd       y|dk(  r||_        | j	                  ||dd       yt        dj                  |j                  j                  j                  |j                  j                  j                              )	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})r1  r2  N)r  r  rO   r  r6  r  r   r   r   r   r   )r4   r9   rx   ry   r*  r+  s         r   &_UpdateHeterogeneousMigrationJobConfigz:MigrationJobsClient._UpdateHeterogeneousMigrationJobConfig  s    
 	00--22D	
 76
  #;;-Em*
==



	 
"%@	@0Hm-
==



	 !!')==DDKK!.!B!B!N!N!U!U "( " r   c                 j   |j                  d      r$| j                         |_        d|_        d|_        y|j                  d      r%| j                  |      |_        d|_        d|_        y| j                  D ]9  }|j                  |      s| j                  |      |_        d|_        d|_         y y)z1Update connectivity method for the migration job.r  Nr_   )r  ri   r  r  r  r`   _REVERSE_MAPre   )r4   rx   r9   fields       r   _UpdateConnectivityz'MigrationJobsClient._UpdateConnectivity  s    $+/+H+H+Jm(-1m*-1m*
#-1-L-L
.m* .2m*+/m(""			%	 /3/N/N0
, 04,-1* #r   c                 (   |j                   t        d      |j                   }|j                  d      r|j                  |_        |j                  d      r|j
                  |_        |j                  d      r|j                  |_        |j                  d      s|j                  d      r|j                  | j                  j                         |_	        |j                  d      r|j                  |j                  _        |j                  d      r|j                  |j                  _        |j                  d      r,| j!                  |j"                  |j$                        |_        y|j                  d	      rt)        j*                  d
d      y)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.)r#  r   rJ   r   r   r   r   r   r   r   r*   r   r   r   r   r   r   r   r   r   r   r@   )r4   r9   rx   r   s       r   -_UpdateSqlserverHomogeneousMigrationJobConfigzAMigrationJobsClient._UpdateSqlserverHomogeneousMigrationJobConfig0  s    ;;C;  	<< 3  ?@

,
, 5F  78

$
$ 5B  >?

+
+ 5E !		!	!"?	@	7	A	A	IMM,,. 	7@ 
	!	!";	<(( 	7@@I 
	!	!"?	@ ,, ;DDQ 56

+
+&&(J(J 5D
 
	!	!"A	B//
+1  
Cr   c                 v    |j                  d      s|j                  d      r| j                  |      |_        yy)z>Update the migration job objects config for the migration job.r   r   N)rJ   r   r$  )r4   r9   rx   s      r    _UpdateMigrationJobObjectsConfigz4MigrationJobsClient._UpdateMigrationJobObjectsConfige  s=      23t7O7O8 %)$F$Ft$Lm!8r   c           
         t        | j                        D cg c](  }|j                  |      rt        j                  |      * }}|j                  t        | j                        D cg c]7  }|j                  |      r$dj                  t        j                  |            9 c}       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d	      s|j                  d      r|j                  d
       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      r|j                  d       |j                  d      s|j                  d      r|j                  d       |j                  d      s|j                  d      r|j                  d       |S c c}w c c}w )z)Returns update mask for specified fields.zreverseSshConnectivity.{0}r_   zvpcPeeringConnectivity.vpcr   z#performanceConfig.dumpParallelLevelrZ   r"  rH   rE   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_MAPr  r   ConvertToCamelCaseextendr=  r   rw   rJ   )r4   r9   r>  ry   s       r   _GetUpdateMaskz"MigrationJobsClient._GetUpdateMaskm  sm    D,,--EE" 	,,U3-  
  D--.	 /EE"	 	%++007	
 /	  
#78 56@A,:&)8$,0H0H1 9: ?@
D  78
@  >?
C  9:
E  =>
I 		!	!"A	B
B  23t7O7O8 >?o
s   -I9)<I>c                     g }|j                         D ]1  \  }}|j                  | j                  j                  ||             3 | j                  j	                  |      S )z-Returns the dump flags for the migration job.)rO   value)r  )itemsrw   r*   DumpFlag	DumpFlags)r4   r    dump_flags_listrO   rK  s        r   r  z!MigrationJobsClient._GetDumpFlags  sc    O!'')e
--
 
  !  * ==""_"==r   c                 v   | j                  |      }|j                  d      r|j                  |_        |j                  d      r5| j	                  | j
                  j                  |j                        |_        |j                  d      r5| j                  | j
                  j                  |j                        |_        |j                  d      r|j                  |_        |j                  d      r | j                  |j                        |_        |j                  d      r|j#                         |_        |j                  d      r|j#                         |_        |j                  d      r| j)                  |      |_        |j                  d	      r<t-        j.                         j1                  |j2                        \  |_        }||_        | j5                  ||       | j7                  |||       |j                  d
      sf|j                  d      sU|j                  d      sD|j                  d      s3|j                  d      s"|j                  d      s|j                  d      r| j9                  ||       | j;                  ||       | j=                  |      r| j?                  |||       ||fS )z9Returns updated migration job and list of updated fields.r   r   rZ   r   r    r   r   r   rH   r   r   r   r   r   r   r   ) rI  r  r   r  rW   r*   rq   r   rJ   r\   rZ   r"  r   r  r  r    r  r   r   r   r   r!  r
   r  r   rH   r?  r~   rA  rC  r   r;  )r4   rx   r%  r&  r9   ry   r-  s          r   _GetUpdatedMigrationJobz+MigrationJobsClient._GetUpdatedMigrationJob  sN    ''-M'"&"3"3m==)C)CTYYOm,#00
--
$
$dnn m $#~~m% $ 2 24?? Cm!'446m&"1">">"@m 56(,(B(B4(Hm%)#1#:#:#<#D#D
++$ dk= +m]D1t]M:  !@A##$;<##$BC##$9:##$CD##$=>##$AB
88}M))$>33D9
11
} -''r   c                 p    | j                   j                  |      }| j                  j                  |      S )Nr   )r*   5DatamigrationProjectsLocationsMigrationJobsGetRequestr,   Get)r4   rO   get_reqs      r   _GetExistingMigrationJobz,MigrationJobsClient._GetExistingMigrationJob  s9    KK 	L 	
 
 ==W%%r   Nc                    | j                  |       | j                  ||       | j                  |||||      }t        j                         }	| j
                  j                  }
 |
||||	      }| j                  j                  |      S )ah  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.
      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:   rM   r.  r   GenerateRequestIdr*   8DatamigrationProjectsLocationsMigrationJobsCreateRequestr,   Create)r4   
parent_refmigration_job_idr%  r&  rL   r'  r9   rx   
request_idcreate_req_type
create_reqs               r   r^  zMigrationJobsClient.Create  s    < 	t))*BDI)) M ++-JNN  !"'	J ==
++r   c                    | j                  |       | j                  |      }t        |d      rI|j                  =| j	                  |j                  |       | j                  |j                  |      |_        | j                  ||||      \  }}t        j                         }| j                  j                  }	 |	|||dj                  |            }
| j                  j                  |
      S )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  ,)rX  rO   r[  
updateMask)r:   rV  hasattrr  rQ   r   rQ  r   r\  r*   7DatamigrationProjectsLocationsMigrationJobsPatchRequestjoinr,   Patch)r4   rO   r%  r&  r9   
current_mjrx   ry   ra  update_req_type
update_reqs              r   UpdatezMigrationJobsClient.Update$  s     	t..t4J 	
12**6
22

(
($ (,'N'N

(
($(j$ $(#?#?J$ M= ++-JMM  !"88M*	J ==z**r   c                     | j                   j                         }|j                  d      r| j                  |      |_        | j                   j                  ||      }| j                  j                  |      S )a  Promotes 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   )rO   promoteMigrationJobRequest)r*   PromoteMigrationJobRequestrJ   r   objectsFilter9DatamigrationProjectsLocationsMigrationJobsPromoteRequestr,   Promote)r4   rO   r9   promote_mj_reqpromote_reqs        r   rt  zMigrationJobsClient.PromoteU  st     ]]==?N 23%)%G%G%Mn" 	OO'5 	P 	
  ==  --r   c                 v   | j                   j                         }|j                  d      s|j                  d      r| j                  |      |_        |j                  d      rd|_        |j                  d      rd|_        | j                   j                  ||      }| j                  j                  |      S )a  Restarts 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)rO   restartMigrationJobRequest)
r*   RestartMigrationJobRequestrJ   r   rr  skipValidationrestartFailedObjects9DatamigrationProjectsLocationsMigrationJobsRestartRequestr,   Restart)r4   rO   r9   restart_mj_reqrestart_reqs        r   r  zMigrationJobsClient.Restartq  s     ]]==?N 23t7O7O8 &*%G%G%Mn" 12&*n# 89,0n) 	OO'5 	P 	
  ==  --r   c                 p    | j                   j                  |      }| j                  j                  |      S )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)r4   rO   fetch_source_objects_reqs      r   r  z&MigrationJobsClient.FetchSourceObjects  s:      $}}qq  r   ==++,DEEr   c                     | j                   j                  } ||j                               }t        j                  | j
                  |dddd      S )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.
    )rZ  NmigrationJobObjects)servicerequestlimit
batch_sizer>  batch_size_attribute)r*   =DatamigrationProjectsLocationsMigrationJobsObjectsListRequestr   r   YieldFromListr0   )r4   migration_job_reflist_req_typelist_reqs       r   ListObjectszMigrationJobsClient.ListObjects  sW     	SS  $5$B$B$DEH##%%#! r   )NNNr&   )0r   r   r   r   rF  r=  r5   r:   r7   rM   rQ   rW   r\   r`   re   ri   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r.  r6  r;  r?  rA  rC  rI  r  rQ  rV  r^  rn  rt  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kZ<!F23jM9v
>0(d&  $4,l/+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   rA   r   objectr   r   r   r   <module>r     sW    5 &  ' % ' > K D 7 ( . < = : 
7O!! 7S& Sr   