Skip to content

Commit

Permalink
refactoring the result, receipt, report subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
ndenny committed Dec 3, 2024
1 parent bc22106 commit f48e6a5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 59 deletions.
33 changes: 17 additions & 16 deletions lib/Bastion/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,23 @@ def changed(self, *args):

def toJDN(self, **kwargs):
jdn = isReceipt.toJDN(self, **kwargs)
jdn['request']['result']['report'] = str(self)
jdn['request']['result']['report'] = self.body
return jdn

@property
def body(self):
if getattr(self, '_body', None) is None:
self._body = str(self)
#-- encode my object, if I have one, to a YAML string.
if self.record:
self._body = toJDN(self.record)
else:
self._body = ""
return self._body

def __str__(self):
return yaml.dump(self.toJDN(), default_flow_style = False, sort_keys = True)



class ReportException(Report):
def __init__(self, request, *args, **kwargs):
Expand All @@ -239,7 +247,7 @@ def __init__(self, request, *args, **kwargs):
status = args[0]
errobj = args[1]
else:
status = ReplyStatus.failed
status = ReplyStatus.Failed
errobj = args[0]

assert status.indicates_failure, "ReportException must be created with a reply status indicating failure"
Expand All @@ -251,33 +259,26 @@ def __init__(self, request, *args, **kwargs):
self.xname = type(xobj).__name__
self.xmsg = str(xobj)

def

def __str__(self):
return ''.join( traceback.format_exception(self.xobj) )




class Request(isRequest):
#-- Subclasses can set their own REPORT.
#-- This is used mostly in the convenience methods: .succeeded, .failed, etc.
REPORTS = { } #-- An optional mapping of ReplyStatus code to report class or function.

def succeeded(self, *args, **kwargs):
status = ReplyStatus.Ok
mkReport = self.REPORTS.get(status.code, Report)
return mkReport(self, status, *args, **kwargs)
return Report(self, ResultStatus.Ok, *args, **kwargs)

def failed(self, *args, **kwargs):
status = ReplyStatus.Failed
mkReport = self.REPORTS.get(status.code, Report)
return mkReport(self, status, *args, **kwargs)
return Report(self, ResultStatus.Failed, *args, **kwargs)

def crashed(self, *args, **kwargs):
status = ReplyStatus.Crashed
mkReport = self.REPORTS.get(status.code, Report)
return mkReport(self, status, *args, **kwargs)
return Report(self, ResultStatus.Crashed, *args, **kwargs)

def inconclusive(self, *args, **kwargs)
status = ReplyStatus.Inconclusive
mkReport = self.REPORTS.get(status.code, Report)
return mkReport(self, status, *args, **kwargs)
return Report(self, ResultStatus.Inconclusive, *args, **kwargs)
27 changes: 1 addition & 26 deletions lib/Bastion/Movers/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,7 @@
from Bastion.Common import Thing, Unknown
import Bastion.Model
from Bastion.Curator import Manifest, BLONDE, Snap
from Bastion.CARP import Request, Receipt


class PackRequest(Request):
REPORT = PackReport

def __init__(self, asset, spooled, basis = None, **kwargs):
Request.__init__(self, kwargs.get("action", "pack"))

self.context['asset'] = str(asset.CURIE)
self.context['halo'] = str(asset.halo)

if basis:
self.context['detail'] = 'D'
self.context['basis'] = str(kwargs['basis'])
self.context['whence'] = kwargs['whence'].isoformat()
if 'genus' in kwargs:
self.context['genus'] = kwargs['genus']
else:
self.context['detail'] = 'F'


class PackReport(Receipt):
def __init__(self, request, status, doc, obj = None, **kwargs):
Report.__init__(self, request, status, doc, obj, **kwargs)

from Bastion.CARP import Request, Receipt, ResultStatus


class PutRequest(Request):
Expand Down
3 changes: 1 addition & 2 deletions lib/Bastion/Movers/SFTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def provision(self, *args):
repo = self.scurler / ark.site / ark.zone / ark.asset
return repo.mkdir(parents = True, exist_ok = True)


def pack(self, asset, basis = None, **kwargs):
"""
Given a local asset, I package (.tar, .zip, etc) the asset into my scratch (spool) space.
Expand Down Expand Up @@ -110,7 +109,7 @@ def push(self, asset, basis = None, **kwargs):
"""
packed = self.pack(asset, basis, **kwargs)

xferrd = self.put(packed.spooled, packed.opts['tag'])
transferred = self.put(packed.spooled, packed.opts['tag'])

if transferred:
#-- clean up!
Expand Down
13 changes: 10 additions & 3 deletions lib/Bastion/Packers/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

logger = logging.getLogger(__name__)

class PackReport(Report):
def __init__(self, request, status, obj = None, **kwargs):
Report.__init__(self, request, status, obj, **kwargs)

class PackRequest(Bastion.CARP.Request):
def __init__(self, asset, basis = None, **kwargs):

class PackRequest(Request):
def __init__(self, asset, spooled, basis = None, **kwargs):
#-- Which asset will be packed?
#-- If differential backup, what basis is used for determining changes?
Request.__init__(self, kwargs.get("action", "pack"))
Expand All @@ -20,10 +24,13 @@ def __init__(self, asset, basis = None, **kwargs):

if basis:
self.context['detail'] = 'D'
self.context['basis'] = str(basis)
self.context['basis'] = str(kwargs['basis'])
self.context['whence'] = kwargs['whence'].isoformat()
if 'genus' in kwargs:
self.context['genus'] = kwargs['genus']
else:
self.context['detail'] = 'F'

def succeeded(self, catalog, *args, **kwargs):
return PackReport(self, ResultStatus.Ok, catalog)

12 changes: 0 additions & 12 deletions lib/Bastion/Vaults/SFTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ def bank(self):
#---------------------------------------
#-- BEGIN Bastion.Model.Vault PROTOCOL |
#↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
def provision(self, *args):
"""
provision(ark) - ensures that the site, zone, and asset folders exist.
provision(site, zone, asset_name) - an alias for provision(ark)
"""
if len(args) == 1:
return self._provision_ark( args[0] )
elif len(args) == 3:
return self._provision_site_zone_asset( args[0], args[1], args[2] )
else:
raise ValueError

def pack(self, asset, basis = None, **kwargs):
"""
Given a local asset, I package (.tar, .zip, etc) the asset into my scratch (spool) space.
Expand Down

0 comments on commit f48e6a5

Please sign in to comment.