diff --git a/sdk/api-learn/Azure.Learn.Computation/Azure.Learn.Computation.sln b/sdk/api-learn/Azure.Learn.Computation/Azure.Learn.Computation.sln new file mode 100644 index 0000000000000..18d932e377cab --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/Azure.Learn.Computation.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Learn.Computation", "src\Azure.Learn.Computation.csproj", "{E33D09D9-D809-472C-82E6-6A26BDB86FC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Learn.Computation.Tests", "tests\Azure.Learn.Computation.Tests.csproj", "{4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33D09D9-D809-472C-82E6-6A26BDB86FC2}.Release|Any CPU.Build.0 = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F476D56-DDE7-43D3-8CB4-BA1E77F5A300}.Release|Any CPU.Build.0 = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/api-learn/Azure.Learn.Computation/Directory.Build.props b/sdk/api-learn/Azure.Learn.Computation/Directory.Build.props new file mode 100644 index 0000000000000..1a9611bd49242 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Azure.Learn.Computation.csproj b/sdk/api-learn/Azure.Learn.Computation/src/Azure.Learn.Computation.csproj new file mode 100644 index 0000000000000..5773995607956 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Azure.Learn.Computation.csproj @@ -0,0 +1,31 @@ + + + API Design Learning Project + + 1.0.0-beta.1 + + $(RequiredTargetFrameworks) + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputationComputePiHeaders.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputationComputePiHeaders.cs new file mode 100644 index 0000000000000..31aa9443c360f --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputationComputePiHeaders.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Learn.Computation +{ + internal class ComputationComputePiHeaders + { + private readonly Response _response; + public ComputationComputePiHeaders(Response response) + { + _response = response; + } + /// This will point to an operation (/operations/{operationId}) that can be used to monitor the progress. + public string OperationLocation => _response.Headers.TryGetValue("Operation-Location", out string value) ? value : null; + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputationRestClient.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputationRestClient.cs new file mode 100644 index 0000000000000..5c879b09d0acf --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputationRestClient.cs @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.Learn.Computation +{ + internal partial class ComputationRestClient + { + private string nodeName; + private Uri endpoint; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of ComputationRestClient. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The String to use. + /// server parameter. + /// is null. + public ComputationRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string nodeName, Uri endpoint = null) + { + if (nodeName == null) + { + throw new ArgumentNullException(nameof(nodeName)); + } + endpoint ??= new Uri(""); + + this.nodeName = nodeName; + this.endpoint = endpoint; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateComputePiRequest(int? precision) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/ComputeNodes/", false); + uri.AppendPath(nodeName, true); + uri.AppendPath("/computePi", false); + if (precision != null) + { + uri.AppendQuery("precision", precision.Value, true); + } + request.Uri = uri; + return message; + } + + /// The Integer to use. + /// The cancellation token to use. + public async Task> ComputePiAsync(int? precision = null, CancellationToken cancellationToken = default) + { + using var message = CreateComputePiRequest(precision); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ComputationComputePiHeaders(message.Response); + switch (message.Response.Status) + { + case 202: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// The Integer to use. + /// The cancellation token to use. + public ResponseWithHeaders ComputePi(int? precision = null, CancellationToken cancellationToken = default) + { + using var message = CreateComputePiRequest(precision); + _pipeline.Send(message, cancellationToken); + var headers = new ComputationComputePiHeaders(message.Response); + switch (message.Response.Status) + { + case 202: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputeNodeAdministrationRestClient.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputeNodeAdministrationRestClient.cs new file mode 100644 index 0000000000000..ae99836835c04 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ComputeNodeAdministrationRestClient.cs @@ -0,0 +1,279 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Learn.Computation.Models; + +namespace Azure.Learn.Computation +{ + internal partial class ComputeNodeAdministrationRestClient + { + private string nodeName; + private Uri endpoint; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of ComputeNodeAdministrationRestClient. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The String to use. + /// server parameter. + /// is null. + public ComputeNodeAdministrationRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string nodeName, Uri endpoint = null) + { + if (nodeName == null) + { + throw new ArgumentNullException(nameof(nodeName)); + } + endpoint ??= new Uri(""); + + this.nodeName = nodeName; + this.endpoint = endpoint; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateListRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/ComputeNodes", false); + request.Uri = uri; + return message; + } + + /// The cancellation token to use. + public async Task> ListAsync(CancellationToken cancellationToken = default) + { + using var message = CreateListRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + PageOfComputeNodes value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = PageOfComputeNodes.DeserializePageOfComputeNodes(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// The cancellation token to use. + public Response List(CancellationToken cancellationToken = default) + { + using var message = CreateListRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + PageOfComputeNodes value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = PageOfComputeNodes.DeserializePageOfComputeNodes(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateCreateRequest(string ifMatch, ComputeNode computeNode) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/ComputeNodes/", false); + uri.AppendPath(nodeName, true); + request.Uri = uri; + if (ifMatch != null) + { + request.Headers.Add("if-match", ifMatch); + } + request.Headers.Add("Content-Type", "application/json"); + if (computeNode != null) + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(computeNode); + request.Content = content; + } + return message; + } + + /// The String to use. + /// The ComputeNode to use. + /// The cancellation token to use. + public async Task> CreateAsync(string ifMatch = null, ComputeNode computeNode = null, CancellationToken cancellationToken = default) + { + using var message = CreateCreateRequest(ifMatch, computeNode); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + case 201: + { + ComputeNode value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ComputeNode.DeserializeComputeNode(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// The String to use. + /// The ComputeNode to use. + /// The cancellation token to use. + public Response Create(string ifMatch = null, ComputeNode computeNode = null, CancellationToken cancellationToken = default) + { + using var message = CreateCreateRequest(ifMatch, computeNode); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + case 201: + { + ComputeNode value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ComputeNode.DeserializeComputeNode(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetRequest() + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/ComputeNodes/", false); + uri.AppendPath(nodeName, true); + request.Uri = uri; + return message; + } + + /// The cancellation token to use. + public async Task> GetAsync(CancellationToken cancellationToken = default) + { + using var message = CreateGetRequest(); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + ComputeNode value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ComputeNode.DeserializeComputeNode(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// The cancellation token to use. + public Response Get(CancellationToken cancellationToken = default) + { + using var message = CreateGetRequest(); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + ComputeNode value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ComputeNode.DeserializeComputeNode(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateListNextPageRequest(string nextLink) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendRawNextLink(nextLink, false); + request.Uri = uri; + return message; + } + + /// The URL to the next page of results. + /// The cancellation token to use. + /// is null. + public async Task> ListNextPageAsync(string nextLink, CancellationToken cancellationToken = default) + { + if (nextLink == null) + { + throw new ArgumentNullException(nameof(nextLink)); + } + + using var message = CreateListNextPageRequest(nextLink); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + PageOfComputeNodes value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = PageOfComputeNodes.DeserializePageOfComputeNodes(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// The URL to the next page of results. + /// The cancellation token to use. + /// is null. + public Response ListNextPage(string nextLink, CancellationToken cancellationToken = default) + { + if (nextLink == null) + { + throw new ArgumentNullException(nameof(nextLink)); + } + + using var message = CreateListNextPageRequest(nextLink); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + PageOfComputeNodes value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = PageOfComputeNodes.DeserializePageOfComputeNodes(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/ComputeNode.Serialization.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/ComputeNode.Serialization.cs new file mode 100644 index 0000000000000..d26bf8892c68e --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/ComputeNode.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Learn.Computation.Models +{ + public partial class ComputeNode : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("kind"); + writer.WriteStringValue(Kind); + writer.WriteEndObject(); + } + + internal static ComputeNode DeserializeComputeNode(JsonElement element) + { + if (element.TryGetProperty("kind", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "LinuxComputeNode": return LinuxComputeNode.DeserializeLinuxComputeNode(element); + case "WindowsComputeNode": return WindowsComputeNode.DeserializeWindowsComputeNode(element); + } + } + Optional eTag = default; + string name = default; + string kind = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("eTag")) + { + eTag = property.Value.GetString(); + continue; + } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("kind")) + { + kind = property.Value.GetString(); + continue; + } + } + return new ComputeNode(eTag.Value, name, kind); + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/ComputeNode.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/ComputeNode.cs new file mode 100644 index 0000000000000..26116f290f0bd --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/ComputeNode.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Learn.Computation.Models +{ + /// The ComputeNode. + public partial class ComputeNode + { + /// Initializes a new instance of ComputeNode. + /// The name of the compute node. + /// is null. + public ComputeNode(string name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + Name = name; + } + + /// Initializes a new instance of ComputeNode. + /// An HTTP ETag. + /// The name of the compute node. + /// . + internal ComputeNode(string eTag, string name, string kind) + { + ETag = eTag; + Name = name; + Kind = kind; + } + + /// An HTTP ETag. + public string ETag { get; } + /// The name of the compute node. + public string Name { get; } + internal string Kind { get; set; } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/LinuxComputeNode.Serialization.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/LinuxComputeNode.Serialization.cs new file mode 100644 index 0000000000000..cb0377a0cae7c --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/LinuxComputeNode.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Learn.Computation.Models +{ + public partial class LinuxComputeNode : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("sshPublicKey"); + writer.WriteStringValue(SshPublicKey); + writer.WritePropertyName("kind"); + writer.WriteStringValue(Kind); + writer.WriteEndObject(); + } + + internal static LinuxComputeNode DeserializeLinuxComputeNode(JsonElement element) + { + string sshPublicKey = default; + Optional eTag = default; + string name = default; + string kind = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("sshPublicKey")) + { + sshPublicKey = property.Value.GetString(); + continue; + } + if (property.NameEquals("eTag")) + { + eTag = property.Value.GetString(); + continue; + } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("kind")) + { + kind = property.Value.GetString(); + continue; + } + } + return new LinuxComputeNode(eTag.Value, name, kind, sshPublicKey); + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/LinuxComputeNode.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/LinuxComputeNode.cs new file mode 100644 index 0000000000000..5b59c1dfcd420 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/LinuxComputeNode.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Learn.Computation.Models +{ + /// The LinuxComputeNode. + public partial class LinuxComputeNode : ComputeNode + { + /// Initializes a new instance of LinuxComputeNode. + /// The name of the compute node. + /// The compute node's public key. + /// or is null. + public LinuxComputeNode(string name, string sshPublicKey) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (sshPublicKey == null) + { + throw new ArgumentNullException(nameof(sshPublicKey)); + } + + SshPublicKey = sshPublicKey; + Kind = "LinuxComputeNode"; + } + + /// Initializes a new instance of LinuxComputeNode. + /// An HTTP ETag. + /// The name of the compute node. + /// . + /// The compute node's public key. + internal LinuxComputeNode(string eTag, string name, string kind, string sshPublicKey) : base(eTag, name, kind) + { + SshPublicKey = sshPublicKey; + Kind = kind ?? "LinuxComputeNode"; + } + + /// The compute node's public key. + public string SshPublicKey { get; set; } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/Operation.Serialization.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/Operation.Serialization.cs new file mode 100644 index 0000000000000..9a8385cd6ea52 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/Operation.Serialization.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Learn.Computation.Models +{ + public partial class Operation + { + internal static Operation DeserializeOperation(JsonElement element) + { + Optional createdDateTime = default; + Optional percentComplete = default; + Optional status = default; + Optional value = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("createdDateTime")) + { + createdDateTime = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("percentComplete")) + { + percentComplete = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("status")) + { + status = new OperationStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("value")) + { + value = property.Value.GetSingle(); + continue; + } + } + return new Operation(Optional.ToNullable(createdDateTime), Optional.ToNullable(percentComplete), Optional.ToNullable(status), Optional.ToNullable(value)); + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/Operation.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/Operation.cs new file mode 100644 index 0000000000000..f9f7d5ed2648b --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/Operation.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Learn.Computation.Models +{ + /// The Operation. + public partial class Operation + { + /// Initializes a new instance of Operation. + internal Operation() + { + } + + /// Initializes a new instance of Operation. + /// Date and time (UTC) when the operation was submitted. + /// The completion state of the operation. + /// The current status of the operation. + /// The computed value. + internal Operation(DateTimeOffset? createdDateTime, float? percentComplete, OperationStatus? status, float? value) + { + CreatedDateTime = createdDateTime; + PercentComplete = percentComplete; + Status = status; + Value = value; + } + + /// Date and time (UTC) when the operation was submitted. + public DateTimeOffset? CreatedDateTime { get; } + /// The completion state of the operation. + public float? PercentComplete { get; } + /// The current status of the operation. + public OperationStatus? Status { get; } + /// The computed value. + public float? Value { get; } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/OperationStatus.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/OperationStatus.cs new file mode 100644 index 0000000000000..c5bba5c714a7b --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/OperationStatus.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Learn.Computation.Models +{ + /// The current status of the operation. + public readonly partial struct OperationStatus : IEquatable + { + private readonly string _value; + + /// Determines if two values are the same. + /// is null. + public OperationStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string NotstartedValue = "notstarted"; + private const string RunningValue = "running"; + private const string SucceededValue = "succeeded"; + private const string FailedValue = "failed"; + private const string CancelledValue = "cancelled"; + + /// notstarted. + public static OperationStatus Notstarted { get; } = new OperationStatus(NotstartedValue); + /// running. + public static OperationStatus Running { get; } = new OperationStatus(RunningValue); + /// succeeded. + public static OperationStatus Succeeded { get; } = new OperationStatus(SucceededValue); + /// failed. + public static OperationStatus Failed { get; } = new OperationStatus(FailedValue); + /// cancelled. + public static OperationStatus Cancelled { get; } = new OperationStatus(CancelledValue); + /// Determines if two values are the same. + public static bool operator ==(OperationStatus left, OperationStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OperationStatus left, OperationStatus right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OperationStatus(string value) => new OperationStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OperationStatus other && Equals(other); + /// + public bool Equals(OperationStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/PageOfComputeNodes.Serialization.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/PageOfComputeNodes.Serialization.cs new file mode 100644 index 0000000000000..64db5b4187093 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/PageOfComputeNodes.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Learn.Computation.Models +{ + public partial class PageOfComputeNodes + { + internal static PageOfComputeNodes DeserializePageOfComputeNodes(JsonElement element) + { + IReadOnlyList value = default; + Optional nextLink = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("value")) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ComputeNode.DeserializeComputeNode(item)); + } + value = array; + continue; + } + if (property.NameEquals("nextLink")) + { + nextLink = property.Value.GetString(); + continue; + } + } + return new PageOfComputeNodes(value, nextLink.Value); + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/PageOfComputeNodes.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/PageOfComputeNodes.cs new file mode 100644 index 0000000000000..14abfaa967f38 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/PageOfComputeNodes.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.Learn.Computation.Models +{ + /// The PageOfComputeNodes. + public partial class PageOfComputeNodes + { + /// Initializes a new instance of PageOfComputeNodes. + /// The compute nodes in this page. + /// is null. + internal PageOfComputeNodes(IEnumerable value) + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + Value = value.ToList(); + } + + /// Initializes a new instance of PageOfComputeNodes. + /// The compute nodes in this page. + /// The opaque URL to retrieve the next page. + internal PageOfComputeNodes(IReadOnlyList value, string nextLink) + { + Value = value; + NextLink = nextLink; + } + + /// The compute nodes in this page. + public IReadOnlyList Value { get; } + /// The opaque URL to retrieve the next page. + public string NextLink { get; } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/WindowsComputeNode.Serialization.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/WindowsComputeNode.Serialization.cs new file mode 100644 index 0000000000000..b0eb94422cb41 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/WindowsComputeNode.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Learn.Computation.Models +{ + public partial class WindowsComputeNode : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("userName"); + writer.WriteStringValue(UserName); + writer.WritePropertyName("kind"); + writer.WriteStringValue(Kind); + writer.WriteEndObject(); + } + + internal static WindowsComputeNode DeserializeWindowsComputeNode(JsonElement element) + { + string userName = default; + Optional eTag = default; + string name = default; + string kind = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("userName")) + { + userName = property.Value.GetString(); + continue; + } + if (property.NameEquals("eTag")) + { + eTag = property.Value.GetString(); + continue; + } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("kind")) + { + kind = property.Value.GetString(); + continue; + } + } + return new WindowsComputeNode(eTag.Value, name, kind, userName); + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/WindowsComputeNode.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/WindowsComputeNode.cs new file mode 100644 index 0000000000000..2baee42f377a6 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/Models/WindowsComputeNode.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Learn.Computation.Models +{ + /// The WindowsComputeNode. + public partial class WindowsComputeNode : ComputeNode + { + /// Initializes a new instance of WindowsComputeNode. + /// The name of the compute node. + /// The Windows user name. + /// or is null. + public WindowsComputeNode(string name, string userName) : base(name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (userName == null) + { + throw new ArgumentNullException(nameof(userName)); + } + + UserName = userName; + Kind = "WindowsComputeNode"; + } + + /// Initializes a new instance of WindowsComputeNode. + /// An HTTP ETag. + /// The name of the compute node. + /// . + /// The Windows user name. + internal WindowsComputeNode(string eTag, string name, string kind, string userName) : base(eTag, name, kind) + { + UserName = userName; + Kind = kind ?? "WindowsComputeNode"; + } + + /// The Windows user name. + public string UserName { get; set; } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/ServiceComputationHeaders.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ServiceComputationHeaders.cs new file mode 100644 index 0000000000000..989a73991d203 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ServiceComputationHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Learn.Computation +{ + internal class ServiceComputationHeaders + { + private readonly Response _response; + public ServiceComputationHeaders(Response response) + { + _response = response; + } + public string Location => _response.Headers.TryGetValue("Location", out string value) ? value : null; + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/Generated/ServiceRestClient.cs b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ServiceRestClient.cs new file mode 100644 index 0000000000000..06ab78007771a --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/Generated/ServiceRestClient.cs @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Learn.Computation.Models; + +namespace Azure.Learn.Computation +{ + internal partial class ServiceRestClient + { + private Uri endpoint; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of ServiceRestClient. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// server parameter. + public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) + { + endpoint ??= new Uri(""); + + this.endpoint = endpoint; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateComputationRequest(string operationId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/operations/", false); + uri.AppendPath(operationId, true); + request.Uri = uri; + return message; + } + + /// The String to use. + /// The cancellation token to use. + /// is null. + public async Task> ComputationAsync(string operationId, CancellationToken cancellationToken = default) + { + if (operationId == null) + { + throw new ArgumentNullException(nameof(operationId)); + } + + using var message = CreateComputationRequest(operationId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceComputationHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + Operation value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = Operation.DeserializeOperation(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// The String to use. + /// The cancellation token to use. + /// is null. + public ResponseWithHeaders Computation(string operationId, CancellationToken cancellationToken = default) + { + if (operationId == null) + { + throw new ArgumentNullException(nameof(operationId)); + } + + using var message = CreateComputationRequest(operationId); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceComputationHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + Operation value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = Operation.DeserializeOperation(document.RootElement); + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/src/autorest.md b/sdk/api-learn/Azure.Learn.Computation/src/autorest.md new file mode 100644 index 0000000000000..9de09b29ccbd4 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/autorest.md @@ -0,0 +1,8 @@ +# Generated code configuration + +Run `dotnet msbuild /t:GenerateCode` to generate code. + +``` yaml +input-file: + - $(this-folder)/swagger/computation.json +``` diff --git a/sdk/api-learn/Azure.Learn.Computation/src/swagger/computation.json b/sdk/api-learn/Azure.Learn.Computation/src/swagger/computation.json new file mode 100644 index 0000000000000..fca58facce2b3 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/src/swagger/computation.json @@ -0,0 +1,275 @@ +{ + "swagger": "2.0", + "info": { + "title": "Example Computation service for Azure SDK API Design training unit", + "version": "1.1" + }, + "consumes": [ "application/json" ], + "produces": [ "application/json" ], + "paths": { + "/ComputeNodes": { + "get": { + "operationId": "ComputeNodeAdministration_List", + "tags": [ "Administration" ], + "responses": { + "200": { + "description": "Successfully listed (one page of) ComputeNodes", + "schema": { + "$ref": "#/definitions/PageOfComputeNodes" + } + }, + "default": { + "description": "Failed to get ComputeNodes", + "schema": { + "$ref": "#/definitions/Error" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink", + "itemName": "value" + } + } + }, + "/ComputeNodes/{nodeName}": { + "parameters": [ + { + "$ref": "#/parameters/NodeName" + } + ], + "put": { + "operationId": "ComputeNodeAdministration_Create", + "tags": [ "Administration" ], + "parameters": [ + { + "name": "computeNode", + "in": "body", + "schema": { + "$ref": "#/definitions/ComputeNode" + } + }, + { + "name": "if-match", + "in": "header", + "type": "string" + } + ], + "responses": { + "201": { + "description": "Successfully created a new ComputeNode", + "schema": { + "$ref": "#/definitions/ComputeNode" + } + }, + "200": { + "description": "Successfully replace an existing ComputeNode", + "schema": { + "$ref": "#/definitions/ComputeNode" + } + }, + "default": { + "description": "Something went wrong", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "get": { + "operationId": "ComputeNodeAdministration_Get", + "tags": [ "Administration" ], + "responses": { + "200": { + "description": "Successfully got the computeNode", + "schema": { + "$ref": "#/definitions/ComputeNode" + } + } + } + } + }, + "/ComputeNodes/{nodeName}/computePi": { + "parameters": [ + { + "$ref": "#/parameters/NodeName" + } + ], + "post": { + "operationId": "Computation_ComputePi", + "tags": [ "Computation" ], + "parameters": [ + { + "name": "precision", + "in": "query", + "type": "integer", + "default": 17, + "minimum": 0 + } + ], + "responses": { + "202": { + "description": "Started long running process", + "headers": { + "Operation-Location": { + "description": "This will point to an operation (/operations/{operationId}) that can be used to monitor the progress", + "type": "string", + "format": "uri" + } + } + } + } + } + }, + "/operations/{operationId}": { + "parameters": [ + { + "name": "operationId", + "type": "string", + "in": "path", + "required": true + } + ], + "get": { + "tags": [ "Computation" ], + "responses": { + "200": { + "description": "Successfully got the operation status", + "headers": { + "Location": { + "type": "string", + "format": "uri" + } + }, + "schema": { + "$ref": "#/definitions/Operation" + } + } + } + } + } + }, + "parameters": { + "NodeName": { + "name": "nodeName", + "in": "path", + "type": "string", + "required": true + } + }, + "definitions": { + "Error": { + "type": "object" + }, + "PageOfComputeNodes": { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": { + "$ref": "#/definitions/ComputeNode" + }, + "description": "The compute nodes in this page" + }, + "nextLink": { + "type": "string", + "description": "The opaque URL to retrieve the next page" + } + } + }, + "ComputeNode": { + "type": "object", + "required": [ + "kind", + "name" + ], + "discriminator": "kind", + "properties": { + "eTag": { + "readOnly": true, + "type": "string", + "description": "An HTTP ETag" + }, + "name": { + "readOnly": true, + "type": "string", + "description": "The name of the compute node" + }, + "kind": { + "type": "string" + } + } + }, + "LinuxComputeNode": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ComputeNode" + } + ], + "required": [ + "sshPublicKey" + ], + "properties": { + "sshPublicKey": { + "type": "string", + "description": "The compute node's public key" + } + } + }, + "WindowsComputeNode": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ComputeNode" + } + ], + "required": [ + "userName" + ], + "properties": { + "userName": { + "type": "string", + "description": "The Windows user name" + } + } + }, + "Operation": { + "type": "object", + "properties": { + "createdDateTime": { + "readOnly": true, + "type": "string", + "format": "date-time", + "description": "Date and time (UTC) when the operation was submitted" + }, + "percentComplete": { + "readOnly": true, + "type": "number", + "minimum": 0, + "maximum": 100, + "description": "The completion state of the operation" + }, + "status": { + "type": "string", + "readOnly": true, + "enum": [ + "notstarted", + "running", + "succeeded", + "failed", + "cancelled" + ], + "description": "The current status of the operation" + }, + "value": { + "readOnly": true, + "type": "number", + "description": "The computed value" + } + } + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/tests/Azure.Learn.Computation.Tests.csproj b/sdk/api-learn/Azure.Learn.Computation/tests/Azure.Learn.Computation.Tests.csproj new file mode 100644 index 0000000000000..e1822e212cab3 --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/tests/Azure.Learn.Computation.Tests.csproj @@ -0,0 +1,18 @@ + + + $(RequiredTargetFrameworks) + + + + + + + + + + + + + + + diff --git a/sdk/api-learn/Azure.Learn.Computation/tests/ComputationClientTestEnvironment.cs b/sdk/api-learn/Azure.Learn.Computation/tests/ComputationClientTestEnvironment.cs new file mode 100644 index 0000000000000..29fcf5e1f2f6f --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/tests/ComputationClientTestEnvironment.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.Learn.Computation.Samples +{ + // To learn more about TestEnvironment classes, please see: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core.TestFramework/README.md + public class ComputationClientTestEnvironment : TestEnvironment + { + public ComputationClientTestEnvironment() : base("api-learn") + { + } + } +} diff --git a/sdk/api-learn/Azure.Learn.Computation/tests/Samples/Sample1_HelloWorld.cs b/sdk/api-learn/Azure.Learn.Computation/tests/Samples/Sample1_HelloWorld.cs new file mode 100644 index 0000000000000..b25fefe497b4c --- /dev/null +++ b/sdk/api-learn/Azure.Learn.Computation/tests/Samples/Sample1_HelloWorld.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.Learn.Computation.Samples +{ + public class Sample1_HelloWorld : SamplesBase + { + } +}