Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
5 changes: 2 additions & 3 deletions src/Azure/Azure.Quantum.Client.Test/WorkspaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.Azure.Quantum.Client;
using Microsoft.Azure.Quantum.Client.Models;
using Microsoft.Azure.Quantum.Exceptions;
using Microsoft.Rest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

Expand Down Expand Up @@ -184,13 +183,13 @@ private static IWorkspace GetWorkspace()
workspaceName: TestConstants.WorkspaceName)
{
// Mock jobs client (only needed for unit tests)
JobsClient = new QuantumClient(MockHelper.GetHttpClientMock(), true)
QuantumClient = new QuantumClient(MockHelper.GetHttpClientMock(), true)
{
SubscriptionId = TestConstants.SubscriptionId,
ResourceGroupName = TestConstants.ResourceGroupName,
WorkspaceName = TestConstants.WorkspaceName,
BaseUri = new Uri(TestConstants.Endpoint),
}.Jobs,
},
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Microsoft.Azure.Quantum.Exceptions
{
using System;

/// <summary>
/// The exception that is thrown when an error related to the Azure storage client occurs.
/// </summary>
Expand Down Expand Up @@ -46,19 +46,16 @@ public StorageClientException(
/// Initializes a new instance of the <see cref="StorageClientException"/> class with a specified error message, a reference to another exception that caused this one and more detailes that are specific to the storage client.
/// </summary>
/// <param name="message">Error message that explains the reason for the exception.</param>
/// <param name="connectionString">Connection string used by the storage client.</param>
/// <param name="containerName">Name of the container involved in the operation that caused the exception.</param>
/// <param name="blobName">Name of the BLOB involved in the operation that caused the exception.</param>
/// <param name="inner">Exception that is the cause of the current one.</param>
public StorageClientException(
string message,
string connectionString,
string containerName,
string blobName,
Exception inner)
: base(
$"{BaseMessage}: {message}{Environment.NewLine}" +
$"ConnectionString: {connectionString}{Environment.NewLine}" +
$"ContainerName: {containerName}{Environment.NewLine}" +
$"BlobName: {blobName}",
inner)
Expand Down
14 changes: 7 additions & 7 deletions src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Quantum.Client.Models;
using Microsoft.Azure.Quantum.Utility;
using Microsoft.Quantum.Runtime;

namespace Microsoft.Azure.Quantum
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Quantum.Client.Models;
using Microsoft.Azure.Quantum.Utility;
using Microsoft.Quantum.Runtime;

/// <summary>
/// Cloud job class.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Azure/Azure.Quantum.Client/JobManagement/IWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,17 @@ Task<CloudJob> GetJobAsync(
/// <returns>List of jobs</returns>
Task<IEnumerable<CloudJob>> ListJobsAsync(
CancellationToken cancellationToken = default);

/// <summary>
/// Gets as SAS Uri for the storage account associated with the workspace.
/// </summary>
/// <param name="containerName">Name of the container.</param>
/// <param name="blobName">Name of the BLOB.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Sas Uri.</returns>
Task<string> GetSasUriAsync(
string containerName,
string blobName = null,
CancellationToken cancellationToken = default);
}
}
85 changes: 53 additions & 32 deletions src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Microsoft.Azure.Quantum.Authentication;
using Microsoft.Azure.Quantum.Client;
using Microsoft.Azure.Quantum.Client.Models;
using Microsoft.Azure.Quantum.Exceptions;
using Microsoft.Azure.Quantum.Utility;

namespace Microsoft.Azure.Quantum
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using global::Azure.Core;
using Microsoft.Azure.Quantum.Authentication;
using Microsoft.Azure.Quantum.Client;
using Microsoft.Azure.Quantum.Client.Models;
using Microsoft.Azure.Quantum.Exceptions;
using Microsoft.Azure.Quantum.Utility;

/// <summary>
/// Workspace class.
/// </summary>
/// <seealso cref="Microsoft.Azure.Quantum.Client.IWorkspace" />
public class Workspace : IWorkspace
{
private readonly Uri BaseUri;
private readonly string ResourceGroupName;
private readonly string SubscriptionId;
private readonly string WorkspaceName;
private readonly Uri baseUri;
private readonly string resourceGroupName;
private readonly string subscriptionId;
private readonly string workspaceName;

/// <summary>
/// Initializes a new instance of the <see cref="Workspace"/> class.
Expand Down Expand Up @@ -79,13 +79,13 @@ private Workspace(
IAccessTokenProvider accessTokenProvider,
Uri baseUri = null)
{
BaseUri = baseUri ?? new Uri(Constants.DefaultBaseUri);
this.baseUri = baseUri ?? new Uri(Constants.DefaultBaseUri);
Ensure.NotNullOrWhiteSpace(subscriptionId, nameof(subscriptionId));
SubscriptionId = subscriptionId;
this.subscriptionId = subscriptionId;
Ensure.NotNullOrWhiteSpace(resourceGroupName, nameof(resourceGroupName));
ResourceGroupName = resourceGroupName;
this.resourceGroupName = resourceGroupName;
Ensure.NotNullOrWhiteSpace(workspaceName, nameof(workspaceName));
WorkspaceName = workspaceName;
this.workspaceName = workspaceName;

try
{
Expand All @@ -100,13 +100,13 @@ private Workspace(

try
{
this.JobsClient = new QuantumClient(new AuthorizationClientHandler(accessTokenProvider))
this.QuantumClient = new QuantumClient(new AuthorizationClientHandler(accessTokenProvider))
{
BaseUri = BaseUri,
BaseUri = this.baseUri,
SubscriptionId = subscriptionId,
ResourceGroupName = resourceGroupName,
WorkspaceName = workspaceName,
}.Jobs;
};
}
catch (Exception ex)
{
Expand All @@ -121,7 +121,7 @@ private Workspace(
/// <value>
/// The jobs client.
/// </value>
internal IJobsOperations JobsClient { get; set; }
internal IQuantumClient QuantumClient { get; set; }

/// <summary>
/// Submits the job.
Expand All @@ -140,7 +140,7 @@ public async Task<CloudJob> SubmitJobAsync(

try
{
JobDetails jobDetails = await this.JobsClient.PutAsync(
JobDetails jobDetails = await this.QuantumClient.Jobs.PutAsync(
jobId: jobDefinition.Details.Id,
jobDefinition: jobDefinition.Details,
cancellationToken: cancellationToken);
Expand All @@ -165,7 +165,7 @@ public async Task<CloudJob> CancelJobAsync(string jobId, CancellationToken cance

try
{
JobDetails jobDetails = await this.JobsClient.DeleteAsync(
JobDetails jobDetails = await this.QuantumClient.Jobs.DeleteAsync(
jobId: jobId,
cancellationToken: cancellationToken);

Expand All @@ -191,7 +191,7 @@ public async Task<CloudJob> GetJobAsync(string jobId, CancellationToken cancella

try
{
JobDetails jobDetails = await this.JobsClient.GetAsync(
JobDetails jobDetails = await this.QuantumClient.Jobs.GetAsync(
jobId: jobId,
cancellationToken: cancellationToken);

Expand All @@ -214,7 +214,7 @@ public async Task<IEnumerable<CloudJob>> ListJobsAsync(CancellationToken cancell
{
try
{
var jobs = await this.JobsClient.ListAsync(
var jobs = await this.QuantumClient.Jobs.ListAsync(
cancellationToken: cancellationToken);

return jobs
Expand All @@ -226,17 +226,38 @@ public async Task<IEnumerable<CloudJob>> ListJobsAsync(CancellationToken cancell
}
}

/// <summary>
/// Gets as SAS Uri for the linked storage account.
/// </summary>
/// <param name="containerName">Name of the container.</param>
/// <param name="blobName">Name of the BLOB.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// Sas Uri.
/// </returns>
public async Task<string> GetSasUriAsync(string containerName, string blobName = null, CancellationToken cancellationToken = default)
{
BlobDetails details = new BlobDetails
{
ContainerName = containerName,
BlobName = blobName,
};

var response = await this.QuantumClient.Storage.SasUriAsync(details, cancellationToken);
return response.SasUri;
}

private WorkspaceClientException CreateException(
Exception inner,
string message,
string jobId = "")
{
return new WorkspaceClientException(
message,
SubscriptionId,
ResourceGroupName,
WorkspaceName,
BaseUri,
subscriptionId,
resourceGroupName,
workspaceName,
baseUri,
jobId,
inner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ targetName is null
: (IQuantumMachine)Activator.CreateInstance(
machineType,
targetName,
storageAccountConnectionString,
workspace);
workspace,
storageAccountConnectionString);
}
}
}
27 changes: 16 additions & 11 deletions src/Azure/Azure.Quantum.Client/Storage/IStorageHelper.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Bond;
using Microsoft.WindowsAzure.Storage.Blob;

namespace Microsoft.Azure.Quantum.Storage
{
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Bond;
using global::Azure.Storage.Blobs;
using Microsoft.WindowsAzure.Storage.Blob;

public interface IStorageHelper
{
/// <summary>
/// Downloads the BLOB.
/// </summary>
/// <param name="containerName">Name of the container.</param>
/// <param name="containerClient">Container client.</param>
/// <param name="blobName">Name of the BLOB.</param>
/// <param name="destination">The destination.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Serialization protocol of the downloaded BLOB.</returns>
Task<ProtocolType> DownloadBlobAsync(
string containerName,
BlobContainerClient containerClient,
string blobName,
Stream destination,
CancellationToken cancellationToken = default);

/// <summary>
/// Uploads the BLOB.
/// </summary>
/// <param name="containerName">Name of the container.</param>
/// <param name="containerClient">Container client.</param>
/// <param name="blobName">Name of the BLOB.</param>
/// <param name="input">The input.</param>
/// <param name="protocol">Serialization protocol of the BLOB to upload.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>async task.</returns>
Task UploadBlobAsync(
string containerName,
BlobContainerClient containerClient,
string blobName,
Stream input,
ProtocolType protocol = ProtocolType.COMPACT_PROTOCOL,
Expand All @@ -45,12 +46,14 @@ Task UploadBlobAsync(
/// <summary>
/// Gets the BLOB sas URI.
/// </summary>
/// <param name="connectionString">Storage account connection string.</param>
/// <param name="containerName">Name of the container.</param>
/// <param name="blobName">Name of the BLOB.</param>
/// <param name="expiryInterval">The expiry interval.</param>
/// <param name="permissions">The permissions.</param>
/// <returns>Blob uri.</returns>
string GetBlobSasUri(
string connectionString,
string containerName,
string blobName,
TimeSpan expiryInterval,
Expand All @@ -59,11 +62,13 @@ string GetBlobSasUri(
/// <summary>
/// Gets the BLOB container sas URI.
/// </summary>
/// <param name="connectionString">Storage account connection string.</param>
/// <param name="containerName">Name of the container.</param>
/// <param name="expiryInterval">The expiry interval.</param>
/// <param name="permissions">The permissions.</param>
/// <returns>Container uri.</returns>
string GetBlobContainerSasUri(
string connectionString,
string containerName,
TimeSpan expiryInterval,
SharedAccessBlobPermissions permissions);
Expand Down
Loading