Skip to content

Commit 4559e19

Browse files
author
Zoltan Varga
authored
Address feedbacks: Rename type, improve readme (Azure#14905)
* fix(azure-digitaltwins-core): address feedbacks * fix(digitaltwins): update for GA * fix(digitaltwins): address comments * fix(digitaltwins): update unit tests * fix(digitaltwins): address more comments * fix(digitaltwins): fix link error * fix(digitaltwins): fix link error 2 * fix(digitaltwins): set "unreleased" in changelog
1 parent aebd212 commit 4559e19

File tree

19 files changed

+283
-178
lines changed

19 files changed

+283
-178
lines changed

eng/ignore-links.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ https://docs.microsoft.com/python/api/overview/azure/{{package_doc_id}}
22
https://pypi.org/project/azure-servicebus/7.0.0b7/
33
https://github.com/Azure/azure-digital-twins/blob/private-preview/Documentation/how-to-manage-routes.md
44
https://pypi.org/project/azure-digitaltwins-core
5-
6-
5+
https://docs.microsoft.com/azure/digital-twins/how-to-query-graph#query-limitations
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release History
22

3+
## 1.0.0 (unreleased)
4+
5+
- The is the GA release containing the following changes:
6+
- Added etag and match_condition parameters to upsert_digital_twin and upsert_relationship APIs to support conditional operation.
7+
- Rename EventRoute type to DigitalTwinsEventRoute
8+
- Rename component_path to component_name
9+
- Rename models to dtdl_models
10+
- Fix some documentation
11+
312
## 1.0.0b1 (2020-10-31)
413

514
* Initial Release

sdk/digitaltwins/azure-digitaltwins-core/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This package contains an SDK for Azure Digital Twins API to provide access to the Azure Digital Twins service for managing twins, models, relationships, etc.
44

5-
This package contains an isomorphic SDK for Azure Digital Twins API to provide access to the Azure Digital Twins service for managing twins, models, relationships, etc.
6-
75
## Getting started
86

97
### Introduction
@@ -194,6 +192,9 @@ print(get_twin)
194192

195193
Query the Azure Digital Twins instance for digital twins using the [Azure Digital Twins Query Store lanaguage](https://review.docs.microsoft.com/azure/digital-twins/concepts-query-language). Query calls support paging. Here's an example of how to query for digital twins and how to iterate over the results.
196194

195+
Note that there may be a delay between before changes in your instance are reflected in queries.
196+
For more details on query limitations, see (https://docs.microsoft.com/azure/digital-twins/how-to-query-graph#query-limitations)
197+
197198
```Python Snippet:dt_digitaltwins_query
198199
query_expression = 'SELECT * FROM digitaltwins'
199200
query_result = service_client.query_twins(query_expression)

sdk/digitaltwins/azure-digitaltwins-core/azure/digitaltwins/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from ._generated.models import DigitalTwinsModelData
1111
from ._generated.models import QueryResult
1212
from ._generated.models import IncomingRelationship
13-
from ._generated.models import EventRoute
13+
from ._generated.models import DigitalTwinsEventRoute
1414

1515
__all__ = [
1616
'DigitalTwinsClient',
1717
'DigitalTwinsModelData',
1818
'QueryResult',
1919
'IncomingRelationship',
20-
'EventRoute'
20+
'DigitalTwinsEventRoute'
2121
]
2222

2323
from ._version import VERSION

sdk/digitaltwins/azure-digitaltwins-core/azure/digitaltwins/core/_digitaltwins_client.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from azure.core import MatchConditions
1414

1515
from ._utils import (
16-
prep_if_match
16+
prep_if_match,
17+
prep_if_none_match
1718
)
1819

1920
from ._generated import models
@@ -65,6 +66,9 @@ def upsert_digital_twin(self, digital_twin_id, digital_twin, **kwargs):
6566
:param str digital_twin_id: The Id of the digital twin.
6667
:param Dict[str, object] digital_twin:
6768
Dictionary containing the twin to create or update.
69+
:keyword str etag: Only perform the operation if the entity does not already exist.
70+
:keyword ~azure.core.MatchConditions match_condition:
71+
The match condition to use upon the etag
6872
:return: Dictionary containing the created or updated twin.
6973
:rtype: Dict[str, object]
7074
:raises :class: `~azure.core.exceptions.HttpResponseError`
@@ -73,9 +77,13 @@ def upsert_digital_twin(self, digital_twin_id, digital_twin, **kwargs):
7377
:raises :class: `~azure.core.exceptions.ResourceExistsError`:
7478
If the digital twin is already exist.
7579
"""
80+
etag = kwargs.get("etag", None)
81+
match_condition = kwargs.get("match_condition", MatchConditions.Unconditionally)
82+
7683
return self._client.digital_twins.add(
7784
digital_twin_id,
7885
digital_twin,
86+
if_none_match=prep_if_none_match(etag, match_condition),
7987
**kwargs
8088
)
8189

@@ -146,12 +154,12 @@ def delete_digital_twin(
146154
)
147155

148156
@distributed_trace
149-
def get_component(self, digital_twin_id, component_path, **kwargs):
157+
def get_component(self, digital_twin_id, component_name, **kwargs):
150158
# type: (str, str, **Any) -> Dict[str, object]
151159
"""Get a component on a digital twin.
152160
153161
:param str digital_twin_id: The Id of the digital twin.
154-
:param str component_path: The component being retrieved.
162+
:param str component_name: The component being retrieved.
155163
:return: Dictionary containing the component.
156164
:rtype: Dict[str, object]
157165
:raises :class: `~azure.core.exceptions.HttpResponseError`
@@ -160,23 +168,23 @@ def get_component(self, digital_twin_id, component_path, **kwargs):
160168
"""
161169
return self._client.digital_twins.get_component(
162170
digital_twin_id,
163-
component_path,
171+
component_name,
164172
**kwargs
165173
)
166174

167175
@distributed_trace
168176
def update_component(
169177
self,
170178
digital_twin_id,
171-
component_path,
179+
component_name,
172180
json_patch,
173181
**kwargs
174182
):
175183
# type: (str, str, Dict[str, object], **Any) -> None
176184
"""Update properties of a component on a digital twin using a JSON patch.
177185
178186
:param str digital_twin_id: The Id of the digital twin.
179-
:param str component_path: The component being updated.
187+
:param str component_name: The component being updated.
180188
:param Dict[str, object] json_patch: An update specification described by JSON Patch.
181189
:keyword str etag: Only perform the operation if the entity's etag matches one of
182190
the etags provided or * is provided.
@@ -193,7 +201,7 @@ def update_component(
193201

194202
return self._client.digital_twins.update_component(
195203
digital_twin_id,
196-
component_path,
204+
component_name,
197205
patch_document=json_patch,
198206
if_match=prep_if_match(etag, match_condition),
199207
**kwargs
@@ -226,17 +234,24 @@ def upsert_relationship(self, digital_twin_id, relationship_id, relationship=Non
226234
:param str digital_twin_id: The Id of the digital twin.
227235
:param str relationship_id: The Id of the relationship to retrieve.
228236
:param Dict[str, object] relationship: Dictionary containing the relationship.
237+
:keyword str etag: Only perform the operation if the entity does not already exist.
238+
:keyword ~azure.core.MatchConditions match_condition:
239+
The match condition to use upon the etag
229240
:return: The created or updated relationship.
230241
:rtype: Dict[str, object]
231242
:raises :class: `~azure.core.exceptions.HttpResponseError`
232243
:raises :class: `~azure.core.exceptions.ServiceRequestError`: If the request is invalid.
233244
:raises :class: `~azure.core.exceptions.ResourceNotFoundError`: If there is either no
234245
digital twin, target digital twin or relationship with the provided id.
235246
"""
247+
etag = kwargs.get("etag", None)
248+
match_condition = kwargs.get("match_condition", MatchConditions.Unconditionally)
249+
236250
return self._client.digital_twins.add_relationship(
237251
id=digital_twin_id,
238252
relationship_id=relationship_id,
239253
relationship=relationship,
254+
if_none_match=prep_if_none_match(etag, match_condition),
240255
**kwargs
241256
)
242257

@@ -378,7 +393,7 @@ def publish_telemetry(self, digital_twin_id, payload, message_id=None, **kwargs)
378393
def publish_component_telemetry(
379394
self,
380395
digital_twin_id,
381-
component_path,
396+
component_name,
382397
payload,
383398
message_id=None,
384399
**kwargs
@@ -388,7 +403,7 @@ def publish_component_telemetry(
388403
one or many destination endpoints (subscribers) defined under.
389404
390405
:param str digital_twin_id: The Id of the digital twin.
391-
:param str component_path: The name of the DTDL component.
406+
:param str component_name: The name of the DTDL component.
392407
:param object payload: The telemetry payload to be sent.
393408
:param str message_id: The message Id.
394409
:return: None
@@ -404,7 +419,7 @@ def publish_component_telemetry(
404419

405420
return self._client.digital_twins.send_component_telemetry(
406421
digital_twin_id,
407-
component_path,
422+
component_name,
408423
dt_id=message_id,
409424
telemetry=payload,
410425
dt_timestamp=timestamp,
@@ -464,7 +479,7 @@ def list_models(self, dependencies_for, **kwargs):
464479
)
465480

466481
@distributed_trace
467-
def create_models(self, model_list=None, **kwargs):
482+
def create_models(self, dtdl_models=None, **kwargs):
468483
# type: (Optional[List[object]], **Any) -> List[~azure.digitaltwins.models.ModelData]
469484
"""Create one or more models. When any error occurs, no models are uploaded.
470485
@@ -477,7 +492,7 @@ def create_models(self, model_list=None, **kwargs):
477492
the provided models already exist.
478493
"""
479494
return self._client.digital_twin_models.add(
480-
model_list,
495+
dtdl_models,
481496
**kwargs
482497
)
483498

@@ -524,12 +539,12 @@ def delete_model(self, model_id, **kwargs):
524539

525540
@distributed_trace
526541
def get_event_route(self, event_route_id, **kwargs):
527-
# type: (str, **Any) -> ~azure.digitaltwins.models.EventRoute
542+
# type: (str, **Any) -> DigitalTwinsEventRoute
528543
"""Get an event route.
529544
530545
:param str event_route_id: The Id of the event route.
531-
:return: The EventRoute object.
532-
:rtype: ~azure.digitaltwins.models.EventRoute
546+
:return: The DigitalTwinsEventRoute object.
547+
:rtype: DigitalTwinsEventRoute
533548
:raises :class: `~azure.core.exceptions.HttpResponseError`
534549
:raises :class: `~azure.core.exceptions.ResourceNotFoundError`: There is no
535550
event route with the provided id.
@@ -541,13 +556,13 @@ def get_event_route(self, event_route_id, **kwargs):
541556

542557
@distributed_trace
543558
def list_event_routes(self, **kwargs):
544-
# type: (**Any) -> ~azure.core.paging.ItemPaged[~azure.digitaltwins.models.EventRoute]
559+
# type: (**Any) -> ~azure.core.paging.ItemPaged[DigitalTwinsEventRoute]
545560
"""Retrieves all event routes.
546561
547562
:keyword int results_per_page: The maximum number of items to retrieve per request.
548563
The server may choose to return less than the requested max.
549-
:return: An iterator instance of list of EventRoute.
550-
:rtype: ~azure.core.paging.ItemPaged[~azure.digitaltwins.models.EventRoute]
564+
:return: An iterator instance of list of DigitalTwinsEventRoute.
565+
:rtype: ~azure.core.paging.ItemPaged[DigitalTwinsEventRoute]
551566
:raises :class: `~azure.core.exceptions.HttpResponseError`
552567
:raises :class: `~azure.core.exceptions.ServiceRequestError`: The request is invalid.
553568
"""
@@ -563,11 +578,11 @@ def list_event_routes(self, **kwargs):
563578

564579
@distributed_trace
565580
def upsert_event_route(self, event_route_id, event_route, **kwargs):
566-
# type: (str, "models.EventRoute", **Any) -> None
581+
# type: (str, "DigitalTwinsEventRoute", **Any) -> None
567582
"""Create or update an event route.
568583
569584
:param str event_route_id: The Id of the event route to create or update.
570-
:param ~azure.digitaltwins.models.EventRoute event_route: The event route data.
585+
:param DigitalTwinsEventRoute event_route: The event route data.
571586
:return: None
572587
:rtype: None
573588
:raises :class: `~azure.core.exceptions.HttpResponseError`
@@ -599,6 +614,9 @@ def delete_event_route(self, event_route_id, **kwargs):
599614
def query_twins(self, query_expression, **kwargs):
600615
# type: (str, **Any) -> ~azure.core.async_paging.ItemPaged[Dict[str, object]]
601616
"""Query for digital twins.
617+
Note: that there may be a delay between before changes in your instance are reflected in queries.
618+
For more details on query limitations, see
619+
https://docs.microsoft.com/en-us/azure/digital-twins/how-to-query-graph#query-limitations
602620
603621
:param str query_expression: The query expression to execute.
604622
:return: The QueryResult object.

sdk/digitaltwins/azure-digitaltwins-core/azure/digitaltwins/core/_generated/aio/operations_async/_digital_twins_operations_async.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ async def add(
121121
self,
122122
id: str,
123123
twin: object,
124-
if_none_match: Optional[str] = "*",
125124
digital_twins_add_options: Optional["models.DigitalTwinsAddOptions"] = None,
126125
**kwargs
127126
) -> Optional[object]:
@@ -145,8 +144,6 @@ async def add(
145144
:type id: str
146145
:param twin: The digital twin instance being added. If provided, the $dtId property is ignored.
147146
:type twin: object
148-
:param if_none_match: Only perform the operation if the entity does not already exist.
149-
:type if_none_match: str
150147
:param digital_twins_add_options: Parameter group.
151148
:type digital_twins_add_options: ~azure.digitaltwins.core.models.DigitalTwinsAddOptions
152149
:keyword callable cls: A custom type or function that will be passed the direct response
@@ -160,9 +157,11 @@ async def add(
160157

161158
_traceparent = None
162159
_tracestate = None
160+
_if_none_match = None
163161
if digital_twins_add_options is not None:
164162
_traceparent = digital_twins_add_options.traceparent
165163
_tracestate = digital_twins_add_options.tracestate
164+
_if_none_match = digital_twins_add_options.if_none_match
166165
api_version = "2020-10-31"
167166
content_type = kwargs.pop("content_type", "application/json")
168167

@@ -183,8 +182,8 @@ async def add(
183182
header_parameters['traceparent'] = self._serialize.header("traceparent", _traceparent, 'str')
184183
if _tracestate is not None:
185184
header_parameters['tracestate'] = self._serialize.header("tracestate", _tracestate, 'str')
186-
if if_none_match is not None:
187-
header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
185+
if _if_none_match is not None:
186+
header_parameters['If-None-Match'] = self._serialize.header("if_none_match", _if_none_match, 'str')
188187
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
189188
header_parameters['Accept'] = 'application/json'
190189

@@ -477,7 +476,6 @@ async def add_relationship(
477476
id: str,
478477
relationship_id: str,
479478
relationship: object,
480-
if_none_match: Optional[str] = "*",
481479
digital_twins_add_relationship_options: Optional["models.DigitalTwinsAddRelationshipOptions"] = None,
482480
**kwargs
483481
) -> object:
@@ -509,8 +507,6 @@ async def add_relationship(
509507
:type relationship_id: str
510508
:param relationship: The data for the relationship.
511509
:type relationship: object
512-
:param if_none_match: Only perform the operation if the entity does not already exist.
513-
:type if_none_match: str
514510
:param digital_twins_add_relationship_options: Parameter group.
515511
:type digital_twins_add_relationship_options: ~azure.digitaltwins.core.models.DigitalTwinsAddRelationshipOptions
516512
:keyword callable cls: A custom type or function that will be passed the direct response
@@ -524,9 +520,11 @@ async def add_relationship(
524520

525521
_traceparent = None
526522
_tracestate = None
523+
_if_none_match = None
527524
if digital_twins_add_relationship_options is not None:
528525
_traceparent = digital_twins_add_relationship_options.traceparent
529526
_tracestate = digital_twins_add_relationship_options.tracestate
527+
_if_none_match = digital_twins_add_relationship_options.if_none_match
530528
api_version = "2020-10-31"
531529
content_type = kwargs.pop("content_type", "application/json")
532530

@@ -548,8 +546,8 @@ async def add_relationship(
548546
header_parameters['traceparent'] = self._serialize.header("traceparent", _traceparent, 'str')
549547
if _tracestate is not None:
550548
header_parameters['tracestate'] = self._serialize.header("tracestate", _tracestate, 'str')
551-
if if_none_match is not None:
552-
header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
549+
if _if_none_match is not None:
550+
header_parameters['If-None-Match'] = self._serialize.header("if_none_match", _if_none_match, 'str')
553551
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
554552
header_parameters['Accept'] = 'application/json'
555553

0 commit comments

Comments
 (0)