11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4- using System . Data . Common ;
54using Aspire . Hosting . ApplicationModel ;
65using Aspire . Hosting . Milvus ;
76using Aspire . Hosting . Utils ;
8- using Aspire . Milvus . Client ;
9- using Microsoft . Extensions . DependencyInjection ;
10- using Microsoft . Extensions . Diagnostics . HealthChecks ;
11- using Microsoft . Extensions . Logging ;
12- using Milvus . Client ;
137
148namespace Aspire . Hosting ;
159
@@ -56,27 +50,6 @@ public static IResourceBuilder<MilvusServerResource> AddMilvus(this IDistributed
5650 ParameterResourceBuilderExtensions . CreateDefaultPasswordParameter ( builder , $ "{ name } -key") ;
5751
5852 var milvus = new MilvusServerResource ( name , apiKeyParameter ) ;
59-
60- MilvusClient ? milvusClient = null ;
61-
62- builder . Eventing . Subscribe < ConnectionStringAvailableEvent > ( milvus , async ( @event , ct ) =>
63- {
64- var connectionString = await milvus . ConnectionStringExpression . GetValueAsync ( ct ) . ConfigureAwait ( false )
65- ?? throw new DistributedApplicationException ( $ "ConnectionStringAvailableEvent was published for the '{ milvus . Name } ' resource but the connection string was null.") ;
66- milvusClient = CreateMilvusClient ( @event . Services , connectionString ) ;
67- } ) ;
68-
69- var healthCheckKey = $ "{ name } _check";
70- // TODO: Use health check from AspNetCore.Diagnostics.HealthChecks once it's implemented via this issue:
71- // https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2214
72- builder . Services . AddHealthChecks ( )
73- . Add ( new HealthCheckRegistration (
74- healthCheckKey ,
75- sp => new MilvusHealthCheck ( milvusClient ! ) ,
76- failureStatus : default ,
77- tags : default ,
78- timeout : default ) ) ;
79-
8053 return builder . AddResource ( milvus )
8154 . WithImage ( MilvusContainerImageTags . Image , MilvusContainerImageTags . Tag )
8255 . WithImageRegistry ( MilvusContainerImageTags . Registry )
@@ -93,8 +66,7 @@ public static IResourceBuilder<MilvusServerResource> AddMilvus(this IDistributed
9366 {
9467 ctx . EnvironmentVariables [ "COMMON_SECURITY_DEFAULTROOTPASSWORD" ] = milvus . ApiKeyParameter ;
9568 } )
96- . WithArgs ( "milvus" , "run" , "standalone" )
97- . WithHealthCheck ( healthCheckKey ) ;
69+ . WithArgs ( "milvus" , "run" , "standalone" ) ;
9870 }
9971
10072 /// <summary>
@@ -217,44 +189,4 @@ private static void ConfigureAttuContainer(EnvironmentCallbackContext context, M
217189 // This will need to be refactored once updated service discovery APIs are available
218190 context . EnvironmentVariables . Add ( "MILVUS_URL" , $ "{ resource . PrimaryEndpoint . Scheme } ://{ resource . Name } :{ resource . PrimaryEndpoint . TargetPort } ") ;
219191 }
220- internal static MilvusClient CreateMilvusClient ( IServiceProvider sp , string ? connectionString )
221- {
222- if ( connectionString is null )
223- {
224- throw new InvalidOperationException ( "Connection string is unavailable" ) ;
225- }
226-
227- Uri ? endpoint = null ;
228- string ? key = null ;
229- string ? database = null ;
230-
231- if ( Uri . TryCreate ( connectionString , UriKind . Absolute , out var uri ) )
232- {
233- endpoint = uri ;
234- }
235- else
236- {
237- var connectionBuilder = new DbConnectionStringBuilder
238- {
239- ConnectionString = connectionString
240- } ;
241-
242- if ( connectionBuilder . ContainsKey ( "Endpoint" ) && Uri . TryCreate ( connectionBuilder [ "Endpoint" ] . ToString ( ) , UriKind . Absolute , out var serviceUri ) )
243- {
244- endpoint = serviceUri ;
245- }
246-
247- if ( connectionBuilder . ContainsKey ( "Key" ) )
248- {
249- key = connectionBuilder [ "Key" ] . ToString ( ) ;
250- }
251-
252- if ( connectionBuilder . ContainsKey ( "Database" ) )
253- {
254- database = connectionBuilder [ "Database" ] . ToString ( ) ;
255- }
256- }
257-
258- return new MilvusClient ( endpoint ! , apiKey : key ! , database : database , loggerFactory : sp . GetRequiredService < ILoggerFactory > ( ) ) ;
259- }
260192}
0 commit comments