mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-02-21 20:38:57 +00:00
fw/run: Implement Run Structures as Podable
Ensure that Run structures now have serialization versions. Also fix serialization/de-serialization of `Status` type as previously this was formatted as a String instead a pod.
This commit is contained in:
parent
8ee924b896
commit
1462f26b2e
@ -22,27 +22,34 @@ from copy import copy
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from wa.framework.configuration.core import Status
|
from wa.framework.configuration.core import Status
|
||||||
|
from wa.utils.serializer import Podable
|
||||||
|
|
||||||
|
|
||||||
class RunInfo(object):
|
class RunInfo(Podable):
|
||||||
"""
|
"""
|
||||||
Information about the current run, such as its unique ID, run
|
Information about the current run, such as its unique ID, run
|
||||||
time, etc.
|
time, etc.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
_pod_serialization_version = 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_pod(pod):
|
def from_pod(pod):
|
||||||
|
pod = RunInfo._upgrade_pod(pod)
|
||||||
uid = pod.pop('uuid')
|
uid = pod.pop('uuid')
|
||||||
|
_pod_version = pod.pop('_pod_version')
|
||||||
duration = pod.pop('duration')
|
duration = pod.pop('duration')
|
||||||
if uid is not None:
|
if uid is not None:
|
||||||
uid = uuid.UUID(uid)
|
uid = uuid.UUID(uid)
|
||||||
instance = RunInfo(**pod)
|
instance = RunInfo(**pod)
|
||||||
|
instance._pod_version = _pod_version # pylint: disable=protected-access
|
||||||
instance.uuid = uid
|
instance.uuid = uid
|
||||||
instance.duration = duration if duration is None else timedelta(seconds=duration)
|
instance.duration = duration if duration is None else timedelta(seconds=duration)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def __init__(self, run_name=None, project=None, project_stage=None,
|
def __init__(self, run_name=None, project=None, project_stage=None,
|
||||||
start_time=None, end_time=None, duration=None):
|
start_time=None, end_time=None, duration=None):
|
||||||
|
super(RunInfo, self).__init__()
|
||||||
self.uuid = uuid.uuid4()
|
self.uuid = uuid.uuid4()
|
||||||
self.run_name = run_name
|
self.run_name = run_name
|
||||||
self.project = project
|
self.project = project
|
||||||
@ -52,7 +59,8 @@ class RunInfo(object):
|
|||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
|
||||||
def to_pod(self):
|
def to_pod(self):
|
||||||
d = copy(self.__dict__)
|
d = super(RunInfo, self).to_pod()
|
||||||
|
d.update(copy(self.__dict__))
|
||||||
d['uuid'] = str(self.uuid)
|
d['uuid'] = str(self.uuid)
|
||||||
if self.duration is None:
|
if self.duration is None:
|
||||||
d['duration'] = self.duration
|
d['duration'] = self.duration
|
||||||
@ -60,16 +68,23 @@ class RunInfo(object):
|
|||||||
d['duration'] = self.duration.total_seconds()
|
d['duration'] = self.duration.total_seconds()
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _pod_upgrade_v1(pod):
|
||||||
|
pod['_pod_version'] = pod.get('_pod_version', 1)
|
||||||
|
return pod
|
||||||
|
|
||||||
class RunState(object):
|
|
||||||
|
class RunState(Podable):
|
||||||
"""
|
"""
|
||||||
Represents the state of a WA run.
|
Represents the state of a WA run.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
_pod_serialization_version = 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_pod(pod):
|
def from_pod(pod):
|
||||||
instance = RunState()
|
instance = super(RunState, RunState).from_pod(pod)
|
||||||
instance.status = Status(pod['status'])
|
instance.status = Status.from_pod(pod['status'])
|
||||||
instance.timestamp = pod['timestamp']
|
instance.timestamp = pod['timestamp']
|
||||||
jss = [JobState.from_pod(j) for j in pod['jobs']]
|
jss = [JobState.from_pod(j) for j in pod['jobs']]
|
||||||
instance.jobs = OrderedDict(((js.id, js.iteration), js) for js in jss)
|
instance.jobs = OrderedDict(((js.id, js.iteration), js) for js in jss)
|
||||||
@ -81,6 +96,7 @@ class RunState(object):
|
|||||||
if js.status > Status.RUNNING)
|
if js.status > Status.RUNNING)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
super(RunState, self).__init__()
|
||||||
self.jobs = OrderedDict()
|
self.jobs = OrderedDict()
|
||||||
self.status = Status.NEW
|
self.status = Status.NEW
|
||||||
self.timestamp = datetime.utcnow()
|
self.timestamp = datetime.utcnow()
|
||||||
@ -101,18 +117,28 @@ class RunState(object):
|
|||||||
return counter
|
return counter
|
||||||
|
|
||||||
def to_pod(self):
|
def to_pod(self):
|
||||||
return OrderedDict(
|
pod = super(RunState, self).to_pod()
|
||||||
status=str(self.status),
|
pod['status'] = self.status.to_pod()
|
||||||
timestamp=self.timestamp,
|
pod['timestamp'] = self.timestamp
|
||||||
jobs=[j.to_pod() for j in self.jobs.values()],
|
pod['jobs'] = [j.to_pod() for j in self.jobs.values()]
|
||||||
)
|
return pod
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _pod_upgrade_v1(pod):
|
||||||
|
pod['_pod_version'] = pod.get('_pod_version', 1)
|
||||||
|
pod['status'] = Status(pod['status']).to_pod()
|
||||||
|
return pod
|
||||||
|
|
||||||
|
|
||||||
class JobState(object):
|
class JobState(Podable):
|
||||||
|
|
||||||
|
_pod_serialization_version = 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_pod(pod):
|
def from_pod(pod):
|
||||||
instance = JobState(pod['id'], pod['label'], pod['iteration'], Status(pod['status']))
|
pod = JobState._upgrade_pod(pod)
|
||||||
|
instance = JobState(pod['id'], pod['label'], pod['iteration'],
|
||||||
|
Status.from_pod(pod['status']))
|
||||||
instance.retries = pod['retries']
|
instance.retries = pod['retries']
|
||||||
instance.timestamp = pod['timestamp']
|
instance.timestamp = pod['timestamp']
|
||||||
return instance
|
return instance
|
||||||
@ -123,6 +149,7 @@ class JobState(object):
|
|||||||
|
|
||||||
def __init__(self, id, label, iteration, status):
|
def __init__(self, id, label, iteration, status):
|
||||||
# pylint: disable=redefined-builtin
|
# pylint: disable=redefined-builtin
|
||||||
|
super(JobState, self).__init__()
|
||||||
self.id = id
|
self.id = id
|
||||||
self.label = label
|
self.label = label
|
||||||
self.iteration = iteration
|
self.iteration = iteration
|
||||||
@ -131,11 +158,17 @@ class JobState(object):
|
|||||||
self.timestamp = datetime.utcnow()
|
self.timestamp = datetime.utcnow()
|
||||||
|
|
||||||
def to_pod(self):
|
def to_pod(self):
|
||||||
return OrderedDict(
|
pod = super(JobState, self).to_pod()
|
||||||
id=self.id,
|
pod['id'] = self.id
|
||||||
label=self.label,
|
pod['label'] = self.label
|
||||||
iteration=self.iteration,
|
pod['iteration'] = self.iteration
|
||||||
status=str(self.status),
|
pod['status'] = self.status.to_pod()
|
||||||
retries=0,
|
pod['retries'] = 0
|
||||||
timestamp=self.timestamp,
|
pod['timestamp'] = self.timestamp
|
||||||
)
|
return pod
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _pod_upgrade_v1(pod):
|
||||||
|
pod['_pod_version'] = pod.get('_pod_version', 1)
|
||||||
|
pod['status'] = Status(pod['status']).to_pod()
|
||||||
|
return pod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user