Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model for import job errors #3124

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
}