From 8de0ce8f79d209a5dfbffd406512871e2679c21f Mon Sep 17 00:00:00 2001 From: nhertz <nhertz@nrao.edu> Date: Mon, 12 Oct 2020 14:04:33 -0600 Subject: [PATCH] Updated CapabilityStep class to support workflow arguments; updated null.cap with arguments --- services/capability/test/null.cap | 2 +- shared/workspaces/src/workspaces/helpers.py | 59 +++++++++++++-------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/services/capability/test/null.cap b/services/capability/test/null.cap index 06f70e35d..58399e70d 100644 --- a/services/capability/test/null.cap +++ b/services/capability/test/null.cap @@ -1,3 +1,3 @@ 0 null 2 -prepare-and-run-workflow null +prepare-and-run-workflow null -g await-parameter qa-status \ No newline at end of file diff --git a/shared/workspaces/src/workspaces/helpers.py b/shared/workspaces/src/workspaces/helpers.py index 69ef4884d..5e59fc378 100644 --- a/shared/workspaces/src/workspaces/helpers.py +++ b/shared/workspaces/src/workspaces/helpers.py @@ -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 -- GitLab