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>
@@ -220,44 +192,4 @@ private static void ConfigureAttuContainer(EnvironmentCallbackContext context, M
220192 // This will need to be refactored once updated service discovery APIs are available
221193 context . EnvironmentVariables . Add ( "MILVUS_URL" , $ "{ resource . PrimaryEndpoint . Scheme } ://{ resource . Name } :{ resource . PrimaryEndpoint . TargetPort } ") ;
222194 }
223- internal static MilvusClient CreateMilvusClient ( IServiceProvider sp , string ? connectionString )
224- {
225- if ( connectionString is null )
226- {
227- throw new InvalidOperationException ( "Connection string is unavailable" ) ;
228- }
229-
230- Uri ? endpoint = null ;
231- string ? key = null ;
232- string ? database = null ;
233-
234- if ( Uri . TryCreate ( connectionString , UriKind . Absolute , out var uri ) )
235- {
236- endpoint = uri ;
237- }
238- else
239- {
240- var connectionBuilder = new DbConnectionStringBuilder
241- {
242- ConnectionString = connectionString
243- } ;
244-
245- if ( connectionBuilder . ContainsKey ( "Endpoint" ) && Uri . TryCreate ( connectionBuilder [ "Endpoint" ] . ToString ( ) , UriKind . Absolute , out var serviceUri ) )
246- {
247- endpoint = serviceUri ;
248- }
249-
250- if ( connectionBuilder . ContainsKey ( "Key" ) )
251- {
252- key = connectionBuilder [ "Key" ] . ToString ( ) ;
253- }
254-
255- if ( connectionBuilder . ContainsKey ( "Database" ) )
256- {
257- database = connectionBuilder [ "Database" ] . ToString ( ) ;
258- }
259- }
260-
261- return new MilvusClient ( endpoint ! , apiKey : key ! , database : database , loggerFactory : sp . GetRequiredService < ILoggerFactory > ( ) ) ;
262- }
263195}
0 commit comments