1818using System . Text ;
1919using Argo ;
2020using 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 ;
2225
2326namespace Monai . Deploy . WorkflowManager . TaskManager . Argo
2427{
2528 public class ArgoClient : BaseArgoClient , IArgoClient
2629 {
27- public ArgoClient ( HttpClient httpClient ) : base ( httpClient ) { }
30+ public ArgoClient ( HttpClient httpClient , ILoggerFactory logger ) : base ( httpClient , logger ) { }
2831
2932 public async Task < Workflow > Argo_CreateWorkflowAsync ( string argoNamespace , WorkflowCreateRequest body , CancellationToken cancellationToken )
3033 {
@@ -77,7 +80,23 @@ public async Task<Workflow> Argo_StopWorkflowAsync(string argoNamespace, string
7780
7881 const string method = "PUT" ;
7982 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+
81100
82101 }
83102
@@ -92,7 +111,22 @@ public async Task<Workflow> Argo_TerminateWorkflowAsync(string argoNamespace, st
92111
93112 const string method = "PUT" ;
94113 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+ }
96130 }
97131
98132 public async Task < WorkflowTemplate ? > Argo_GetWorkflowTemplateAsync ( string argoNamespace , string name , string ? getOptionsResourceVersion )
@@ -231,9 +265,11 @@ public class BaseArgoClient
231265
232266 protected readonly HttpClient HttpClient ;
233267
234- public BaseArgoClient ( HttpClient httpClient )
268+ protected readonly ILogger Logger ;
269+ public BaseArgoClient ( HttpClient httpClient , ILoggerFactory loggerFactory )
235270 {
236271 HttpClient = httpClient ;
272+ Logger = loggerFactory . CreateLogger ( "BaseArgoClient" ) ;
237273 }
238274
239275 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
250286 request . RequestUri = new Uri ( urlBuilder . ToString ( ) , UriKind . RelativeOrAbsolute ) ;
251287
252288 HttpResponseMessage ? response = null ;
289+ var logStringContent = stringContent == null ? string . Empty : await stringContent . ReadAsStringAsync ( ) ;
290+ Logger . CallingArgoHttpInfo ( request . RequestUri . ToString ( ) , method , logStringContent ) ;
253291 response = await HttpClient . SendAsync ( request , HttpCompletionOption . ResponseContentRead , cancellationToken ) . ConfigureAwait ( false ) ;
254292
255293 try
0 commit comments