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

Version the status endpoint and include it in the C# client #3946

Merged
merged 2 commits into from
Sep 13, 2024
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
4 changes: 2 additions & 2 deletions eng/deployment/product-construction-service-deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ param(
$containerapp = az containerapp show -g $resourceGroupName -n $containerappName | ConvertFrom-Json
$pcsUrl = "https://$($containerapp.properties.configuration.ingress.fqdn)"
$pcsStatusUrl = $pcsUrl + "/status"
$pcsStopUrl = $pcsStatusUrl + "/stop"
$pcsStartUrl = $pcsStatusUrl + "/start"
$pcsStopUrl = $pcsStatusUrl + "/stop?api-version=2020-02-20"
$pcsStartUrl = $pcsStatusUrl + "/start?api-version=2020-02-20"
$authenticationHeader = @{
"Authorization" = "Bearer $token"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.ApiVersioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Extensions;
Expand All @@ -10,6 +11,7 @@
namespace ProductConstructionService.Api.Controllers;

[Route("status")]
[ApiVersion("2020-02-20")]
public class StatusController(WorkItemScopeManager workItemScopeManager)
: ControllerBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial interface IProductConstructionServiceApi
IChannels Channels { get; }
IPipelines Pipelines { get; }
IRepository Repository { get; }
IStatus Status { get; }
ISubscriptions Subscriptions { get; }
}

Expand Down Expand Up @@ -129,6 +130,8 @@ public HttpPipeline Pipeline

public IRepository Repository { get; }

public IStatus Status { get; }

public ISubscriptions Subscriptions { get; }


Expand All @@ -149,6 +152,7 @@ public ProductConstructionServiceApi(ProductConstructionServiceApiOptions option
Channels = new Channels(this);
Pipelines = new Pipelines(this);
Repository = new Repository(this);
Status = new Status(this);
Subscriptions = new Subscriptions(this);
SerializerSettings = new JsonSerializerSettings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Core;



namespace ProductConstructionService.Client
{
public partial interface IStatus
{
Task StopPcsWorkItemProcessorAsync(
CancellationToken cancellationToken = default
);

Task StartPcsWorkItemProcessorAsync(
CancellationToken cancellationToken = default
);

Task GetPcsWorkItemProcessorStatusAsync(
CancellationToken cancellationToken = default
);

}

internal partial class Status : IServiceOperations<ProductConstructionServiceApi>, IStatus
{
public Status(ProductConstructionServiceApi client)
{
Client = client ?? throw new ArgumentNullException(nameof(client));
}

public ProductConstructionServiceApi Client { get; }

partial void HandleFailedRequest(RestApiException ex);

partial void HandleFailedStopPcsWorkItemProcessorRequest(RestApiException ex);

public async Task StopPcsWorkItemProcessorAsync(
CancellationToken cancellationToken = default
)
{

const string apiVersion = "2020-02-20";

var _baseUri = Client.Options.BaseUri;
var _url = new RequestUriBuilder();
_url.Reset(_baseUri);
_url.AppendPath(
"/api/status/stop",
false);

_url.AppendQuery("api-version", Client.Serialize(apiVersion));


using (var _req = Client.Pipeline.CreateRequest())
{
_req.Uri = _url;
_req.Method = RequestMethod.Put;

using (var _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false))
{
if (_res.Status < 200 || _res.Status >= 300)
{
await OnStopPcsWorkItemProcessorFailed(_req, _res).ConfigureAwait(false);
}


return;
}
}
}

internal async Task OnStopPcsWorkItemProcessorFailed(Request req, Response res)
{
string content = null;
if (res.ContentStream != null)
{
using (var reader = new StreamReader(res.ContentStream))
{
content = await reader.ReadToEndAsync().ConfigureAwait(false);
}
}

var ex = new RestApiException<Models.ApiError>(
req,
res,
content,
Client.Deserialize<Models.ApiError>(content)
);
HandleFailedStopPcsWorkItemProcessorRequest(ex);
HandleFailedRequest(ex);
Client.OnFailedRequest(ex);
throw ex;
}

partial void HandleFailedStartPcsWorkItemProcessorRequest(RestApiException ex);

public async Task StartPcsWorkItemProcessorAsync(
CancellationToken cancellationToken = default
)
{

const string apiVersion = "2020-02-20";

var _baseUri = Client.Options.BaseUri;
var _url = new RequestUriBuilder();
_url.Reset(_baseUri);
_url.AppendPath(
"/api/status/start",
false);

_url.AppendQuery("api-version", Client.Serialize(apiVersion));


using (var _req = Client.Pipeline.CreateRequest())
{
_req.Uri = _url;
_req.Method = RequestMethod.Put;

using (var _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false))
{
if (_res.Status < 200 || _res.Status >= 300)
{
await OnStartPcsWorkItemProcessorFailed(_req, _res).ConfigureAwait(false);
}


return;
}
}
}

internal async Task OnStartPcsWorkItemProcessorFailed(Request req, Response res)
{
string content = null;
if (res.ContentStream != null)
{
using (var reader = new StreamReader(res.ContentStream))
{
content = await reader.ReadToEndAsync().ConfigureAwait(false);
}
}

var ex = new RestApiException<Models.ApiError>(
req,
res,
content,
Client.Deserialize<Models.ApiError>(content)
);
HandleFailedStartPcsWorkItemProcessorRequest(ex);
HandleFailedRequest(ex);
Client.OnFailedRequest(ex);
throw ex;
}

partial void HandleFailedGetPcsWorkItemProcessorStatusRequest(RestApiException ex);

public async Task GetPcsWorkItemProcessorStatusAsync(
CancellationToken cancellationToken = default
)
{

const string apiVersion = "2020-02-20";

var _baseUri = Client.Options.BaseUri;
var _url = new RequestUriBuilder();
_url.Reset(_baseUri);
_url.AppendPath(
"/api/status",
false);

_url.AppendQuery("api-version", Client.Serialize(apiVersion));


using (var _req = Client.Pipeline.CreateRequest())
{
_req.Uri = _url;
_req.Method = RequestMethod.Get;

using (var _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false))
{
if (_res.Status < 200 || _res.Status >= 300)
{
await OnGetPcsWorkItemProcessorStatusFailed(_req, _res).ConfigureAwait(false);
}


return;
}
}
}

internal async Task OnGetPcsWorkItemProcessorStatusFailed(Request req, Response res)
{
string content = null;
if (res.ContentStream != null)
{
using (var reader = new StreamReader(res.ContentStream))
{
content = await reader.ReadToEndAsync().ConfigureAwait(false);
}
}

var ex = new RestApiException<Models.ApiError>(
req,
res,
content,
Client.Deserialize<Models.ApiError>(content)
);
HandleFailedGetPcsWorkItemProcessorStatusRequest(ex);
HandleFailedRequest(ex);
Client.OnFailedRequest(ex);
throw ex;
}
}
}