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

feat(iot-hub): Add jobs API and tests #14358

Merged
merged 3 commits into from
Aug 19, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ public enum ServiceVersion
}
public partial class JobsClient
{
public JobsClient() { }
protected JobsClient() { }
public virtual Azure.Response<string> CancelImportExportJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<string>> CancelImportExportJobAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Iot.Hub.Service.Models.JobProperties> CreateExportDevicesJob(System.Uri outputBlobContainerUri, bool excludeKeys, Azure.Iot.Hub.Service.Models.ExportJobRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Iot.Hub.Service.Models.JobProperties>> CreateExportDevicesJobAsync(System.Uri outputBlobContainerUri, bool excludeKeys, Azure.Iot.Hub.Service.Models.ExportJobRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Iot.Hub.Service.Models.JobProperties> CreateImportDevicesJob(System.Uri importBlobContainerUri, System.Uri outputBlobContainerUri, Azure.Iot.Hub.Service.Models.ImportJobRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Iot.Hub.Service.Models.JobProperties>> CreateImportDevicesJobAsync(System.Uri importBlobContainerUri, System.Uri outputBlobContainerUri, Azure.Iot.Hub.Service.Models.ImportJobRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Iot.Hub.Service.Models.JobProperties> GetImportExportJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Iot.Hub.Service.Models.JobProperties>> GetImportExportJobAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Iot.Hub.Service.Models.JobProperties>> GetImportExportJobs(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Iot.Hub.Service.Models.JobProperties>>> GetImportExportJobsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class ModulesClient
{
Expand Down Expand Up @@ -602,6 +612,17 @@ public ExportImportDevice() { }
public static bool operator !=(Azure.Iot.Hub.Service.Models.ExportImportDeviceStatus left, Azure.Iot.Hub.Service.Models.ExportImportDeviceStatus right) { throw null; }
public override string ToString() { throw null; }
}
public partial class ExportJobRequestOptions : Azure.Iot.Hub.Service.Models.JobRequestOptions
{
public ExportJobRequestOptions() { }
public string OutputBlobName { get { throw null; } set { } }
}
public partial class ImportJobRequestOptions : Azure.Iot.Hub.Service.Models.JobRequestOptions
{
public ImportJobRequestOptions() { }
public string InputBlobName { get { throw null; } set { } }
public string OutputBlobName { get { throw null; } set { } }
}
public partial class JobProperties
{
public JobProperties() { }
Expand Down Expand Up @@ -704,6 +725,11 @@ public JobRequest() { }
public Azure.Iot.Hub.Service.Models.JobRequestType? Type { get { throw null; } set { } }
public Azure.Iot.Hub.Service.Models.TwinData UpdateTwin { get { throw null; } set { } }
}
public partial class JobRequestOptions
{
public JobRequestOptions() { }
public Azure.Iot.Hub.Service.Models.JobPropertiesStorageAuthenticationType AuthenticationType { get { throw null; } set { } }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct JobRequestType : System.IEquatable<Azure.Iot.Hub.Service.Models.JobRequestType>
{
Expand Down
94 changes: 94 additions & 0 deletions sdk/iot/Azure.Iot.Hub.Service/src/Customized/JobsRestClient.cs
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)
vinagesh marked this conversation as resolved.
Show resolved Hide resolved
{
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;
}
}
}
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; }
}
}
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; }
}
}
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 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.

4 changes: 3 additions & 1 deletion sdk/iot/Azure.Iot.Hub.Service/src/IotHubServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class IotHubServiceClient
private readonly QueryRestClient _queryRestClient;
private readonly StatisticsRestClient _statisticsRestClient;
private readonly ConfigurationRestClient _configurationRestClient;
private readonly JobsRestClient _jobsRestClient;

/// <summary>
/// place holder for Devices.
Expand Down Expand Up @@ -143,6 +144,7 @@ private IotHubServiceClient(IotHubSasCredential credential, IotHubServiceClientO
_queryRestClient = new QueryRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
_statisticsRestClient = new StatisticsRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
_configurationRestClient = new ConfigurationRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());
_jobsRestClient = new JobsRestClient(_clientDiagnostics, _httpPipeline, credential.Endpoint, options.GetVersionString());

// Note that the devices and modules subclient take a reference to the Query convenience layer client. This
// is because they each expose a helper function that uses the query client for listing twins. By passing in
Expand All @@ -156,7 +158,7 @@ private IotHubServiceClient(IotHubSasCredential credential, IotHubServiceClientO

Messages = new CloudToDeviceMessagesClient();
Files = new FilesClient();
Jobs = new JobsClient();
Jobs = new JobsClient(_jobsRestClient);
}

private static IotHubSasCredential SetEndpointToIotHubSasCredential(Uri endpoint, IotHubSasCredential credential)
Expand Down
Loading