Skip to content

Commit

Permalink
Add model for import job errors (#3124)
Browse files Browse the repository at this point in the history
  • Loading branch information
David R. Williamson authored Feb 22, 2023
1 parent 2baa8e0 commit 27dd935
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
1 change: 1 addition & 0 deletions SDK v2 migration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ What was a loose affiliation of separate clients is now a consolidated client wi

- `JobProperties` now has a helper property `IsFinished` which returns true if the job status is in a terminal state.
- `TryGetValue<T>(...)` is available off of the desired and reported properties on `TwinProperties`.
- Added type `ImportJobError` to deserialize the error details of an import job.

#### API mapping

Expand Down
4 changes: 2 additions & 2 deletions e2e/test/iothub/device/MessageReceiveFaultInjectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ await ReceiveMessageWithCallbackRecoveryAsync(

[TestMethod]
[Timeout(TestTimeoutMilliseconds)]
public async Task Message_AmqpC2DLinkDropReceiveWithCallbackRecovery_Amqp()
public async Task Message_AmqpC2dLinkDropReceiveWithCallbackRecovery_Amqp()
{
await ReceiveMessageWithCallbackRecoveryAsync(
new IotHubClientAmqpSettings(),
Expand All @@ -147,7 +147,7 @@ await ReceiveMessageWithCallbackRecoveryAsync(

[TestMethod]
[Timeout(TestTimeoutMilliseconds)]
public async Task Message_AmqpC2DLinkDropReceiveWithCallbackRecovery_AmqpWs()
public async Task Message_AmqpC2dLinkDropReceiveWithCallbackRecovery_AmqpWs()
{
await ReceiveMessageWithCallbackRecoveryAsync(
new IotHubClientAmqpSettings(IotHubClientTransportProtocol.WebSocket),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
Expand All @@ -22,8 +21,6 @@ namespace Microsoft.Azure.Devices.Samples
/// </summary>
public class CleanupDevicesSample
{
private const string ImportErrorsLog = "importErrors.log";

private static readonly string s_importExportDevicesFileName = $"delete-devices-{Guid.NewGuid()}.txt";
private static readonly TimeSpan s_waitDuration = TimeSpan.FromSeconds(30);
private static readonly TimeSpan s_maxJobDuration = TimeSpan.FromHours(4);
Expand Down Expand Up @@ -139,7 +136,7 @@ private async Task DiscoverAndReportErrorsAsync()
Console.WriteLine("Looking for any errors reported from import...");
try
{
BlobClient importErrorsBlobClient = _blobContainerClient.GetBlobClient(ImportErrorsLog);
BlobClient importErrorsBlobClient = _blobContainerClient.GetBlobClient(ImportJobError.ImportErrorsBlobName);

var content = await importErrorsBlobClient.DownloadContentAsync();
string errorContent = content.Value.Content.ToString();
Expand All @@ -150,7 +147,7 @@ private async Task DiscoverAndReportErrorsAsync()
{
try
{
ImportError importError = JsonConvert.DeserializeObject<ImportError>(error);
ImportJobError importError = JsonConvert.DeserializeObject<ImportJobError>(error);
Console.WriteLine($"\tImport error for {importError.DeviceId} of code {importError.ErrorCode} with status: '{importError.ErrorStatus}'.");
}
catch (Exception ex)
Expand Down

This file was deleted.

40 changes: 40 additions & 0 deletions iothub/service/src/Registry/Models/ImportJobError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Newtonsoft.Json;

namespace Microsoft.Azure.Devices
{
/// <summary>
/// Useful for deserializing errors that occur from a bulk import job.
/// </summary>
/// <remarks>
/// Any errors that occur during a bulk import job can be deserialized with this class from a blob file named "importErrors.log"
/// in the container specified during import.
/// </remarks>
public class ImportJobError
{
/// <summary>
/// The name of the blob file that contains the import errors.
/// </summary>
public const string ImportErrorsBlobName = "importErrors.log";

/// <summary>
/// The Id of the device for the error.
/// </summary>
[JsonProperty("deviceId")]
public string DeviceId { get; set; }

/// <summary>
/// An error code for the device import.
/// </summary>
[JsonProperty("errorCode")]
public string ErrorCode { get; set; }

/// <summary>
/// A textual reason for the error.
/// </summary>
[JsonProperty("errorStatus")]
public string ErrorStatus { get; set; }
}
}

0 comments on commit 27dd935

Please sign in to comment.