Skip to content

Commit

Permalink
Dt data history3 (#504)
Browse files Browse the repository at this point in the history
* Remove flag, change consumer group check logic
  • Loading branch information
vilit1 authored Mar 23, 2022
1 parent 57ec71d commit 8c14895
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 178 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Release History
- az dt endpoint create
- az dt private-endpoint create

* Added `az dt data-history` command group, which will allow users to configure a data history connection
for a Digital Twins instance using an Event Hub and Azure Data Explorer database. Once configured,
changes to the Digital Twins instance can be seen in the Azure Data Explorer database.

**IoT Central updates**

* Added commands for Edge devices and modules:
Expand Down
237 changes: 116 additions & 121 deletions azext_iot/digitaltwins/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
Help definitions for IoT Hub commands.
"""

import os
from knack.help_files import helps

enabled_data_history = os.environ.get("ADT_DH_PREVIEW_ENABLE")


def load_digitaltwins_help():

Expand Down Expand Up @@ -143,124 +140,122 @@ def load_digitaltwins_help():
az dt reset -n {instance_name}
"""

# TODO: uncomment once data history is public
if enabled_data_history:
helps["dt data-history"] = """
type: group
short-summary: Manage and configure data history.
"""

helps["dt data-history connection"] = """
type: group
short-summary: Manage and configure data history connections.
"""

helps["dt data-history connection create"] = """
type: group
short-summary: Creates a data history connection between a Digital Twins instance and supported resources.
"""

helps["dt data-history connection create adx"] = """
type: command
short-summary: Creates a data history connection between a Digital Twins instance and an Azure
Data Explorer database. Requires pre-created Azure Data Explorer and Event Hub resources.
long-summary: |
Will prompt the user to add the following roles and permissions on the Digital Twins instance needed to successfully create the connection:
- 'Contributor' role for the Azure Data Explorer Database scope
- 'Database Admin' permission for the Azure Data Explorer Database scope
- 'Azure Event Hubs Data Owner' role for the Event Hub scope
examples:
- name: Adds a data history connection to a target Digital Twins instance with the $Default Event Hub
consumer group.
text: >
az dt data-history connection create adx -n {instance_name}
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
- name: Adds a data history connection to a target Digital Twins instance with a custom Azure Data Explorer
table name and Event Hub consumer group.
text: >
az dt data-history connection create adx -n {instance_name}
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--adx-table-name {adx_table_name}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
--eventhub-consumer-group {event_hub_consumer_group}
- name: Adds a data history connection to a target Digital Twins instance integrating with an Event Hub and Azure
Data Explorer instances in different resource groups and subscriptions from the target instance.
text: >
az dt data-history connection create adx -n {instance_name}
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--adx-resource-group {adx_resource_group}
--adx-subscription {adx_subscription}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
--eventhub-resource-group {event_hub_resource_group}
--eventhub-subscription {event_subscription}
- name: Adds a data history connection to a target Digital Twins instance with the $Default Event Hub consumer group
and skip the role assignment prompts.
text: >
az dt data-history connection create adx -n {instance_name} -y
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
"""

helps["dt data-history connection list"] = """
type: command
short-summary: List all data history connections configured on a Digital Twins instance.
examples:
- name: List all data history connections configured on an instance.
text: >
az dt data-history connection list -n {instance_name}
"""

helps["dt data-history connection show"] = """
type: command
short-summary: Show details of a data history connection configured on a Digital Twins instance.
examples:
- name: Show a data history connection configured on an instance.
text: >
az dt data-history connection show -n {instance_name} --cn {time_series_database_connection_name}
"""

helps["dt data-history connection wait"] = """
type: command
short-summary: Wait until an operation on a data history connection is complete.
examples:
- name: Wait until a data history connection is created.
text: >
az dt data-history connection wait -n {instance_name} --cn {time_series_database_connection_name} --created
- name: Wait until an existing data history connection is deleted.
text: >
az dt data-history connection wait -n {instance_name} --cn {time_series_database_connection_name} --deleted
"""

helps["dt data-history connection delete"] = """
type: command
short-summary: Delete a data history connection configured on a Digital Twins instance.
examples:
- name: Delete a data history connection configured on an instance
and block until the operation is complete.
text: >
az dt data-history connection delete -n {instance_name}
--cn {time_series_database_connection_name}
- name: Delete a data history connection configured on an instance
without confirmation or blocking.
text: >
az dt data-history connection delete -n {instance_name}
--cn {time_series_database_connection_name}
-y --no-wait
"""
helps["dt data-history"] = """
type: group
short-summary: Manage and configure data history.
"""

helps["dt data-history connection"] = """
type: group
short-summary: Manage and configure data history connections.
"""

helps["dt data-history connection create"] = """
type: group
short-summary: Creates a data history connection between a Digital Twins instance and supported resources.
"""

helps["dt data-history connection create adx"] = """
type: command
short-summary: Creates a data history connection between a Digital Twins instance and an Azure
Data Explorer database. Requires pre-created Azure Data Explorer and Event Hub resources.
long-summary: |
Will prompt the user to add the following roles and permissions on the Digital Twins instance needed to successfully create the connection:
- 'Contributor' role for the Azure Data Explorer Database scope
- 'Database Admin' permission for the Azure Data Explorer Database scope
- 'Azure Event Hubs Data Owner' role for the Event Hub scope
examples:
- name: Adds a data history connection to a target Digital Twins instance with the $Default Event Hub
consumer group.
text: >
az dt data-history connection create adx -n {instance_name}
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
- name: Adds a data history connection to a target Digital Twins instance with a custom Azure Data Explorer
table name and Event Hub consumer group.
text: >
az dt data-history connection create adx -n {instance_name}
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--adx-table-name {adx_table_name}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
--eventhub-consumer-group {event_hub_consumer_group}
- name: Adds a data history connection to a target Digital Twins instance integrating with an Event Hub and Azure
Data Explorer instances in different resource groups and subscriptions from the target instance.
text: >
az dt data-history connection create adx -n {instance_name}
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--adx-resource-group {adx_resource_group}
--adx-subscription {adx_subscription}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
--eventhub-resource-group {event_hub_resource_group}
--eventhub-subscription {event_subscription}
- name: Adds a data history connection to a target Digital Twins instance with the $Default Event Hub consumer group
and skip the role assignment prompts.
text: >
az dt data-history connection create adx -n {instance_name} -y
--cn {time_series_database_connection_name}
--adx-cluster-name {adx_cluster_name}
--adx-database-name {adx_database_name}
--eventhub {event_hub}
--eventhub-namespace {event_hub_namespace}
"""

helps["dt data-history connection list"] = """
type: command
short-summary: List all data history connections configured on a Digital Twins instance.
examples:
- name: List all data history connections configured on an instance.
text: >
az dt data-history connection list -n {instance_name}
"""

helps["dt data-history connection show"] = """
type: command
short-summary: Show details of a data history connection configured on a Digital Twins instance.
examples:
- name: Show a data history connection configured on an instance.
text: >
az dt data-history connection show -n {instance_name} --cn {time_series_database_connection_name}
"""

helps["dt data-history connection wait"] = """
type: command
short-summary: Wait until an operation on a data history connection is complete.
examples:
- name: Wait until a data history connection is created.
text: >
az dt data-history connection wait -n {instance_name} --cn {time_series_database_connection_name} --created
- name: Wait until an existing data history connection is deleted.
text: >
az dt data-history connection wait -n {instance_name} --cn {time_series_database_connection_name} --deleted
"""

helps["dt data-history connection delete"] = """
type: command
short-summary: Delete a data history connection configured on a Digital Twins instance.
examples:
- name: Delete a data history connection configured on an instance
and block until the operation is complete.
text: >
az dt data-history connection delete -n {instance_name}
--cn {time_series_database_connection_name}
- name: Delete a data history connection configured on an instance
without confirmation or blocking.
text: >
az dt data-history connection delete -n {instance_name}
--cn {time_series_database_connection_name}
-y --no-wait
"""

helps["dt endpoint"] = """
type: group
Expand Down
52 changes: 23 additions & 29 deletions azext_iot/digitaltwins/command_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
Load CLI commands
"""
import os
from azure.cli.core.commands import CliCommandType

digitaltwins_resource_ops = CliCommandType(
Expand All @@ -31,9 +30,6 @@
)


enabled_data_history = os.environ.get("ADT_DH_PREVIEW_ENABLE")


def load_digitaltwins_commands(self, _):
"""
Load CLI commands
Expand All @@ -49,31 +45,29 @@ def load_digitaltwins_commands(self, _):
cmd_group.wait_command("wait", "wait_instance")
cmd_group.command("reset", "reset_instance", confirmation=True, is_preview=True)

# TODO: unhide in with Public preview for data history
if enabled_data_history:
with self.command_group(
"dt data-history",
command_type=digitaltwins_resource_ops,
is_preview=True,
) as cmd_group:
pass

with self.command_group(
"dt data-history connection",
command_type=digitaltwins_resource_ops,
) as cmd_group:
cmd_group.show_command("show", "show_data_connection")
cmd_group.wait_command("wait", "wait_data_connection")
cmd_group.command("list", "list_data_connection")
cmd_group.command(
"delete", "delete_data_connection", confirmation=True, supports_no_wait=True
)

with self.command_group(
"dt data-history connection create",
command_type=digitaltwins_resource_ops,
) as cmd_group:
cmd_group.command("adx", "create_adx_data_connection", supports_no_wait=True)
with self.command_group(
"dt data-history",
command_type=digitaltwins_resource_ops,
is_preview=True,
) as cmd_group:
pass

with self.command_group(
"dt data-history connection",
command_type=digitaltwins_resource_ops,
) as cmd_group:
cmd_group.show_command("show", "show_data_connection")
cmd_group.wait_command("wait", "wait_data_connection")
cmd_group.command("list", "list_data_connection")
cmd_group.command(
"delete", "delete_data_connection", confirmation=True, supports_no_wait=True
)

with self.command_group(
"dt data-history connection create",
command_type=digitaltwins_resource_ops,
) as cmd_group:
cmd_group.command("adx", "create_adx_data_connection", supports_no_wait=True)

with self.command_group(
"dt endpoint", command_type=digitaltwins_resource_ops
Expand Down
4 changes: 4 additions & 0 deletions azext_iot/digitaltwins/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
SKIP_ADD_ROLE_MSG = "Skipping addition of the {0}. This may prevent creation of the data history connection."


# Default Event Hub Consumer Group
DEFAULT_CONSUMER_GROUP = "$Default"


# Enums
class ADTEndpointType(Enum):
"""
Expand Down
Loading

0 comments on commit 8c14895

Please sign in to comment.