Skip to content

Commit b9de4b9

Browse files
authored
Change manifest publishing to emit v0 resources. (dotnet#617)
* Change manifest publishing to emit v0 resources.
1 parent 82ca358 commit b9de4b9

File tree

10 files changed

+288
-36
lines changed

10 files changed

+288
-36
lines changed

samples/dapr/AppHost/aspire-manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"resources": {
33
"servicea": {
4-
"type": "project.v1",
4+
"type": "project.v0",
55
"path": "..\\ServiceA\\DaprServiceA.csproj",
66
"env": {
77
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -21,7 +21,7 @@
2121
}
2222
},
2323
"serviceb": {
24-
"type": "project.v1",
24+
"type": "project.v0",
2525
"path": "..\\ServiceB\\DaprServiceB.csproj",
2626
"env": {
2727
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -41,7 +41,7 @@
4141
}
4242
},
4343
"service-a": {
44-
"type": "executable.v1",
44+
"type": "executable.v0",
4545
"env": {},
4646
"bindings": {
4747
"grpc": {
@@ -62,7 +62,7 @@
6262
}
6363
},
6464
"service-b": {
65-
"type": "executable.v1",
65+
"type": "executable.v0",
6666
"env": {},
6767
"bindings": {
6868
"grpc": {

samples/eShopLite/AppHost/aspire-manifest.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"resources": {
33
"postgres": {
4-
"type": "postgres.server.v1"
4+
"type": "postgres.server.v0"
55
},
66
"catalogdb": {
7-
"type": "postgres.database.v1",
7+
"type": "postgres.database.v0",
88
"parent": "postgres"
99
},
1010
"basketcache": {
11-
"type": "redis.v1"
11+
"type": "redis.v0"
1212
},
1313
"catalogservice": {
14-
"type": "project.v1",
14+
"type": "project.v0",
1515
"path": "..\\CatalogService\\CatalogService.csproj",
1616
"env": {
1717
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -32,10 +32,10 @@
3232
}
3333
},
3434
"messaging": {
35-
"type": "rabbitmq.server.v1"
35+
"type": "rabbitmq.server.v0"
3636
},
3737
"basketservice": {
38-
"type": "project.v1",
38+
"type": "project.v0",
3939
"path": "..\\BasketService\\BasketService.csproj",
4040
"env": {
4141
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -57,7 +57,7 @@
5757
}
5858
},
5959
"frontend": {
60-
"type": "project.v1",
60+
"type": "project.v0",
6161
"path": "..\\MyFrontend\\MyFrontend.csproj",
6262
"env": {
6363
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -80,7 +80,7 @@
8080
}
8181
},
8282
"orderprocessor": {
83-
"type": "project.v1",
83+
"type": "project.v0",
8484
"path": "..\\OrderProcessor\\OrderProcessor.csproj",
8585
"env": {
8686
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -101,7 +101,7 @@
101101
}
102102
},
103103
"apigateway": {
104-
"type": "project.v1",
104+
"type": "project.v0",
105105
"path": "..\\ApiGateway\\ApiGateway.csproj",
106106
"env": {
107107
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
@@ -125,7 +125,7 @@
125125
}
126126
},
127127
"catalogdbapp": {
128-
"type": "project.v1",
128+
"type": "project.v0",
129129
"path": "..\\CatalogDb\\CatalogDb.csproj",
130130
"env": {
131131
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",

src/Aspire.Hosting.Azure/AzureResourceExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static IResourceBuilder<AzureKeyVaultResource> AddAzureKeyVault(this IDis
2424

2525
private static void WriteAzureKeyVaultToManifest(Utf8JsonWriter jsonWriter)
2626
{
27-
jsonWriter.WriteString("type", "azure.keyvault.v1");
27+
jsonWriter.WriteString("type", "azure.keyvault.v0");
2828
}
2929

3030
/// <summary>
@@ -49,7 +49,7 @@ public static IResourceBuilder<AzureServiceBusResource> AddAzureServiceBus(this
4949

5050
private static void WriteAzureServiceBusToManifest(AzureServiceBusResource resource, Utf8JsonWriter jsonWriter)
5151
{
52-
jsonWriter.WriteString("type", "azure.servicebus.v1");
52+
jsonWriter.WriteString("type", "azure.servicebus.v0");
5353

5454
if (resource.QueueNames.Length > 0)
5555
{
@@ -87,7 +87,7 @@ public static IResourceBuilder<AzureStorageResource> AddAzureStorage(this IDistr
8787

8888
private static void WriteAzureStorageToManifest(Utf8JsonWriter jsonWriter)
8989
{
90-
jsonWriter.WriteString("type", "azure.storage.v1");
90+
jsonWriter.WriteString("type", "azure.storage.v0");
9191
}
9292

9393
/// <summary>
@@ -105,7 +105,7 @@ public static IResourceBuilder<AzureBlobStorageResource> AddBlobs(this IResource
105105

106106
private static void WriteBlobStorageToManifest(Utf8JsonWriter json, AzureBlobStorageResource resource)
107107
{
108-
json.WriteString("type", "azure.storage.blob.v1");
108+
json.WriteString("type", "azure.storage.blob.v0");
109109
json.WriteString("parent", resource.Parent.Name);
110110
}
111111

@@ -124,7 +124,7 @@ public static IResourceBuilder<AzureTableStorageResource> AddTables(this IResour
124124

125125
private static void WriteTableStorageToManifest(Utf8JsonWriter json, AzureTableStorageResource resource)
126126
{
127-
json.WriteString("type", "azure.storage.table.v1");
127+
json.WriteString("type", "azure.storage.table.v0");
128128
json.WriteString("parent", resource.Parent.Name);
129129
}
130130

@@ -143,7 +143,7 @@ public static IResourceBuilder<AzureQueueStorageResource> AddQueues(this IResour
143143

144144
private static void WriteQueueStorageToManifest(Utf8JsonWriter json, AzureQueueStorageResource resource)
145145
{
146-
json.WriteString("type", "azure.storage.queue.v1");
146+
json.WriteString("type", "azure.storage.queue.v0");
147147
json.WriteString("parent", resource.Parent.Name);
148148
}
149149

@@ -178,7 +178,7 @@ public static IResourceBuilder<AzureRedisResource> AddAzureRedis(this IDistribut
178178

179179
private static void WriteAzureRedisToManifest(Utf8JsonWriter writer)
180180
{
181-
writer.WriteString("type", "azure.redis.v1");
181+
writer.WriteString("type", "azure.redis.v0");
182182
}
183183

184184
/// <summary>
@@ -196,6 +196,6 @@ public static IResourceBuilder<AzureAppConfigurationResource> AddAzureAppConfigu
196196

197197
private static void WriteAzureAppConfigurationToManifest(Utf8JsonWriter writer)
198198
{
199-
writer.WriteString("type", "azure.appconfiguration.v1");
199+
writer.WriteString("type", "azure.appconfiguration.v0");
200200
}
201201
}

src/Aspire.Hosting/Postgres/PostgresBuilderExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ public static IResourceBuilder<PostgresDatabaseResource> AddDatabase(this IResou
6262

6363
private static void WritePostgresConnectionToManifest(Utf8JsonWriter jsonWriter, PostgresConnectionResource postgresConnection)
6464
{
65-
jsonWriter.WriteString("type", "postgres.connection.v1");
65+
jsonWriter.WriteString("type", "postgres.connection.v0");
6666
jsonWriter.WriteString("connectionString", postgresConnection.GetConnectionString());
6767
}
6868

6969
private static void WritePostgresContainerToManifest(Utf8JsonWriter jsonWriter)
7070
{
71-
jsonWriter.WriteString("type", "postgres.server.v1");
71+
jsonWriter.WriteString("type", "postgres.server.v0");
7272
}
7373

7474
private static void WritePostgresDatabaseToManifest(Utf8JsonWriter json, PostgresDatabaseResource postgresDatabase)
7575
{
76-
json.WriteString("type", "postgres.database.v1");
76+
json.WriteString("type", "postgres.database.v0");
7777
json.WriteString("parent", postgresDatabase.Parent.Name);
7878
}
7979
}

src/Aspire.Hosting/Publishing/ManifestPublisher.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88

99
namespace Aspire.Hosting.Publishing;
1010

11-
internal sealed class ManifestPublisher(IOptions<PublishingOptions> options, IHostApplicationLifetime lifetime) : IDistributedApplicationPublisher
11+
public class ManifestPublisher(IOptions<PublishingOptions> options, IHostApplicationLifetime lifetime) : IDistributedApplicationPublisher
1212
{
1313
private readonly IOptions<PublishingOptions> _options = options;
1414
private readonly IHostApplicationLifetime _lifetime = lifetime;
1515

16-
public async Task PublishAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
16+
public Utf8JsonWriter? JsonWriter { get; set; }
17+
18+
public virtual async Task PublishAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
1719
{
18-
await WriteManifestAsync(model, cancellationToken).ConfigureAwait(false);
20+
await PublishInternalAsync(model, cancellationToken).ConfigureAwait(false);
1921
_lifetime.StopApplication();
2022
}
2123

22-
private async Task WriteManifestAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
24+
protected virtual async Task PublishInternalAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
2325
{
2426
if (_options.Value.OutputPath == null)
2527
{
@@ -29,8 +31,13 @@ private async Task WriteManifestAsync(DistributedApplicationModel model, Cancell
2931
}
3032

3133
using var stream = new FileStream(_options.Value.OutputPath, FileMode.Create);
32-
using var jsonWriter = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
34+
using var jsonWriter = JsonWriter ?? new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
35+
36+
await WriteManifestAsync(model, jsonWriter, cancellationToken).ConfigureAwait(false);
37+
}
3338

39+
protected async Task WriteManifestAsync(DistributedApplicationModel model, Utf8JsonWriter jsonWriter, CancellationToken cancellationToken)
40+
{
3441
jsonWriter.WriteStartObject();
3542
WriteResources(model, jsonWriter);
3643
jsonWriter.WriteEndObject();
@@ -169,7 +176,7 @@ private static void WriteBindings(IResource resource, Utf8JsonWriter jsonWriter)
169176

170177
private static void WriteContainer(ContainerResource container, Utf8JsonWriter jsonWriter)
171178
{
172-
jsonWriter.WriteString("type", "container.v1");
179+
jsonWriter.WriteString("type", "container.v0");
173180

174181
if (!container.TryGetContainerImageName(out var image))
175182
{
@@ -184,7 +191,7 @@ private static void WriteContainer(ContainerResource container, Utf8JsonWriter j
184191

185192
private void WriteProject(ProjectResource project, Utf8JsonWriter jsonWriter)
186193
{
187-
jsonWriter.WriteString("type", "project.v1");
194+
jsonWriter.WriteString("type", "project.v0");
188195

189196
if (!project.TryGetLastAnnotation<IServiceMetadata>(out var metadata))
190197
{
@@ -203,7 +210,7 @@ private void WriteProject(ProjectResource project, Utf8JsonWriter jsonWriter)
203210

204211
private static void WriteExecutable(ExecutableResource executable, Utf8JsonWriter jsonWriter)
205212
{
206-
jsonWriter.WriteString("type", "executable.v1");
213+
jsonWriter.WriteString("type", "executable.v0");
207214

208215
WriteEnvironmentVariables(executable, jsonWriter);
209216
WriteBindings(executable, jsonWriter);

src/Aspire.Hosting/RabbitMQ/RabbitMQBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public static IResourceBuilder<RabbitMQConnectionResource> AddRabbitMQConnection
4545
}
4646
private static void WriteRabbitMQContainerToManifest(Utf8JsonWriter json)
4747
{
48-
json.WriteString("type", "rabbitmq.server.v1");
48+
json.WriteString("type", "rabbitmq.server.v0");
4949
}
5050

5151
private static void WriteRabbitMQConnectionToManifest(Utf8JsonWriter json, RabbitMQConnectionResource rabbitMqConnection)
5252
{
53-
json.WriteString("type", "rabbitmq.connection.v1");
53+
json.WriteString("type", "rabbitmq.connection.v0");
5454
json.WriteString("connectionString", rabbitMqConnection.GetConnectionString());
5555
}
5656
}

src/Aspire.Hosting/Redis/RedisBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static void WriteRedisResourceToManifest(Utf8JsonWriter jsonWriter) =>
4545

4646
private static void WriteRedisResourceToManifest(Utf8JsonWriter jsonWriter, string? connectionString)
4747
{
48-
jsonWriter.WriteString("type", "redis.v1");
48+
jsonWriter.WriteString("type", "redis.v0");
4949
if (!string.IsNullOrEmpty(connectionString))
5050
{
5151
jsonWriter.WriteString("connectionString", connectionString);

tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<ItemGroup>
99
<ProjectReference Include="..\..\src\Aspire.Hosting\Aspire.Hosting.csproj" />
10+
<ProjectReference Include="..\..\src\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" />
1011
<ProjectReference Include="..\testproject\TestProject.AppHost\TestProject.AppHost.csproj" />
1112
</ItemGroup>
1213

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Text.Json;
5+
using Aspire.Hosting.Publishing;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Options;
9+
10+
namespace Aspire.Hosting.Tests.Helpers;
11+
12+
internal sealed class JsonDocumentManifestPublisher(IOptions<PublishingOptions> options, IHostApplicationLifetime lifetime) : ManifestPublisher(options, lifetime)
13+
{
14+
protected override async Task PublishInternalAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
15+
{
16+
using var stream = new MemoryStream();
17+
using var writer = new Utf8JsonWriter(stream, new() { Indented = true });
18+
19+
await WriteManifestAsync(model, writer, cancellationToken).ConfigureAwait(false);
20+
21+
stream.Seek(0, SeekOrigin.Begin);
22+
_manifestDocument = await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken).ConfigureAwait(false);
23+
}
24+
25+
private JsonDocument? _manifestDocument;
26+
27+
public JsonDocument ManifestDocument
28+
{
29+
get
30+
{
31+
return _manifestDocument ?? throw new InvalidOperationException("JsonDocument not available.");
32+
}
33+
}
34+
}
35+
36+
internal static class JsonDocumentManifestPublisherExtensions
37+
{
38+
public static JsonDocumentManifestPublisher GetManifestPublisher(this TestProgram testProgram)
39+
{
40+
var publisher = testProgram.App?.Services.GetRequiredKeyedService<IDistributedApplicationPublisher>("manifest") as JsonDocumentManifestPublisher;
41+
return publisher ?? throw new InvalidOperationException($"Manifest publisher was not {nameof(JsonDocumentManifestPublisher)}");
42+
}
43+
}

0 commit comments

Comments
 (0)