@@ -2,18 +2,14 @@ use anyhow::{Context, Result};
2
2
use spin_core:: wasmtime:: component:: ResourceTable ;
3
3
use spin_core:: { async_trait, wasmtime:: component:: Resource } ;
4
4
use spin_resource_table:: Table ;
5
- use spin_world:: wasi:: blobstore;
5
+ use spin_world:: wasi:: blobstore:: { self as bs } ;
6
6
use std:: { collections:: HashSet , sync:: Arc } ;
7
7
use tokio:: io:: { ReadHalf , SimplexStream , WriteHalf } ;
8
8
use tokio:: sync:: mpsc;
9
9
use tokio:: sync:: RwLock ;
10
10
use wasmtime_wasi:: WasiView ;
11
11
12
- use blobstore:: blobstore:: { self as wb} ;
13
- use blobstore:: container:: { self as wbc} ;
14
- use blobstore:: types:: { self as wbt} ;
15
-
16
- pub use wbt:: Error ;
12
+ pub use bs:: types:: Error ;
17
13
18
14
#[ async_trait]
19
15
pub trait ContainerManager : Sync + Send {
@@ -33,12 +29,12 @@ pub trait ContainerManager: Sync + Send {
33
29
pub trait Container : Sync + Send {
34
30
async fn exists ( & self ) -> anyhow:: Result < bool > ;
35
31
async fn name ( & self ) -> String ;
36
- async fn info ( & self ) -> anyhow:: Result < wbt :: ContainerMetadata > ;
32
+ async fn info ( & self ) -> anyhow:: Result < bs :: types :: ContainerMetadata > ;
37
33
async fn clear ( & self ) -> anyhow:: Result < ( ) > ;
38
34
async fn delete_object ( & self , name : & str ) -> anyhow:: Result < ( ) > ;
39
35
async fn delete_objects ( & self , names : & [ String ] ) -> anyhow:: Result < ( ) > ;
40
36
async fn has_object ( & self , name : & str ) -> anyhow:: Result < bool > ;
41
- async fn object_info ( & self , name : & str ) -> anyhow:: Result < wbt :: ObjectMetadata > ;
37
+ async fn object_info ( & self , name : & str ) -> anyhow:: Result < bs :: types :: ObjectMetadata > ;
42
38
async fn get_data (
43
39
& self ,
44
40
name : & str ,
@@ -176,7 +172,7 @@ impl<'a> BlobStoreDispatch<'a> {
176
172
177
173
pub async fn get_container (
178
174
& self ,
179
- container : Resource < wb :: Container > ,
175
+ container : Resource < bs :: blobstore :: Container > ,
180
176
) -> anyhow:: Result < Arc < dyn Container > > {
181
177
self . containers
182
178
. read ( )
@@ -192,7 +188,7 @@ impl<'a> BlobStoreDispatch<'a> {
192
188
193
189
async fn take_incoming_value (
194
190
& mut self ,
195
- resource : Resource < wbc :: IncomingValue > ,
191
+ resource : Resource < bs :: container :: IncomingValue > ,
196
192
) -> Result < Box < dyn IncomingData > , String > {
197
193
self . incoming_values
198
194
. write ( )
@@ -202,15 +198,18 @@ impl<'a> BlobStoreDispatch<'a> {
202
198
}
203
199
}
204
200
205
- impl wb :: Host for BlobStoreDispatch < ' _ > {
201
+ impl bs :: blobstore :: Host for BlobStoreDispatch < ' _ > {
206
202
async fn create_container (
207
203
& mut self ,
208
204
_name : String ,
209
- ) -> Result < Resource < wbc :: Container > , String > {
205
+ ) -> Result < Resource < bs :: container :: Container > , String > {
210
206
Err ( "This version of Spin does not support creating containers" . to_owned ( ) )
211
207
}
212
208
213
- async fn get_container ( & mut self , name : String ) -> Result < Resource < wbc:: Container > , String > {
209
+ async fn get_container (
210
+ & mut self ,
211
+ name : String ,
212
+ ) -> Result < Resource < bs:: container:: Container > , String > {
214
213
if self . allowed_containers . contains ( & name) {
215
214
let container = self . manager . get ( & name) . await ?;
216
215
let rep = self . containers . write ( ) . await . push ( container) . unwrap ( ) ;
@@ -233,25 +232,33 @@ impl wb::Host for BlobStoreDispatch<'_> {
233
232
}
234
233
}
235
234
236
- async fn copy_object ( & mut self , _src : wb:: ObjectId , _dest : wb:: ObjectId ) -> Result < ( ) , String > {
235
+ async fn copy_object (
236
+ & mut self ,
237
+ _src : bs:: blobstore:: ObjectId ,
238
+ _dest : bs:: blobstore:: ObjectId ,
239
+ ) -> Result < ( ) , String > {
237
240
Err ( "This version of Spin does not support copying objects" . to_owned ( ) )
238
241
}
239
242
240
- async fn move_object ( & mut self , _src : wb:: ObjectId , _dest : wb:: ObjectId ) -> Result < ( ) , String > {
243
+ async fn move_object (
244
+ & mut self ,
245
+ _src : bs:: blobstore:: ObjectId ,
246
+ _dest : bs:: blobstore:: ObjectId ,
247
+ ) -> Result < ( ) , String > {
241
248
Err ( "This version of Spin does not support moving objects" . to_owned ( ) )
242
249
}
243
250
}
244
251
245
- impl wbt :: Host for BlobStoreDispatch < ' _ > {
252
+ impl bs :: types :: Host for BlobStoreDispatch < ' _ > {
246
253
fn convert_error ( & mut self , error : String ) -> anyhow:: Result < String > {
247
254
Ok ( error)
248
255
}
249
256
}
250
257
251
- impl wbt :: HostIncomingValue for BlobStoreDispatch < ' _ > {
258
+ impl bs :: types :: HostIncomingValue for BlobStoreDispatch < ' _ > {
252
259
async fn incoming_value_consume_sync (
253
260
& mut self ,
254
- self_ : Resource < wbt :: IncomingValue > ,
261
+ self_ : Resource < bs :: types :: IncomingValue > ,
255
262
) -> Result < Vec < u8 > , String > {
256
263
let mut incoming = self . take_incoming_value ( self_) . await ?;
257
264
incoming
@@ -263,7 +270,7 @@ impl wbt::HostIncomingValue for BlobStoreDispatch<'_> {
263
270
264
271
async fn incoming_value_consume_async (
265
272
& mut self ,
266
- self_ : Resource < wbt :: IncomingValue > ,
273
+ self_ : Resource < bs :: types :: IncomingValue > ,
267
274
) -> Result < Resource < wasmtime_wasi:: InputStream > , String > {
268
275
let mut incoming = self . take_incoming_value ( self_) . await ?;
269
276
let async_body = incoming. as_mut ( ) . consume_async ( ) ;
@@ -272,22 +279,22 @@ impl wbt::HostIncomingValue for BlobStoreDispatch<'_> {
272
279
Ok ( resource)
273
280
}
274
281
275
- async fn size ( & mut self , self_ : Resource < wbt :: IncomingValue > ) -> anyhow:: Result < u64 > {
282
+ async fn size ( & mut self , self_ : Resource < bs :: types :: IncomingValue > ) -> anyhow:: Result < u64 > {
276
283
let mut lock = self . incoming_values . write ( ) . await ;
277
284
let incoming = lock
278
285
. get_mut ( self_. rep ( ) )
279
286
. ok_or_else ( || anyhow:: anyhow!( "invalid incoming-value resource" ) ) ?;
280
287
incoming. size ( ) . await
281
288
}
282
289
283
- async fn drop ( & mut self , rep : Resource < wbt :: IncomingValue > ) -> anyhow:: Result < ( ) > {
290
+ async fn drop ( & mut self , rep : Resource < bs :: types :: IncomingValue > ) -> anyhow:: Result < ( ) > {
284
291
self . incoming_values . write ( ) . await . remove ( rep. rep ( ) ) ;
285
292
Ok ( ( ) )
286
293
}
287
294
}
288
295
289
- impl wbt :: HostOutgoingValue for BlobStoreDispatch < ' _ > {
290
- async fn new_outgoing_value ( & mut self ) -> anyhow:: Result < Resource < wbt :: OutgoingValue > > {
296
+ impl bs :: types :: HostOutgoingValue for BlobStoreDispatch < ' _ > {
297
+ async fn new_outgoing_value ( & mut self ) -> anyhow:: Result < Resource < bs :: types :: OutgoingValue > > {
291
298
let outgoing_value = OutgoingValue :: new ( ) ;
292
299
let rep = self
293
300
. outgoing_values
@@ -300,7 +307,7 @@ impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
300
307
301
308
async fn outgoing_value_write_body (
302
309
& mut self ,
303
- self_ : Resource < wbt :: OutgoingValue > ,
310
+ self_ : Resource < bs :: types :: OutgoingValue > ,
304
311
) -> anyhow:: Result < Result < Resource < wasmtime_wasi:: OutputStream > , ( ) > > {
305
312
let mut lock = self . outgoing_values . write ( ) . await ;
306
313
let outgoing = lock
@@ -314,7 +321,7 @@ impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
314
321
Ok ( Ok ( resource) )
315
322
}
316
323
317
- async fn finish ( & mut self , self_ : Resource < wbt :: OutgoingValue > ) -> Result < ( ) , String > {
324
+ async fn finish ( & mut self , self_ : Resource < bs :: types :: OutgoingValue > ) -> Result < ( ) , String > {
318
325
let mut lock = self . outgoing_values . write ( ) . await ;
319
326
let outgoing = lock
320
327
. get_mut ( self_. rep ( ) )
@@ -333,17 +340,17 @@ impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
333
340
}
334
341
}
335
342
336
- async fn drop ( & mut self , rep : Resource < wbt :: OutgoingValue > ) -> anyhow:: Result < ( ) > {
343
+ async fn drop ( & mut self , rep : Resource < bs :: types :: OutgoingValue > ) -> anyhow:: Result < ( ) > {
337
344
self . outgoing_values . write ( ) . await . remove ( rep. rep ( ) ) ;
338
345
Ok ( ( ) )
339
346
}
340
347
}
341
348
342
349
// TODO: TBD if these belong on BSD or some other struct (like the one that maps to a Container resource JUST SAYIN)
343
- impl wbc :: Host for BlobStoreDispatch < ' _ > { }
350
+ impl bs :: container :: Host for BlobStoreDispatch < ' _ > { }
344
351
345
- impl wbc :: HostContainer for BlobStoreDispatch < ' _ > {
346
- async fn name ( & mut self , self_ : Resource < wbc :: Container > ) -> Result < String , String > {
352
+ impl bs :: container :: HostContainer for BlobStoreDispatch < ' _ > {
353
+ async fn name ( & mut self , self_ : Resource < bs :: container :: Container > ) -> Result < String , String > {
347
354
let lock = self . containers . read ( ) . await ;
348
355
let container = lock
349
356
. get ( self_. rep ( ) )
@@ -353,8 +360,8 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
353
360
354
361
async fn info (
355
362
& mut self ,
356
- self_ : Resource < wbc :: Container > ,
357
- ) -> Result < wbc :: ContainerMetadata , String > {
363
+ self_ : Resource < bs :: container :: Container > ,
364
+ ) -> Result < bs :: container :: ContainerMetadata , String > {
358
365
let lock = self . containers . read ( ) . await ;
359
366
let container = lock
360
367
. get ( self_. rep ( ) )
@@ -364,11 +371,11 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
364
371
365
372
async fn get_data (
366
373
& mut self ,
367
- self_ : Resource < wbc :: Container > ,
368
- name : wbc :: ObjectName ,
374
+ self_ : Resource < bs :: container :: Container > ,
375
+ name : bs :: container :: ObjectName ,
369
376
start : u64 ,
370
377
end : u64 ,
371
- ) -> Result < Resource < wbt :: IncomingValue > , String > {
378
+ ) -> Result < Resource < bs :: types :: IncomingValue > , String > {
372
379
let lock = self . containers . read ( ) . await ;
373
380
let container = lock
374
381
. get ( self_. rep ( ) )
@@ -383,9 +390,9 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
383
390
384
391
async fn write_data (
385
392
& mut self ,
386
- self_ : Resource < wbc :: Container > ,
387
- name : wbc :: ObjectName ,
388
- data : Resource < wbt :: OutgoingValue > ,
393
+ self_ : Resource < bs :: container :: Container > ,
394
+ name : bs :: container :: ObjectName ,
395
+ data : Resource < bs :: types :: OutgoingValue > ,
389
396
) -> Result < ( ) , String > {
390
397
let lock = self . containers . read ( ) . await ;
391
398
let container = lock
@@ -407,8 +414,8 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
407
414
408
415
async fn list_objects (
409
416
& mut self ,
410
- self_ : Resource < wbc :: Container > ,
411
- ) -> Result < Resource < wbc :: StreamObjectNames > , String > {
417
+ self_ : Resource < bs :: container :: Container > ,
418
+ ) -> Result < Resource < bs :: container :: StreamObjectNames > , String > {
412
419
let lock = self . containers . read ( ) . await ;
413
420
let container = lock
414
421
. get ( self_. rep ( ) )
@@ -420,7 +427,7 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
420
427
421
428
async fn delete_object (
422
429
& mut self ,
423
- self_ : Resource < wbc :: Container > ,
430
+ self_ : Resource < bs :: container :: Container > ,
424
431
name : String ,
425
432
) -> Result < ( ) , String > {
426
433
let lock = self . containers . read ( ) . await ;
@@ -435,7 +442,7 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
435
442
436
443
async fn delete_objects (
437
444
& mut self ,
438
- self_ : Resource < wbc :: Container > ,
445
+ self_ : Resource < bs :: container :: Container > ,
439
446
names : Vec < String > ,
440
447
) -> Result < ( ) , String > {
441
448
let lock = self . containers . read ( ) . await ;
@@ -450,7 +457,7 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
450
457
451
458
async fn has_object (
452
459
& mut self ,
453
- self_ : Resource < wbc :: Container > ,
460
+ self_ : Resource < bs :: container :: Container > ,
454
461
name : String ,
455
462
) -> Result < bool , String > {
456
463
let lock = self . containers . read ( ) . await ;
@@ -462,9 +469,9 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
462
469
463
470
async fn object_info (
464
471
& mut self ,
465
- self_ : Resource < wbc :: Container > ,
472
+ self_ : Resource < bs :: container :: Container > ,
466
473
name : String ,
467
- ) -> Result < wbt :: ObjectMetadata , String > {
474
+ ) -> Result < bs :: types :: ObjectMetadata , String > {
468
475
let lock = self . containers . read ( ) . await ;
469
476
let container = lock
470
477
. get ( self_. rep ( ) )
@@ -475,24 +482,24 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
475
482
. map_err ( |e| e. to_string ( ) )
476
483
}
477
484
478
- async fn clear ( & mut self , self_ : Resource < wbc :: Container > ) -> Result < ( ) , String > {
485
+ async fn clear ( & mut self , self_ : Resource < bs :: container :: Container > ) -> Result < ( ) , String > {
479
486
let lock = self . containers . read ( ) . await ;
480
487
let container = lock
481
488
. get ( self_. rep ( ) )
482
489
. ok_or_else ( || "invalid container resource" . to_string ( ) ) ?;
483
490
container. clear ( ) . await . map_err ( |e| e. to_string ( ) )
484
491
}
485
492
486
- async fn drop ( & mut self , rep : Resource < wbc :: Container > ) -> anyhow:: Result < ( ) > {
493
+ async fn drop ( & mut self , rep : Resource < bs :: container :: Container > ) -> anyhow:: Result < ( ) > {
487
494
self . containers . write ( ) . await . remove ( rep. rep ( ) ) ;
488
495
Ok ( ( ) )
489
496
}
490
497
}
491
498
492
- impl wbc :: HostStreamObjectNames for BlobStoreDispatch < ' _ > {
499
+ impl bs :: container :: HostStreamObjectNames for BlobStoreDispatch < ' _ > {
493
500
async fn read_stream_object_names (
494
501
& mut self ,
495
- self_ : Resource < wbc :: StreamObjectNames > ,
502
+ self_ : Resource < bs :: container :: StreamObjectNames > ,
496
503
len : u64 ,
497
504
) -> Result < ( Vec < String > , bool ) , String > {
498
505
let mut lock = self . object_names . write ( ) . await ;
@@ -504,7 +511,7 @@ impl wbc::HostStreamObjectNames for BlobStoreDispatch<'_> {
504
511
505
512
async fn skip_stream_object_names (
506
513
& mut self ,
507
- self_ : Resource < wbc :: StreamObjectNames > ,
514
+ self_ : Resource < bs :: container :: StreamObjectNames > ,
508
515
num : u64 ,
509
516
) -> Result < ( u64 , bool ) , String > {
510
517
let mut lock = self . object_names . write ( ) . await ;
@@ -514,7 +521,10 @@ impl wbc::HostStreamObjectNames for BlobStoreDispatch<'_> {
514
521
object_names. skip ( num) . await . map_err ( |e| e. to_string ( ) )
515
522
}
516
523
517
- async fn drop ( & mut self , rep : Resource < wbc:: StreamObjectNames > ) -> anyhow:: Result < ( ) > {
524
+ async fn drop (
525
+ & mut self ,
526
+ rep : Resource < bs:: container:: StreamObjectNames > ,
527
+ ) -> anyhow:: Result < ( ) > {
518
528
self . object_names . write ( ) . await . remove ( rep. rep ( ) ) ;
519
529
Ok ( ( ) )
520
530
}
0 commit comments