Browse Source

Add endpoint for Tye application metadata (#1079)

* Sketch GET for control plane.

* Add properties to control plane metadata.

* Resolve linter warnings.

* Switch to /application endpoint.

* Change ID to Id.
pull/1086/head
Phillip Hoff 5 years ago
committed by GitHub
parent
commit
1719c2eb7f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/Microsoft.Tye.Hosting/Model/Application.cs
  2. 15
      src/Microsoft.Tye.Hosting/Model/V1/V1Application.cs
  3. 21
      src/Microsoft.Tye.Hosting/TyeDashboardApi.cs
  4. 2
      src/tye/ApplicationBuilderExtensions.cs
  5. 4
      test/Test.Infrastructure/TestHelpers.cs

7
src/Microsoft.Tye.Hosting/Model/Application.cs

@ -12,14 +12,19 @@ namespace Microsoft.Tye.Hosting.Model
{
public class Application
{
public Application(FileInfo source, Dictionary<string, Service> services, ContainerEngine containerEngine)
public Application(string name, FileInfo source, Dictionary<string, Service> services, ContainerEngine containerEngine)
{
Name = name;
Source = source.FullName;
ContextDirectory = source.DirectoryName!;
Services = services;
ContainerEngine = containerEngine;
}
public string Id { get; } = Guid.NewGuid().ToString();
public string Name { get; }
public string Source { get; }
public string ContextDirectory { get; }

15
src/Microsoft.Tye.Hosting/Model/V1/V1Application.cs

@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.Tye.Hosting.Model.V1
{
public class V1Application
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Source { get; set; }
}
}

21
src/Microsoft.Tye.Hosting/TyeDashboardApi.cs

@ -37,6 +37,7 @@ namespace Microsoft.Tye.Hosting
public void MapRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapGet("/api/v1", ServiceIndex);
endpoints.MapGet("/api/v1/application", ApplicationIndex);
endpoints.MapDelete("/api/v1/control", ControlPlaneShutdown);
endpoints.MapGet("/api/v1/services", Services);
endpoints.MapGet("/api/v1/services/{name}", Service);
@ -50,15 +51,33 @@ namespace Microsoft.Tye.Hosting
context.Response.ContentType = "application/json";
return JsonSerializer.SerializeAsync(context.Response.Body, new[]
{
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/application",
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/control",
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/services",
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/logs/{{service}}",
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/metrics",
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/metrics/{{service}}",
$"{context.Request.Scheme}://{context.Request.Host}/api/v1/services",
},
_options);
}
private Task ApplicationIndex(HttpContext context)
{
var app = context.RequestServices.GetRequiredService<Application>();
context.Response.ContentType = "application/json";
return JsonSerializer.SerializeAsync(
context.Response.Body,
new V1Application
{
Id = app.Id,
Name = app.Name,
Source = app.Source
},
_options);
}
private Task ControlPlaneShutdown(HttpContext context)
{
var lifetime = context.RequestServices.GetRequiredService<IHostApplicationLifetime>();

2
src/tye/ApplicationBuilderExtensions.cs

@ -213,7 +213,7 @@ namespace Microsoft.Tye
services.Add(ingress.Name, new Service(description));
}
return new Application(application.Source, services, application.ContainerEngine) { Network = application.Network };
return new Application(application.Name, application.Source, services, application.ContainerEngine) { Network = application.Network };
}
public static Tye.Hosting.Model.EnvironmentVariable ToHostingEnvironmentVariable(this EnvironmentVariableBuilder builder)

4
test/Test.Infrastructure/TestHelpers.cs

@ -251,8 +251,8 @@ namespace Test.Infrastructure
var processRunner = new ProcessRunner(logger, replicaRegistry, new ProcessRunnerOptions());
var dockerRunner = new DockerRunner(logger, replicaRegistry);
await processRunner.StartAsync(new Application(new FileInfo(host.Application.Source), new Dictionary<string, Service>(), ContainerEngine.Default));
await dockerRunner.StartAsync(new Application(new FileInfo(host.Application.Source), new Dictionary<string, Service>(), ContainerEngine.Default));
await processRunner.StartAsync(new Application(host.Application.Name, new FileInfo(host.Application.Source), new Dictionary<string, Service>(), ContainerEngine.Default));
await dockerRunner.StartAsync(new Application(host.Application.Name, new FileInfo(host.Application.Source), new Dictionary<string, Service>(), ContainerEngine.Default));
}
await DoOperationAndWaitForReplicasToChangeState(host, ReplicaState.Stopped, replicas.Length, replicas.ToHashSet(), new HashSet<string>(), TimeSpan.Zero, Purge);

Loading…
Cancel
Save