Skip to content

Commit

Permalink
[Synapse] az synapse link-connection: New command group to support …
Browse files Browse the repository at this point in the history
…synapse link connections (#22876)
  • Loading branch information
kevinzz6 authored Jun 30, 2022
1 parent c6636e9 commit 75a6af8
Show file tree
Hide file tree
Showing 19 changed files with 1,882 additions and 753 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,7 @@ def cf_kusto_scripts(cli_ctx, workspace_name):

def cf_synapse_sql_script(cli_ctx, workspace_name):
return cf_synapse_client_artifacts_factory(cli_ctx, workspace_name).sql_script


def cf_synapse_link_connection(cli_ctx, workspace_name):
return cf_synapse_client_artifacts_factory(cli_ctx, workspace_name).link_connection
172 changes: 172 additions & 0 deletions src/azure-cli/azure/cli/command_modules/synapse/manual/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,3 +2272,175 @@
--name testsqlscriptname \\
--file 'path/test.sql'
"""

helps['synapse link-connection'] = """
type: group
short-summary: Manage Synapse's link connection.
"""

helps['synapse link-connection list'] = """
type: command
short-summary: List link connections in a synapse workspace.
examples:
- name: List link connections.
text: |-
az synapse link-connection list --workspace-name testsynapseworkspace
"""

helps['synapse link-connection show'] = """
type: command
short-summary: Get a link connection.
examples:
- name: Get a link-connection.
text: |-
az synapse link-connection show --workspace-name testsynapseworkspace \\
--name testlinkconectionname
"""

helps['synapse link-connection delete'] = """
type: command
short-summary: Delete a link connection.
examples:
- name: Delete a link connection.
text: |-
az synapse link-connection delete --workspace-name testsynapseworkspace \\
--name testlinkconnectionname
"""

helps['synapse link-connection create'] = """
type: command
short-summary: Create a link connection.
examples:
- name: Create a link connection.
text: |-
az synapse link-connection create --workspace-name testsynapseworkspace \\
--name testlinkconnectionname \\
--file @"path/definition.json"
"""

helps['synapse link-connection update'] = """
type: command
short-summary: Update a link connection.
examples:
- name: Update a link connnection.
text: |-
az synapse link-connection update --workspace-name testsynapseworkspace \\
--name testlinkconnectionname \\
--file @"path/definition.json"
"""

helps['synapse link-connection start'] = """
type: command
short-summary: Start a link connnection.
examples:
- name: Start a link connection.
text: |-
az synapse link-connection start --workspace-name testsynapseworkspace \\
--name testlinkconnectionname
"""

helps['synapse link-connection stop'] = """
type: command
short-summary: Stop a link connection.
examples:
- name: Stop a link connection.
text: |-
az synapse link-connection stop --workspace-name testsynapseworkspace \\
--name testlinkconnectionname
"""

helps['synapse link-connection get-status'] = """
type: command
short-summary: check a link connection status after start/stop a link connection.
examples:
- name: Stop a link connection.
text: |-
az synapse link-connection get-status --workspace-name testsynapseworkspace \\
--name testlinkconnectionname
"""

helps['synapse link-connection list-link-tables'] = """
type: command
short-summary: List the link tables of a link connection.
examples:
- name: List the link tables of a link connection.
text: |-
az synapse link-connection list-link-tables --workspace-name testsynapseworkspace \\
--name linkconnectionname \\
"""

helps['synapse link-connection edit-link-tables'] = """
type: command
short-summary: Edit tables for a link connection.
examples:
- name: Edit tables for a link connection.
text: |-
az synapse link-connection edit-link-tables --workspace-name testsynapseworkspace \\
--name linkconnectionname \\
--file @path/edittablerequestfile.json
the file pattern should be:
{
"linkTables": [
{
"id": "<linkTableId1>",
"source": {
"tableName": "<sourceTableName1>",
"schemaName": "<sourceSchemaName1>"
},
"target": {
"tableName": "<sinkTableName1>",
"schemaName": "<sinkSchemaName1>",
"distributionOptions": {
"type": "<Hash|Round_RoBin|Replicate>",
"distributionColumn": "<distributionColumnName>"
}
},
"operationType": "add"
},
{
"id": "<linkTableId2>",
"operationType": "remove"
},
{
"id": "<linkTableId3>",
"source": {
"tableName": "<sourceTableName3>",
"schemaName": "<sourceSchemaName3>"
},
"target": {
"tableName": "<sinkTableName3>",
"schemaName": "<sinkSchemaName3>",
"distributionOptions": {
"type": "<Hash|Round_RoBin|Replicate>",
"distributionColumn": "<distributionColumnName>"
}
},
"operationType": "update"
}
]
}
"""

helps['synapse link-connection get-link-tables-status'] = """
type: command
short-summary: Query the link table status of a link connection.
examples:
- name: Query the link table status of a link connection.
text: |-
az synapse link-connection get-link-tables-status --workspace-name testsynapseworkspace \\
--name linkconnectionname \\
--max-segment-count 50 \\
--continuation-token token
"""

helps['synapse link-connection update-landing-zone-credential'] = """
type: command
short-summary: Update landing zone credetial of a link connection.
examples:
- name: Update landing zone credetial of a link connection.
text: |-
az synapse link-connection update-landing-zone-credential --workspace-name testsynapseworkspace \\
--name linkconnectionname \\
--sas-token sastoken
"""
35 changes: 35 additions & 0 deletions src/azure-cli/azure/cli/command_modules/synapse/manual/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,3 +1100,38 @@ def load_arguments(self, _):
c.argument('workspace_name', arg_type=workspace_name_arg_type, help='The name of the workspace')
c.argument('output_folder', type=str, help='The name of the output folder')
c.argument('script_name', arg_type=name_type, help='The name of the KQL script.')

# synapse link connections
with self.argument_context('synapse link-connection list') as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)

for scope in ['create', 'update']:
with self.argument_context('synapse link-connection ' + scope) as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
c.argument('link_connection_name', arg_type=name_type, help='The link connection name.')
c.argument('definition_file', arg_type=definition_file_arg_type)

for scope in ['show', 'delete', 'get-status', 'start', 'stop']:
with self.argument_context('synapse link-connection ' + scope) as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
c.argument('link_connection_name', arg_type=name_type, help='The link connection name.')

with self.argument_context('synapse link-connection list-link-tables') as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
c.argument('link_connection_name', arg_type=name_type, help='The link connection name.')

with self.argument_context('synapse link-connection edit-link-tables') as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
c.argument('link_connection_name', arg_type=name_type, help='The link connection name.')
c.argument('definition_file', arg_type=definition_file_arg_type, options_list=['--file', '-f'], type=shell_safe_json_parse,
help='The Edit link-tables file path, The file format can be viewed using --help.')

with self.argument_context('synapse link-connection get-link-tables-status') as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
c.argument('link_connection_name', arg_type=name_type, help='The link connection name.')
c.argument('max_segment_count', help='Max segment count to query table status.')
c.argument('continuation_token', help='Continuation token to query table status.')
with self.argument_context('synapse link-connection update-landing-zone-credential') as c:
c.argument('workspace_name', arg_type=workspace_name_arg_type)
c.argument('link_connection_name', arg_type=name_type, help='The link connection name.')
c.argument('sas_token', help='Value of secure string.')
20 changes: 20 additions & 0 deletions src/azure-cli/azure/cli/command_modules/synapse/manual/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)


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"
}
]
}
Loading

0 comments on commit 75a6af8

Please sign in to comment.