18
18
using System . Text ;
19
19
using Argo ;
20
20
using Ardalis . GuardClauses ;
21
-
21
+ using Microsoft . Extensions . Logging ;
22
+ using Monai . Deploy . WorkflowManager . TaskManager . Argo . Logging ;
23
+ using System . Net ;
24
+ using Monai . Deploy . WorkflowManager . TaskManager . Argo . Exceptions ;
22
25
23
26
namespace Monai . Deploy . WorkflowManager . TaskManager . Argo
24
27
{
25
28
public class ArgoClient : BaseArgoClient , IArgoClient
26
29
{
27
- public ArgoClient ( HttpClient httpClient ) : base ( httpClient ) { }
30
+ public ArgoClient ( HttpClient httpClient , ILoggerFactory logger ) : base ( httpClient , logger ) { }
28
31
29
32
public async Task < Workflow > Argo_CreateWorkflowAsync ( string argoNamespace , WorkflowCreateRequest body , CancellationToken cancellationToken )
30
33
{
@@ -77,7 +80,23 @@ public async Task<Workflow> Argo_StopWorkflowAsync(string argoNamespace, string
77
80
78
81
const string method = "PUT" ;
79
82
var content = new StringContent ( Newtonsoft . Json . JsonConvert . SerializeObject ( body ) ) ;
80
- return await SendRequest < Workflow > ( content , urlBuilder , method , new CancellationToken ( ) ) . ConfigureAwait ( false ) ;
83
+ try
84
+ {
85
+ return await SendRequest < Workflow > ( content , urlBuilder , method , new CancellationToken ( ) ) . ConfigureAwait ( false ) ;
86
+ }
87
+ catch ( ApiException < Error > ex )
88
+ {
89
+ if ( ex . StatusCode == ( int ) HttpStatusCode . NotFound )
90
+ {
91
+ throw new ArgoWorkflowNotFoundException ( body . Name , ex ) ;
92
+ }
93
+ throw ;
94
+ }
95
+ catch ( Exception )
96
+ {
97
+ throw ;
98
+ }
99
+
81
100
82
101
}
83
102
@@ -92,7 +111,22 @@ public async Task<Workflow> Argo_TerminateWorkflowAsync(string argoNamespace, st
92
111
93
112
const string method = "PUT" ;
94
113
var content = new StringContent ( Newtonsoft . Json . JsonConvert . SerializeObject ( body ) ) ;
95
- return await SendRequest < Workflow > ( content , urlBuilder , method , new CancellationToken ( ) ) . ConfigureAwait ( false ) ;
114
+ try
115
+ {
116
+ return await SendRequest < Workflow > ( content , urlBuilder , method , new CancellationToken ( ) ) . ConfigureAwait ( false ) ;
117
+ }
118
+ catch ( ApiException < Error > ex )
119
+ {
120
+ if ( ex . StatusCode == ( int ) HttpStatusCode . NotFound )
121
+ {
122
+ throw new ArgoWorkflowNotFoundException ( body . Name , ex ) ;
123
+ }
124
+ throw ;
125
+ }
126
+ catch ( Exception )
127
+ {
128
+ throw ;
129
+ }
96
130
}
97
131
98
132
public async Task < WorkflowTemplate ? > Argo_GetWorkflowTemplateAsync ( string argoNamespace , string name , string ? getOptionsResourceVersion )
@@ -231,9 +265,11 @@ public class BaseArgoClient
231
265
232
266
protected readonly HttpClient HttpClient ;
233
267
234
- public BaseArgoClient ( HttpClient httpClient )
268
+ protected readonly ILogger Logger ;
269
+ public BaseArgoClient ( HttpClient httpClient , ILoggerFactory loggerFactory )
235
270
{
236
271
HttpClient = httpClient ;
272
+ Logger = loggerFactory . CreateLogger ( "BaseArgoClient" ) ;
237
273
}
238
274
239
275
protected async Task < T > SendRequest < T > ( StringContent stringContent , StringBuilder urlBuilder , string method , CancellationToken cancellationToken )
@@ -250,6 +286,8 @@ protected async Task<T> SendRequest<T>(StringContent stringContent, StringBuilde
250
286
request . RequestUri = new Uri ( urlBuilder . ToString ( ) , UriKind . RelativeOrAbsolute ) ;
251
287
252
288
HttpResponseMessage ? response = null ;
289
+ var logStringContent = stringContent == null ? string . Empty : await stringContent . ReadAsStringAsync ( ) ;
290
+ Logger . CallingArgoHttpInfo ( request . RequestUri . ToString ( ) , method , logStringContent ) ;
253
291
response = await HttpClient . SendAsync ( request , HttpCompletionOption . ResponseContentRead , cancellationToken ) . ConfigureAwait ( false ) ;
254
292
255
293
try
0 commit comments