Skip to content
Snippets Groups Projects
Commit 8de0ce8f authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Updated CapabilityStep class to support workflow arguments; updated

null.cap with arguments
parent dc5a49ea
No related branches found
No related tags found
No related merge requests found
0 null 2
prepare-and-run-workflow null
prepare-and-run-workflow null -g
await-parameter qa-status
\ No newline at end of file
......@@ -3,8 +3,12 @@ from __future__ import annotations
from enum import Enum, auto
from typing import Optional, List, Iterator
from .capability_interfaces import ParameterIF, CapabilityStepIF, CapabilitySequenceIF, \
CapabilityRequestIF
from .capability_interfaces import (
ParameterIF,
CapabilityStepIF,
CapabilitySequenceIF,
CapabilityRequestIF,
)
from .product_interfaces import FutureProductIF
......@@ -13,36 +17,44 @@ class CapabilityStep(CapabilityStepIF):
Class that represents a step in a capability sequence. A step is of a certain type and
certain step types can have a value
"""
def __init__(self, step_type: CapabilityStepType, step_value: Optional[str]):
def __init__(
self,
step_type: CapabilityStepType,
step_value: Optional[str],
step_args: Optional[str],
):
self.step_type = step_type
self.step_value = step_value
self.step_args = step_args
@classmethod
def from_str(cls, step_string: str):
"""
Create CapabilityStep from string containing space-separated step type and step value
Create CapabilityStep from string containing space-separated type, value, and args
:param step_string: String of capability step, e.g. "PrepareAndRunWorkflow null"
:return: CapabilityStep of given string
"""
step_list = step_string.split(' ')
step_list = step_string.split(" ")
step_type = CapabilityStepType.from_string(step_list[0])
if step_list[1]:
step_value = step_list[1]
else:
step_value = None
return cls(step_type, step_value)
step_value = step_list[1] if step_list[1] else None
step_args = step_list[2] if step_list[2] else None
return cls(step_type, step_value, step_args)
def __str__(self):
string = f"{self.step_type.name}"
if self.step_value:
return f'{self.step_type.name} {self.step_value}'
else:
return f'{self.step_type.name}'
string += f" {self.step_value}"
elif self.step_args:
string += f" {self.step_args}"
return string
class CapabilitySequence(CapabilitySequenceIF):
"""
Class that represents a capability sequence with a list of steps
"""
def __init__(self, steps: List[CapabilityStep]):
self.steps = steps
......@@ -54,7 +66,7 @@ class CapabilitySequence(CapabilitySequenceIF):
:return: CapabilitySequence of given steps
"""
steps = []
for step in sequence_str.split(','):
for step in sequence_str.split(","):
steps.append(CapabilityStep.from_str(step))
return cls(steps)
......@@ -82,7 +94,7 @@ class CapabilitySequence(CapabilitySequenceIF):
:return: String representation
"""
str_steps = [str(step) for step in self]
return ','.join(str_steps)
return ",".join(str_steps)
class Parameter(ParameterIF):
......@@ -97,6 +109,7 @@ class CapabilityStepType(Enum):
"""
Enum that specifies the types of CapabilitySteps that are possible
"""
PrepareAndRunWorkflow = 0
AwaitQA = 1
AwaitWorkflow = 2
......@@ -108,12 +121,12 @@ class CapabilityStepType(Enum):
def from_string(cls, string: str) -> CapabilityStepType:
print(string)
strings = {
'prepare-and-run-workflow': cls.PrepareAndRunWorkflow,
'await-qa': cls.AwaitQA,
'await-workflow': cls.AwaitWorkflow,
'await-product': cls.AwaitProduct,
'await-parameter': cls.AwaitParameter,
'await-large-alloc-approval': cls.AwaitLargeAllocApproval
"prepare-and-run-workflow": cls.PrepareAndRunWorkflow,
"await-qa": cls.AwaitQA,
"await-workflow": cls.AwaitWorkflow,
"await-product": cls.AwaitProduct,
"await-parameter": cls.AwaitParameter,
"await-large-alloc-approval": cls.AwaitLargeAllocApproval,
}
return strings[string]
......@@ -122,6 +135,7 @@ class CapabilityEventType(Enum):
"""
Enum that specifies the type of CapabilityEvents possible to send
"""
WorkflowComplete = 0
QaApproval = 1
QaDenial = 1
......@@ -136,6 +150,7 @@ class RequestState(Enum):
"""
Enum that specifies the states that a capability request can be in
"""
Complete = 0
Executing = 1
Ready = 2
......@@ -146,6 +161,7 @@ class ExecutionState(Enum):
"""
Enum that specifies the states that a capability execution can find itself in
"""
Complete = 0
ExecutingStep = 1
Ready = 2
......@@ -157,6 +173,7 @@ class ExecutionPriority(Enum):
"""
Enum that specifies the priority of a particular capability execution
"""
High = 25
Default = 50
Low = 100
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment