def create_task(cmd, client, resource_group_name, service_name, project_name, task_name, task_type, source_connection_json, target_connection_json, database_options_json, enable_schema_validation=False, enable_data_integrity_validation=False, enable_query_analysis_validation=False, validate_only=False, validated_task_name=None): # Get source and target platform abd set inputs to lowercase source_platform, target_platform = get_project_platforms( cmd, project_name=project_name, service_name=service_name, resource_group_name=resource_group_name) task_type = task_type.lower() scenario_handled_in_extension = extension_handles_scenario( source_platform, target_platform, task_type) # Validation: Test scenario eligibility if not scenario_handled_in_extension: # If not an extension scenario, run CLI core method # TODO: Remove this check after validations are added to core if source_platform != "sql" or target_platform != "sqldb": raise CLIError( "The combination of the provided task-type and the project's \ source-platform and target-platform is not appropriate. \n\ Please refer to the help file 'az dms project task create -h' \ for the supported scenarios.") # TODO: Calling this validates our inputs. Remove this check after this function is added to core transform_json_inputs(source_connection_json, source_platform, target_connection_json, target_platform, database_options_json) return core_create_task( client, resource_group_name, service_name, project_name, task_name, source_connection_json, target_connection_json, database_options_json, enable_schema_validation, enable_data_integrity_validation, enable_query_analysis_validation) RequireValidationScenarios = [ ScenarioType.mongo_mongo_offline, ScenarioType.mongo_mongo_online ] # Mongo migrations require users to validate their migrations first # Once the migration settings have been attempted, if all database and collection objects aren't in a 'Failed' # state continue creating the task if get_scenario_type(source_platform, target_platform, task_type) in RequireValidationScenarios: if validate_only is False and validated_task_name is None: raise CLIError( "When not validating a MongoDB task, you must supply a previously run 'validate_only' task name." ) if validate_only is False and validated_task_name is not None: # Though getting the task's properties is pretty quick, we want to let the user know something is happening logger.warning("Reviewing validation...") v_result = client.get(group_name=resource_group_name, service_name=service_name, project_name=project_name, task_name=validated_task_name, expand="output") if not mongo_validation_succeeded(v_result.properties.output[0]): raise CLIError( "Not all collections passed during the validation task. Fix your settings, \ validate those settings, and try again. \n\ To view the errors use 'az dms project task show' with the '--expand output' argument on your previous \ validate-only task.") # Get json inputs source_connection_info, target_connection_info, database_options_json = \ transform_json_inputs(source_connection_json, source_platform, target_connection_json, target_platform, database_options_json) # Get the task properties properties_model = get_task_validation_properties if validate_only else get_task_migration_properties task_properties = properties_model(database_options_json, source_platform, target_platform, task_type, source_connection_info, target_connection_info) return client.create_or_update(group_name=resource_group_name, service_name=service_name, project_name=project_name, task_name=task_name, properties=task_properties)
def create_task( cmd, client, resource_group_name, service_name, project_name, task_name, task_type, source_connection_json, target_connection_json, database_options_json, enable_schema_validation=False, enable_data_integrity_validation=False, enable_query_analysis_validation=False, validate_only=False): # Get source and target platform abd set inputs to lowercase source_platform, target_platform = get_project_platforms(cmd, project_name=project_name, service_name=service_name, resource_group_name=resource_group_name) task_type = task_type.lower() scenario_handled_in_extension = extension_handles_scenario(source_platform, target_platform, task_type) # Validation: Test scenario eligibility if not scenario_handled_in_extension: # If not an extension scenario, run CLI core method try: # TODO: Remove this check after validations are added to core if scenario_handled_in_extension: raise ValueError core_res = core_create_task(client, resource_group_name, service_name, project_name, task_name, source_connection_json, target_connection_json, database_options_json, enable_schema_validation, enable_data_integrity_validation, enable_query_analysis_validation) except: # TODO: We currently don't have any CLI core code to perform any validations # because of this we need to raise the error here. raise ValueError("The combination of the provided task-type and the project's \ source-platform and target-platform is not appropriate. \n\ Please refer to the help file 'az dms project task create -h' \ for the supported scenarios.") else: return core_res # Run extension scenario source_connection_info, target_connection_info, database_options_json = \ transform_json_inputs(source_connection_json, source_platform, target_connection_json, target_platform, database_options_json) # Get the task properties properties_model = get_task_validation_properties if validate_only else get_task_migration_properties task_properties = properties_model(database_options_json, source_platform, target_platform, task_type, source_connection_info, target_connection_info) return client.create_or_update(group_name=resource_group_name, service_name=service_name, project_name=project_name, task_name=task_name, properties=task_properties)
def create_task( cmd, client, resource_group_name, service_name, project_name, task_name, task_type, source_connection_json, target_connection_json, database_options_json, enable_schema_validation=False, enable_data_integrity_validation=False, enable_query_analysis_validation=False, validate_only=False, validated_task_name=None): # Get source and target platform abd set inputs to lowercase source_platform, target_platform = get_project_platforms(cmd, project_name=project_name, service_name=service_name, resource_group_name=resource_group_name) task_type = task_type.lower() scenario_handled_in_extension = extension_handles_scenario(source_platform, target_platform, task_type) # Validation: Test scenario eligibility if not scenario_handled_in_extension: # If not an extension scenario, run CLI core method try: # TODO: Remove this check after validations are added to core if source_platform != "sql" or target_platform != "sqldb": raise CLIError("The combination of the provided task-type and the project's \ source-platform and target-platform is not appropriate. \n\ Please refer to the help file 'az dms project task create -h' \ for the supported scenarios.") # TODO: Calling this validates our inputs. Remove this check after this function is added to core transform_json_inputs(source_connection_json, source_platform, target_connection_json, target_platform, database_options_json) core_res = core_create_task(client, resource_group_name, service_name, project_name, task_name, source_connection_json, target_connection_json, database_options_json, enable_schema_validation, enable_data_integrity_validation, enable_query_analysis_validation) except: # TODO: We currently don't have any CLI core code to perform any validations # because of this we need to raise the error here. raise else: return core_res RequireValidationScenarios = [ ScenarioType.mongo_mongo_offline, ScenarioType.mongo_mongo_online] # Mongo migrations require users to validate their migrations first # Once the migration settings have been attempted, if all database and collection objects aren't in a 'Failed' # state continue creating the task if get_scenario_type(source_platform, target_platform, task_type) in RequireValidationScenarios: if validate_only is False and validated_task_name is None: raise CLIError( "When not validating a MongoDB task, you must supply a previously run 'validate_only' task name.") elif validate_only is False and validated_task_name is not None: # Though getting the task's properties is pretty quick, we want to let the user know something is happening logger.warning("Reviewing validation...") v_result = client.get(group_name=resource_group_name, service_name=service_name, project_name=project_name, task_name=validated_task_name, expand="output") if not mongo_validation_succeeded(v_result.properties.output[0]): raise CLIError("Not all collections passed during the validation task. Fix your settings, \ validate those settings, and try again. \n\ To view the errors use 'az dms project task show' with the '--expand output' argument on your previous \ validate-only task.") # Get json inputs source_connection_info, target_connection_info, database_options_json = \ transform_json_inputs(source_connection_json, source_platform, target_connection_json, target_platform, database_options_json) # Get the task properties properties_model = get_task_validation_properties if validate_only else get_task_migration_properties task_properties = properties_model(database_options_json, source_platform, target_platform, task_type, source_connection_info, target_connection_info) return client.create_or_update(group_name=resource_group_name, service_name=service_name, project_name=project_name, task_name=task_name, properties=task_properties)
def create_task(client, resource_group_name, service_name, project_name, task_name, source_platform, target_platform, task_type, source_connection_json, target_connection_json, database_options_json, enable_schema_validation=False, enable_data_integrity_validation=False, enable_query_analysis_validation=False): # Set inputs to lowercase task_type = task_type.lower() source_platform = source_platform.lower() target_platform = target_platform.lower() # Validation: Test scenario eligibility if not determine_scenario_eligibility(source_platform, target_platform, task_type): # If not an extension scenario, run CLI core method # TODO: We currently don't have any CLI core code to perform any validations # because of this we need to raise the error here. try: # CLI core doesnt currently support task types - it only supports offline migrations. # TODO: Remove this check after task types are supported if source_platform != "sql" or target_platform != "sqldb" or task_type != "offlinemigration": raise ValueError core_res = core_create_task( client, resource_group_name, service_name, project_name, task_name, source_connection_json, target_connection_json, database_options_json, enable_schema_validation, enable_data_integrity_validation, enable_query_analysis_validation) except: raise ValueError( "The provided source-platform, target-platform, and task-type \ combination is not appropriate. \n\ Please refer to the help file 'az dms project task create -h' for the supported scenarios." ) else: return core_res # Run extension scenario # Source connection info if os.path.exists(source_connection_json): source_connection_json = get_file_json(source_connection_json) else: source_connection_json = shell_safe_json_parse(source_connection_json) source_connection_info = create_connection(source_connection_json, "Source Database", source_platform) # Target connection info if os.path.exists(target_connection_json): target_connection_json = get_file_json(target_connection_json) else: target_connection_json = shell_safe_json_parse(target_connection_json) target_connection_info = create_connection(target_connection_json, "Target Database", target_platform) # Database options if os.path.exists(database_options_json): database_options_json = get_file_json(database_options_json) else: database_options_json = shell_safe_json_parse(database_options_json) # Get the task properties task_properties = get_task_migration_properties(database_options_json, source_platform, target_platform, task_type, source_connection_info, target_connection_info) return client.create_or_update(group_name=resource_group_name, service_name=service_name, project_name=project_name, task_name=task_name, properties=task_properties)