@@ -31,6 +31,7 @@ use nexus_types::internal_api::params::SwitchPutRequest;
31
31
use nexus_types:: internal_api:: params:: SwitchPutResponse ;
32
32
use nexus_types:: internal_api:: views:: to_list;
33
33
use nexus_types:: internal_api:: views:: BackgroundTask ;
34
+ use nexus_types:: internal_api:: views:: HandleInstancePutResultResult ;
34
35
use nexus_types:: internal_api:: views:: Saga ;
35
36
use omicron_common:: api:: external:: http_pagination:: data_page_params_for;
36
37
use omicron_common:: api:: external:: http_pagination:: PaginatedById ;
@@ -283,42 +284,55 @@ async fn cpapi_instances_put(
283
284
apictx. internal_latencies . instrument_dropshot_handler ( & rqctx, handler) . await
284
285
}
285
286
286
- /// Asynchronously report the successful result of a potentially long-running
287
- /// instance_put call to sled-agent made during instance creation.
287
+ /// Asynchronously report the successful result of certain instance_put calls
288
+ /// (such as the potentially long-running one made during instance creation)
288
289
#[ endpoint {
289
- method = PUT ,
290
- path = "/instances/{instance_id}/creation-success" ,
291
- } ]
290
+ method = PUT ,
291
+ path = "/instances/{instance_id}/creation-success" ,
292
+ } ]
292
293
async fn cpapi_handle_instance_put_success (
293
294
rqctx : RequestContext < Arc < ServerContext > > ,
294
295
path_params : Path < InstancePathParam > ,
295
296
instance_state : TypedBody < SledInstanceState > ,
296
- ) -> Result < HttpResponseUpdatedNoContent , HttpError > {
297
+ ) -> Result < HttpResponseOk < HandleInstancePutResultResult > , HttpError > {
297
298
let apictx = rqctx. context ( ) ;
298
299
let nexus = & apictx. nexus ;
299
300
let path = path_params. into_inner ( ) ;
300
301
let result = Ok ( instance_state. into_inner ( ) ) ;
301
302
let opctx = crate :: context:: op_context_for_internal_api ( & rqctx) . await ;
302
303
let handler = async {
303
- nexus
304
+ // TODO: if instance_handle_creation_result errors because nexus gave
305
+ // up waiting and marked the instance as failed, tell sled-agent to
306
+ // destroy the instance
307
+ match nexus
304
308
. instance_handle_creation_result ( & opctx, & path. instance_id , result)
305
- . await ?;
309
+ . await
310
+ {
311
+ Ok ( _) => Ok ( HandleInstancePutResultResult :: Ok . into ( ) ) ,
312
+ Err ( err) => {
313
+ if todo {
314
+ Ok ( HandleInstancePutResultResult :: TimedOut . into ( ) )
315
+ } else {
316
+ Err ( err)
317
+ }
318
+ }
319
+ }
306
320
Ok ( HttpResponseUpdatedNoContent ( ) )
307
321
} ;
308
322
apictx. internal_latencies . instrument_dropshot_handler ( & rqctx, handler) . await
309
323
}
310
324
311
- /// Asynchronously report the unsuccessful result of a potentially long-running
312
- /// instance_put call to sled-agent made during instance creation.
325
+ /// Asynchronously report the unsuccessful result of certain instance_put calls
326
+ /// (such as the potentially long-running one made during instance creation)
313
327
#[ endpoint {
314
- method = PUT ,
315
- path = "/instances/{instance_id}/creation-failure" ,
316
- } ]
328
+ method = PUT ,
329
+ path = "/instances/{instance_id}/creation-failure" ,
330
+ } ]
317
331
async fn cpapi_handle_instance_put_failure (
318
332
rqctx : RequestContext < Arc < ServerContext > > ,
319
333
path_params : Path < InstancePathParam > ,
320
334
error : TypedBody < String > ,
321
- ) -> Result < HttpResponseUpdatedNoContent , HttpError > {
335
+ ) -> Result < HttpResponseOk < HandleInstancePutResultResult > , HttpError > {
322
336
let apictx = rqctx. context ( ) ;
323
337
let nexus = & apictx. nexus ;
324
338
let path = path_params. into_inner ( ) ;
@@ -327,10 +341,19 @@ async fn cpapi_handle_instance_put_failure(
327
341
} ) ;
328
342
let opctx = crate :: context:: op_context_for_internal_api ( & rqctx) . await ;
329
343
let handler = async {
330
- nexus
344
+ match nexus
331
345
. instance_handle_creation_result ( & opctx, & path. instance_id , result)
332
- . await ?;
333
- Ok ( HttpResponseUpdatedNoContent ( ) )
346
+ . await
347
+ {
348
+ Ok ( _) => Ok ( HandleInstancePutResultResult :: Ok . into ( ) ) ,
349
+ Err ( err) => {
350
+ if todo {
351
+ Ok ( HandleInstancePutResultResult :: TimedOut . into ( ) )
352
+ } else {
353
+ Err ( err)
354
+ }
355
+ }
356
+ }
334
357
} ;
335
358
apictx. internal_latencies . instrument_dropshot_handler ( & rqctx, handler) . await
336
359
}
0 commit comments