66from typing import Optional
77
88from .. import result
9+ from ...management .export import _get_exports
910from ...management .export import ExportService
1011from ...management .export import ExportStatus
1112from ..handler import SQLHandler
@@ -187,7 +188,8 @@ def _start_export(params: Dict[str, Any]) -> Optional[FusionSQLResult]:
187188 order_by = order_by or None ,
188189 properties = json .loads (params ['properties' ]) if params ['properties' ] else None ,
189190 incremental = params .get ('incremental' , False ),
190- refresh_interval = refresh_interval_delta ,
191+ refresh_interval = int (refresh_interval_delta .total_seconds ())
192+ if refresh_interval_delta is not None else None ,
191193 ).start ()
192194
193195 res = FusionSQLResult ()
@@ -387,6 +389,25 @@ def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
387389StartIncrementalExport .register (overwrite = True )
388390
389391
392+ def _format_status (export_id : str , status : ExportStatus ) -> Optional [FusionSQLResult ]:
393+ """Return the status of an export operation."""
394+ info = status ._info ()
395+
396+ res = FusionSQLResult ()
397+ res .add_field ('ExportID' , result .STRING )
398+ res .add_field ('Status' , result .STRING )
399+ res .add_field ('Message' , result .STRING )
400+ res .set_rows ([
401+ (
402+ export_id ,
403+ info .get ('status' , 'Unknown' ),
404+ info .get ('statusMsg' , '' ),
405+ ),
406+ ])
407+
408+ return res
409+
410+
390411class ShowExport (SQLHandler ):
391412 """
392413 SHOW EXPORT export_id;
@@ -400,31 +421,92 @@ class ShowExport(SQLHandler):
400421
401422 def run (self , params : Dict [str , Any ]) -> Optional [FusionSQLResult ]:
402423 wsg = get_workspace_group ({})
403- out = ExportStatus (params ['export_id' ], wsg )
424+ return _format_status (
425+ params ['export_id' ], ExportStatus (params ['export_id' ], wsg ),
426+ )
404427
405- status = out ._info ()
428+
429+ ShowExport .register (overwrite = True )
430+
431+
432+ class ShowExports (SQLHandler ):
433+ """
434+ SHOW EXPORTS [ scope ];
435+
436+ # Location of the export
437+ scope = FOR '<scope>'
438+
439+ """
440+
441+ _enabled = False
442+
443+ def run (self , params : Dict [str , Any ]) -> Optional [FusionSQLResult ]:
444+ wsg = get_workspace_group ({})
445+
446+ exports = _get_exports (wsg , params .get ('scope' , 'all' ))
406447
407448 res = FusionSQLResult ()
408449 res .add_field ('ExportID' , result .STRING )
409450 res .add_field ('Status' , result .STRING )
410451 res .add_field ('Message' , result .STRING )
411452 res .set_rows ([
412453 (
413- params ['export_id' ],
414- status .get ('status' , 'Unknown' ),
415- status .get ('statusMsg' , '' ),
416- ),
454+ info ['egressID' ],
455+ info .get ('status' , 'Unknown' ),
456+ info .get ('statusMsg' , '' ),
457+ )
458+ for info in [x ._info () for x in exports ]
417459 ])
418460
419461 return res
420462
421463
422- ShowExport .register (overwrite = True )
464+ ShowExports .register (overwrite = True )
465+
466+
467+ class SuspendExport (SQLHandler ):
468+ """
469+ SUSPEND EXPORT export_id;
470+
471+ # ID of export
472+ export_id = '<export-id>'
473+
474+ """
475+
476+ _enabled = False
477+
478+ def run (self , params : Dict [str , Any ]) -> Optional [FusionSQLResult ]:
479+ wsg = get_workspace_group ({})
480+ service = ExportService .from_export_id (wsg , params ['export_id' ])
481+ return _format_status (params ['export_id' ], service .suspend ())
482+
483+
484+ SuspendExport .register (overwrite = True )
485+
486+
487+ class ResumeExport (SQLHandler ):
488+ """
489+ RESUME EXPORT export_id;
490+
491+ # ID of export
492+ export_id = '<export-id>'
493+
494+ """
495+
496+ _enabled = False
497+
498+ def run (self , params : Dict [str , Any ]) -> Optional [FusionSQLResult ]:
499+ wsg = get_workspace_group ({})
500+ service = ExportService .from_export_id (wsg , params ['export_id' ])
501+ return _format_status (params ['export_id' ], service .resume ())
502+
503+
504+ ResumeExport .register (overwrite = True )
423505
424506
425- class StopExport (SQLHandler ):
507+ class DropExport (SQLHandler ):
426508 """
427- STOP EXPORT export_id;
509+ DROP EXPORT export_id;
428510
429511 # ID of export
430512 export_id = '<export-id>'
@@ -436,8 +518,8 @@ class StopExport(SQLHandler):
436518 def run (self , params : Dict [str , Any ]) -> Optional [FusionSQLResult ]:
437519 wsg = get_workspace_group ({})
438520 service = ExportService .from_export_id (wsg , params ['export_id' ])
439- service .stop ()
521+ service .drop ()
440522 return None
441523
442524
443- StopExport .register (overwrite = True )
525+ DropExport .register (overwrite = True )
0 commit comments