-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Synapse] az synapse link-connection
: New command group to support synapse link connections
#22876
Changes from 5 commits
2ede2b2
fcc473d
94abc39
495dbaa
c8f3560
d400658
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,6 +207,11 @@ def get_custom_sdk(custom_module, client_factory): | |
client_factory=cf_kusto_script, | ||
) | ||
|
||
synapse_link_connection_sdk = CliCommandType( | ||
operations_tmpl='azure.synapse.artifacts.operations#linkconnectionOperations.{}', | ||
client_factory=None, | ||
) | ||
|
||
# Management Plane Commands --Workspace | ||
with self.command_group('synapse workspace', command_type=synapse_workspace_sdk, | ||
custom_command_type=get_custom_sdk('workspace', cf_synapse_client_workspace_factory), | ||
|
@@ -577,3 +582,18 @@ def get_custom_sdk(custom_module, client_factory): | |
g.custom_command('list', 'synapse_kusto_script_list', client_factory=cf_kusto_scripts) | ||
g.custom_command('export', 'synapse_kusto_script_export') | ||
g.custom_wait_command('wait', 'synapse_kusto_script_show') | ||
|
||
with self.command_group('synapse link-connection', synapse_link_connection_sdk, | ||
custom_command_type=get_custom_sdk('artifacts', None)) as g: | ||
g.custom_command('list', 'list_link_connection') | ||
g.custom_show_command('show', 'get_link_connection') | ||
g.custom_command('delete', 'delete_link_connection') | ||
g.custom_command('create', 'create_or_update_link_connection') | ||
g.custom_command('update', 'create_or_update_link_connection') | ||
g.custom_command('get-status', 'get_link_connection_status') | ||
g.custom_command('start ', 'start_link_connection') | ||
g.custom_command('stop', 'stop_link_connection') | ||
g.custom_command('list-link-tables', 'synapse_list_link_table') | ||
g.custom_command('edit-link-tables', 'synapse_edit_link_table') | ||
g.custom_command('get-link-tables-status', 'synapse_get_link_tables_status') | ||
g.custom_command('update-landing-zone-credential', 'synapse_update_landing_zone_credential') | ||
Comment on lines
+586
to
+599
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then all these commands would have client instance automatically. For some simple commands, you can define |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,15 @@ | |
Trigger, DataFlow, BigDataPoolReference, NotebookSessionProperties, | ||
NotebookResource, SparkJobDefinition, SqlScriptResource, SqlScriptFolder, | ||
SqlScriptContent, SqlScriptMetadata, SqlScript, SqlConnection, | ||
NotebookFolder) | ||
NotebookFolder, LinkConnectionResource, LinkTableRequest, | ||
QueryTableStatusRequest, SecureString) | ||
from azure.cli.core.util import sdk_no_wait, CLIError | ||
from azure.core.exceptions import ResourceNotFoundError | ||
from .._client_factory import (cf_synapse_linked_service, cf_synapse_dataset, cf_synapse_pipeline, | ||
cf_synapse_pipeline_run, cf_synapse_trigger, cf_synapse_trigger_run, | ||
cf_synapse_data_flow, cf_synapse_notebook, cf_synapse_spark_pool, | ||
cf_synapse_spark_job_definition, cf_synapse_library, cf_synapse_sql_script) | ||
cf_synapse_spark_job_definition, cf_synapse_library, cf_synapse_sql_script, | ||
cf_synapse_link_connection) | ||
from ..constant import EXECUTOR_SIZE, SPARK_SERVICE_ENDPOINT_API_VERSION | ||
|
||
|
||
|
@@ -552,3 +554,76 @@ def export_sql_script(cmd, workspace_name, output_folder, sql_script_name=None): | |
from azure.cli.core.azclierror import InvalidArgumentValueError | ||
err_msg = 'Unable to export to file: {}'.format(path) | ||
raise InvalidArgumentValueError(err_msg) | ||
|
||
|
||
def list_link_connection(cmd, workspace_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.list_link_connections_by_workspace() | ||
|
||
|
||
def get_link_connection(cmd, workspace_name, link_connection_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.get_link_connection(link_connection_name) | ||
Comment on lines
+559
to
+566
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, these two commands is simple enough and can be defined as
|
||
|
||
|
||
def create_or_update_link_connection(cmd, workspace_name, link_connection_name, definition_file): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
info = definition_file['properties'] | ||
properties_file = {} | ||
properties_file['sourceDatabase'] = info['sourceDatabase'] | ||
properties_file['targetDatabase'] = info['targetDatabase'] | ||
properties_file['compute'] = info['compute'] | ||
if 'landingZone' in properties_file: | ||
properties_file['landingZone'] = info['landingZone'] | ||
properties = LinkConnectionResource(properties=properties_file) | ||
return client.create_or_update_link_connection(link_connection_name, properties) | ||
|
||
|
||
def delete_link_connection(cmd, workspace_name, link_connection_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.delete_link_connection(link_connection_name) | ||
|
||
|
||
def get_link_connection_status(cmd, workspace_name, link_connection_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.get_detailed_status(link_connection_name) | ||
|
||
|
||
def start_link_connection(cmd, workspace_name, link_connection_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.start(link_connection_name) | ||
|
||
|
||
def stop_link_connection(cmd, workspace_name, link_connection_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.stop(link_connection_name) | ||
|
||
|
||
def synapse_list_link_table(cmd, workspace_name, link_connection_name): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
return client.list_link_tables(link_connection_name).value | ||
|
||
|
||
def synapse_edit_link_table(cmd, workspace_name, link_connection_name, definition_file): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
linkTableRequset_list = [] | ||
for i in range(0, len(definition_file['linkTables'])): | ||
linkTableRequset = LinkTableRequest.from_dict(definition_file['linkTables'][i]) | ||
linkTableRequset_list.append(linkTableRequset) | ||
return client.edit_tables(link_connection_name, linkTableRequset_list) | ||
|
||
|
||
def synapse_get_link_tables_status(cmd, workspace_name, link_connection_name, max_segment_count=50, | ||
continuation_token=None): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
query_table_status_request = QueryTableStatusRequest( | ||
max_segment_count=max_segment_count, | ||
continuation_token=continuation_token | ||
) | ||
return client.query_table_status(link_connection_name, query_table_status_request) | ||
|
||
|
||
def synapse_update_landing_zone_credential(cmd, workspace_name, link_connection_name, sas_token): | ||
client = cf_synapse_link_connection(cmd.cli_ctx, workspace_name) | ||
sas_tokens = SecureString(value=sas_token) | ||
return client.update_landing_zone_credential(link_connection_name, sas_tokens) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"linkTables": [ | ||
{ | ||
"id": "887e9d4df0fa4afaaad0d7a2c7f42d88", | ||
"source": { | ||
"schemaName": "dbo", | ||
"tableName": "weather_history_300000_rows" | ||
}, | ||
"target": { | ||
"distributionOptions": { | ||
"distributionColumn": null, | ||
"type": "Round_RoBin" | ||
}, | ||
"schemaName": "dbo", | ||
"tableName": "weather_history_300000_rows" | ||
}, | ||
"operationType": "add" | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can define the client factory here