Skip to content

Commit 91aa7e3

Browse files
authored
feat(tsi): Model Settings Implementation (Azure#18705)
1 parent 6daa0a4 commit 91aa7e3

File tree

8 files changed

+148
-46
lines changed

8 files changed

+148
-46
lines changed

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/api/Azure.Iot.TimeSeriesInsights.netstandard2.0.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public partial class TimeSeriesInsightsClient
2323
protected TimeSeriesInsightsClient() { }
2424
public TimeSeriesInsightsClient(string environmentFqdn, Azure.Core.TokenCredential credential) { }
2525
public TimeSeriesInsightsClient(string environmentFqdn, Azure.Core.TokenCredential credential, Azure.Iot.TimeSeriesInsights.TimeSeriesInsightsClientOptions options) { }
26-
public virtual Azure.Response<Azure.Iot.TimeSeriesInsights.Models.ModelSettingsResponse> Get(string clientSessionId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
27-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Iot.TimeSeriesInsights.Models.ModelSettingsResponse>> GetAsync(string clientSessionId = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
26+
public virtual Azure.Response<Azure.Iot.TimeSeriesInsights.Models.TimeSeriesModelSettings> GetModelSettings(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
27+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Iot.TimeSeriesInsights.Models.TimeSeriesModelSettings>> GetModelSettingsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
28+
public virtual Azure.Response<Azure.Iot.TimeSeriesInsights.Models.TimeSeriesModelSettings> UpdateModelSettings(Azure.Iot.TimeSeriesInsights.UpdateModelSettingsOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Iot.TimeSeriesInsights.Models.TimeSeriesModelSettings>> UpdateModelSettingsAsync(Azure.Iot.TimeSeriesInsights.UpdateModelSettingsOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2830
}
2931
public partial class TimeSeriesInsightsClientOptions : Azure.Core.ClientOptions
3032
{
@@ -40,6 +42,12 @@ public partial class TimeSeriesVariable
4042
public TimeSeriesVariable() { }
4143
public Azure.Iot.TimeSeriesInsights.TimeSeriesExpression Filter { get { throw null; } set { } }
4244
}
45+
public partial class UpdateModelSettingsOptions
46+
{
47+
public UpdateModelSettingsOptions() { }
48+
public string DefaultTypeId { get { throw null; } set { } }
49+
public string Name { get { throw null; } set { } }
50+
}
4351
}
4452
namespace Azure.Iot.TimeSeriesInsights.Models
4553
{
@@ -547,10 +555,4 @@ public TypesRequestBatchGetOrDelete() { }
547555
public System.Collections.Generic.IList<string> Names { get { throw null; } }
548556
public System.Collections.Generic.IList<string> TypeIds { get { throw null; } }
549557
}
550-
public partial class UpdateModelSettingsRequest
551-
{
552-
public UpdateModelSettingsRequest() { }
553-
public string DefaultTypeId { get { throw null; } set { } }
554-
public string Name { get { throw null; } set { } }
555-
}
556558
}

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/samples/TimeSeriesInsightsClientSample/TimeSeriesInsightsLifecycleSamples.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Threading.Tasks;
6+
using Azure.Iot.TimeSeriesInsights.Models;
67
using static Azure.Iot.TimeSeriesInsights.Samples.SampleLogger;
78

89
namespace Azure.Iot.TimeSeriesInsights.Samples
@@ -26,12 +27,30 @@ public async Task RunSamplesAsync()
2627
try
2728
{
2829
#region Snippet:TimeSeriesInsightsGetModelSettings
29-
30+
3031
// Get the model settings for the time series insights environment
31-
Response<Models.ModelSettingsResponse> response = await client.GetAsync().ConfigureAwait(false);
32-
Console.WriteLine($"Retrieved model {response.Value.ModelSettings.Name}.");
33-
32+
Response<TimeSeriesModelSettings> currentSettings = await client.GetModelSettingsAsync();
33+
Console.WriteLine($"Retrieved model with default type id {currentSettings.Value.DefaultTypeId} " +
34+
$"model name {currentSettings.Value.Name}.");
35+
36+
foreach (TimeSeriesIdProperty tsiId in currentSettings.Value.TimeSeriesIdProperties)
37+
{
38+
Console.WriteLine($"Time series Id name: '{tsiId.Name}', Type: '{tsiId.Type}'.");
39+
}
40+
3441
#endregion Snippet:TimeSeriesInsightsGetModelSettings
42+
43+
#region Snippet:TimeSeriesInsightsUpdateModelSettings
44+
45+
var options = new UpdateModelSettingsOptions
46+
{
47+
Name = "sampleModel"
48+
};
49+
Response<TimeSeriesModelSettings> updatedSettings = await client.UpdateModelSettingsAsync(options);
50+
Console.WriteLine($"Updated model name to {updatedSettings.Value.Name} ");
51+
52+
#endregion Snippet:TimeSeriesInsightsUpdateModelSettings
53+
3554
}
3655
catch (Exception ex)
3756
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Iot.TimeSeriesInsights
7+
{
8+
/// <summary>
9+
/// Options to update model settings. One of &quot;name&quot; or &quot;defaultTypeId&quot; must be set.
10+
/// </summary>
11+
[CodeGenModel("UpdateModelSettingsRequest")]
12+
public partial class UpdateModelSettingsOptions
13+
{
14+
// This class declaration changes the namespace, class name and visibility; do not remove.
15+
}
16+
}

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/src/Generated/ModelSettingsRestClient.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/src/Generated/Models/UpdateModelSettingsRequest.Serialization.cs renamed to sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/src/Generated/Models/UpdateModelSettingsOptions.Serialization.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/src/Generated/Models/UpdateModelSettingsRequest.cs renamed to sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/src/Generated/Models/UpdateModelSettingsOptions.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/src/TimeSeriesInsightsClient.cs

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Azure.Core;
@@ -94,40 +95,103 @@ protected TimeSeriesInsightsClient()
9495
}
9596

9697
/// <summary>
97-
/// Returns the model settings which includes model display name, Time Series ID properties and default type ID. Every Gen2 environment has a model that is automatically created.
98+
/// Gets the scope for authentication/authorization policy.
9899
/// </summary>
99-
/// <param name="clientSessionId"> Optional client session ID. Service records this value. Allows the service to trace a group of related operations across services, and allows the customer to contact support regarding a particular group of requests. </param>
100-
/// <param name="cancellationToken"> The cancellation token to use. </param>
101-
/// <returns>The deserialized application/json model settings digital twin and the http response <see cref="Response{ModelSettingsResponse}"/>.</returns>
102-
/// <example>
103-
/// This sample demonstrates getting and deserializing a model settings.
104-
///
105-
/// <code snippet="Snippet:TimeSeriesInsightsGetModelSettings">
106-
/// // Get the model settings for the time series insights environment
107-
/// Response&lt;Models.ModelSettingsResponse&gt; response = await client.GetAsync().ConfigureAwait(false);
108-
/// Console.WriteLine($&quot;Retrieved model {response.Value.ModelSettings.Name}.&quot;);
109-
/// </code>
110-
/// </example>
111-
public virtual Task<Response<ModelSettingsResponse>> GetAsync(string clientSessionId = null, CancellationToken cancellationToken = default)
100+
/// <returns>List of scopes for the specified endpoint.</returns>
101+
internal static string[] GetAuthorizationScopes() => s_tsiDefaultScopes;
102+
103+
/// <summary>
104+
/// Gets Time Series model settings asynchronously.
105+
/// </summary>
106+
/// <param name="cancellationToken">The cancellation token.</param>
107+
/// <returns>The model settings which includes model display name, Time Series Id properties and default type Id with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns>
108+
public virtual async Task<Response<TimeSeriesModelSettings>> GetModelSettingsAsync(CancellationToken cancellationToken = default)
112109
{
113-
return _modelSettingsRestClient.GetAsync(clientSessionId, cancellationToken);
110+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetModelSettings)}");
111+
scope.Start();
112+
try
113+
{
114+
// To do: Generate client session Id
115+
Response<ModelSettingsResponse> modelSettings = await _modelSettingsRestClient.GetAsync(null, cancellationToken).ConfigureAwait(false);
116+
return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse());
117+
}
118+
catch (Exception ex)
119+
{
120+
scope.Failed(ex);
121+
throw;
122+
}
114123
}
115124

116125
/// <summary>
117-
/// Returns the model settings which includes model display name, Time Series ID properties and default type ID. Every Gen2 environment has a model that is automatically created.
126+
/// Gets Time Series model settings synchronously.
118127
/// </summary>
119-
/// <param name="clientSessionId"> Optional client session ID. Service records this value. Allows the service to trace a group of related operations across services, and allows the customer to contact support regarding a particular group of requests. </param>
120-
/// <param name="cancellationToken"> The cancellation token to use. </param>
121-
/// <returns>The deserialized application/json model settings digital twin and the http response <see cref="Response{ModelSettingsResponse}"/>.</returns>
122-
public virtual Response<ModelSettingsResponse> Get(string clientSessionId = null, CancellationToken cancellationToken = default)
128+
/// <param name="cancellationToken">The cancellation token.</param>
129+
/// <returns>The model settings which includes model display name, Time Series Id properties and default type Id with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns>
130+
public virtual Response<TimeSeriesModelSettings> GetModelSettings(CancellationToken cancellationToken = default)
123131
{
124-
return _modelSettingsRestClient.Get(clientSessionId, cancellationToken);
132+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetModelSettings)}");
133+
scope.Start();
134+
try
135+
{
136+
// To do: Generate client session Id
137+
Response<ModelSettingsResponse> modelSettings = _modelSettingsRestClient.Get(null, cancellationToken);
138+
return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse());
139+
}
140+
catch (Exception ex)
141+
{
142+
scope.Failed(ex);
143+
throw;
144+
}
125145
}
126146

127147
/// <summary>
128-
/// Gets the scope for authentication/authorization policy.
148+
/// Updates model name or default type Id on Time Series model settings asynchronously.
129149
/// </summary>
130-
/// <returns>List of scopes for the specified endpoint.</returns>
131-
internal static string[] GetAuthorizationScopes() => s_tsiDefaultScopes;
150+
/// <param name="options">Model settings update request body.</param>
151+
/// <param name="cancellationToken">The cancellation token.</param>
152+
/// <returns>The updated model settings with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns>
153+
/// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception>
154+
public virtual async Task<Response<TimeSeriesModelSettings>> UpdateModelSettingsAsync(UpdateModelSettingsOptions options, CancellationToken cancellationToken = default)
155+
{
156+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(UpdateModelSettings)}");
157+
scope.Start();
158+
try
159+
{
160+
// To do: Generate client session Id
161+
Argument.AssertNotNull(options, nameof(options));
162+
Response<ModelSettingsResponse> modelSettings = await _modelSettingsRestClient.UpdateAsync(options, null, cancellationToken).ConfigureAwait(false);
163+
return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse());
164+
}
165+
catch (Exception ex)
166+
{
167+
scope.Failed(ex);
168+
throw;
169+
}
170+
}
171+
172+
/// <summary>
173+
/// Updates model name or default type Id on Time Series model settings synchronously.
174+
/// </summary>
175+
/// <param name="options">Model settings update request body.</param>
176+
/// <param name="cancellationToken">The cancellation token.</param>
177+
/// <returns>The updated model settings with the http response <see cref="Response{TimeSeriesModelSettings}"/>.</returns>
178+
/// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception>
179+
public virtual Response<TimeSeriesModelSettings> UpdateModelSettings(UpdateModelSettingsOptions options, CancellationToken cancellationToken = default)
180+
{
181+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(UpdateModelSettings)}");
182+
scope.Start();
183+
try
184+
{
185+
// To do: Generate client session Id
186+
Argument.AssertNotNull(options, nameof(options));
187+
Response<ModelSettingsResponse> modelSettings = _modelSettingsRestClient.Update(options, null, cancellationToken);
188+
return Response.FromValue(modelSettings.Value.ModelSettings, modelSettings.GetRawResponse());
189+
}
190+
catch (Exception ex)
191+
{
192+
scope.Failed(ex);
193+
throw;
194+
}
195+
}
132196
}
133197
}

sdk/timeseriesinsights/Azure.Iot.TimeSeriesInsights/tests/TimeSeriesInsightsClientTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System.Threading.Tasks;
5+
using Azure.Iot.TimeSeriesInsights.Models;
56
using FluentAssertions;
67
using NUnit.Framework;
78

@@ -18,7 +19,7 @@ public TimeSeriesInsightsClientTest(bool isAsync)
1819
public async Task TimeSeriesInsightsClient_Construct()
1920
{
2021
TimeSeriesInsightsClient client = GetClient();
21-
Response<Models.ModelSettingsResponse> response = await client.GetAsync().ConfigureAwait(false);
22+
Response<TimeSeriesModelSettings> response = await client.GetModelSettingsAsync().ConfigureAwait(false);
2223
response.GetRawResponse().Status.Should().Be(200);
2324
}
2425
}

0 commit comments

Comments
 (0)