forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iot-hub): Add jobs API and tests (Azure#14358)
- Loading branch information
Showing
66 changed files
with
2,916 additions
and
1,921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
sdk/iot/Azure.Iot.Hub.Service/src/Customized/JobsRestClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
|
||
namespace Azure.Iot.Hub.Service | ||
{ | ||
internal partial class JobsRestClient | ||
{ | ||
internal Response<string> CancelImportExportJob(string id, CancellationToken cancellationToken = default) | ||
{ | ||
if (id == null) | ||
{ | ||
throw new ArgumentNullException(nameof(id)); | ||
} | ||
|
||
using var message = CreateCancelImportExportJobRequest(id); | ||
_pipeline.Send(message, cancellationToken); | ||
switch (message.Response.Status) | ||
{ | ||
case 200: | ||
{ | ||
string value = default; | ||
using var document = JsonDocument.Parse(message.Response.ContentStream); | ||
if (document.RootElement.ValueKind == JsonValueKind.Null) | ||
{ | ||
value = null; | ||
} | ||
else | ||
{ | ||
value = document.RootElement.GetRawText(); | ||
} | ||
return Response.FromValue(value, message.Response); | ||
} | ||
case 204: | ||
return Response.FromValue<string>(null, message.Response); | ||
|
||
default: | ||
throw _clientDiagnostics.CreateRequestFailedException(message.Response); | ||
} | ||
} | ||
|
||
internal async Task<Response<string>> CancelImportExportJobAsync(string id, CancellationToken cancellationToken = default) | ||
{ | ||
if (id == null) | ||
{ | ||
throw new ArgumentNullException(nameof(id)); | ||
} | ||
|
||
using var message = CreateCancelImportExportJobRequest(id); | ||
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); | ||
switch (message.Response.Status) | ||
{ | ||
case 200: | ||
{ | ||
string value = default; | ||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); | ||
if (document.RootElement.ValueKind == JsonValueKind.Null) | ||
{ | ||
value = null; | ||
} | ||
else | ||
{ | ||
value = document.RootElement.GetRawText(); | ||
} | ||
return Response.FromValue(value, message.Response); | ||
} | ||
case 204: | ||
return Response.FromValue<string>(null, message.Response); | ||
|
||
default: | ||
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
internal HttpMessage CreateCancelImportExportJobRequest(string id) | ||
{ | ||
var message = _pipeline.CreateMessage(); | ||
var request = message.Request; | ||
request.Method = RequestMethod.Delete; | ||
var uri = new RawRequestUriBuilder(); | ||
uri.Reset(endpoint); | ||
uri.AppendPath("/jobs/", false); | ||
uri.AppendPath(id, true); | ||
uri.AppendQuery("api-version", apiVersion, true); | ||
request.Uri = uri; | ||
return message; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
sdk/iot/Azure.Iot.Hub.Service/src/Customized/Models/ExportJobRequestOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Iot.Hub.Service.Models | ||
{ | ||
/// <summary> | ||
/// Optional properties for export jobs. | ||
/// </summary> | ||
public class ExportJobRequestOptions : JobRequestOptions | ||
{ | ||
/// <summary> | ||
/// The name of the blob that contains the export devices registry information for the IoT Hub. If not provided by the user, it will default to "devices.txt". | ||
/// </summary> | ||
public string OutputBlobName { get; set; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
sdk/iot/Azure.Iot.Hub.Service/src/Customized/Models/ImportJobRequestOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Iot.Hub.Service.Models | ||
{ | ||
/// <summary> | ||
/// Optional properties for import jobs. | ||
/// </summary> | ||
public class ImportJobRequestOptions : JobRequestOptions | ||
{ | ||
/// <summary> | ||
/// The name of the blob that will contain the status of importing devices. If not provided by the user, it will default to "devices.txt". | ||
/// </summary> | ||
public string InputBlobName { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the blob that contains the export devices registry information for the IoT Hub. If not provided by the user, it will default to "devices.txt". | ||
/// </summary> | ||
public string OutputBlobName { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
sdk/iot/Azure.Iot.Hub.Service/src/Customized/Models/JobRequestOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Iot.Hub.Service.Models | ||
{ | ||
/// <summary> | ||
/// Optional properties for import and export jobs. | ||
/// </summary> | ||
public class JobRequestOptions | ||
{ | ||
/// <summary> | ||
/// Specifies authentication type being used for connecting to storage account. If not provided by the user, it will default to KeyBased type. | ||
/// </summary> | ||
public JobPropertiesStorageAuthenticationType AuthenticationType { get; set; } | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
sdk/iot/Azure.Iot.Hub.Service/src/Generated/JobsRestClient.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.