Skip to content

Commit

Permalink
fix(operator): simplified container field
Browse files Browse the repository at this point in the history
Replaced container field with image to minimize redundancy. Thank you @AntoineDao for pointing this out.
  • Loading branch information
mostaphaRoudsari committed Oct 24, 2019
1 parent 0bdfc8a commit 0fb923b
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 72 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ all the the `operators` that are referenced by `templates` should be included in
this section. Keep in mind that the operators are reusable and can be shared between
different templates.

An operator has two separate fields for `container` and `local`. The `container` field
An operator has two separate fields for container `image` and `local`. The `image` field
identifies the image for running a `template` and the `local` field identifies the
applications and libraries that this operator relies on to run locally.

Expand All @@ -103,9 +103,7 @@ pass a regex pattern which will be applied to the output of the command.

```yaml
- name: radiance-operator
container:
name: radiance52
image: ladybugtools/radiance:5.2
image: ladybugtools/radiance:5.2
local:
app:
- name: radiance
Expand All @@ -119,9 +117,7 @@ Here is another operator example for running `honeybee-radiance` commands.
```yaml
- name: honeybee-radiance
container:
name: honeybee-radiance
image: ladybugtools/honeybee-radiance-workflow:latest
image: ladybugtools/honeybee-radiance-workflow:latest
local:
app:
- name: radiance
Expand Down Expand Up @@ -156,9 +152,7 @@ In this example the content of `radiance_operator.yaml` can be something like th
```yaml
---
name: honeybee-radiance
container:
name: honeybee-radiance
image: ladybugtools/honeybee-radiance-workflow:latest
image: ladybugtools/honeybee-radiance-workflow:latest
local:
app:
- name: radiance
Expand Down Expand Up @@ -205,7 +199,7 @@ operator.
description: full path to output sky file
operator: radiance-operator
# commands and args will be used both locally and inside the container
# TODO: This will change to be platform specific
# TODO: This must change to be platform specific
command: gensky -c -B '{{ inputs.parameters.desired-irradiance }}' > '{{ inputs.parameters.sky-file }}'
outputs:
artifacts:
Expand Down
3 changes: 2 additions & 1 deletion queenbee/schema/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Parameter(BaseModel):
"""
name: str = Schema(
...,
description='Name is the parameter name.'
description='Name is the parameter name. must be unique within a task\'s '
'inputs / outputs.'
)

value: Any = Schema(
Expand Down
6 changes: 4 additions & 2 deletions queenbee/schema/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ class DAG(BaseModel):

target: str = Schema(
None,
description='Target are one or more names of targets to execute in a DAG. '
'Multiple targets can be specified as space delimited inputs.'
description='Target are one or more names of target tasks to execute in a DAG. '
'Multiple targets can be specified as space delimited inputs. When a target '
'is provided only a subset of tasks in DAG that are required to generate '
'the target(s) will be executed.'
)

fail_fast: bool = Schema(
Expand Down
8 changes: 7 additions & 1 deletion queenbee/schema/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ def check_output_referenced_values(cls, v, values):

@staticmethod
def validate_variable(variables, func_name, input_names):
"""Validate referenced variables."""
"""Validate referenced variables.
Referenced variables must follow x.y.z pattern and start with inputs, outputs or
workflow (e.g. inputs.parameters.filename).
This method is a helper that is used by other @validator classmethods.
"""
for m in variables:
try:
ref, typ, name = m.split('.')
Expand Down
48 changes: 17 additions & 31 deletions queenbee/schema/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,6 @@
from enum import Enum


class Container(BaseModel):
"""An operator container.
Container includes information for a [docker] image that the operator will use to run
the commands.
Unlike Argo, command and arguments are part of the template an not the operator
itself.
See here for more information about command and arguments for Docker images.
https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#containers-and-commands
"""
type: Enum('Container', {'type': 'Container'}) = 'Container'

name: str = Schema(
...,
description='Name of the container.'
)

image: str = Schema(
...,
description='Docker image name.'
)


class Language(BaseModel):
"""Required programming language."""
name: str = Schema(
Expand All @@ -48,7 +22,7 @@ class Language(BaseModel):

_valid_languages: Set[str] = set(['python', 'nodejs', 'bash'])

# NOTE: yaml convertion doesn't play well with Enum. Use validators like this
# NOTE: yaml conversion doesn't play well with Enum. Use validators like this
# instead.
@validator('name')
def check_language(cls, v):
Expand All @@ -63,14 +37,17 @@ def check_language(cls, v):
class App(BaseModel):
"""Local application."""
name: str = Schema(..., description='App name')

version: str = Schema(
None,
description='App version requirements. For instance >=5.2'
)

command: str = Schema(
...,
description='A command to check if application is installed'
)

pattern: str = Schema(
None,
description='An optional regex pattern to apply to command output.'
Expand All @@ -80,6 +57,7 @@ class App(BaseModel):
class Package(BaseModel):
"""A distribution package."""
name: str = Schema(..., description='Package name')

version: str = Schema(
None,
description='Package version requirements. For instance ==3.7 or >=3.6'
Expand Down Expand Up @@ -128,7 +106,7 @@ class LocalRequirements(BaseModel):
'https://docs.npmjs.com/cli/install#synopsis'
)

# NOTE: yaml convertion doesn't play well with Enum hence using a validator.
# NOTE: yaml conversion doesn't play well with Enum hence using a validator.
@validator('platform')
def check_platform(cls, v):
assert v.lower() in cls._valid_platforms, \
Expand All @@ -145,15 +123,23 @@ class Operator(BaseModel):
or in a container.
"""
type: Enum('Operator', {'type': 'Operator'}) = 'Operator'

name: str = Schema(
...,
description='Operator name. This name should be unique among all the operators'
' in your workflow.'
)
container: Container = Schema(

version: str = Schema(
None,
description='An optional [docker] container for executing task commands.'
)
description='Optional version input for operator.'
)

image: str = Schema(
...,
description='Docker image name.'
)

local: LocalRequirements = Schema(
None,
description='An optional requirement object to specify requirements for local'
Expand Down
1 change: 1 addition & 0 deletions queenbee/schema/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Workflow(BaseModel):

outputs: Arguments

# TODO: add a validator to ensure all the names for templates are unique
# @validator('flow')
# def check_templates(cls, v, values):
# """Check templates in flow to ensure they exist."""
Expand Down
4 changes: 1 addition & 3 deletions tests/assets/import_from/radiance_operator.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
name: radiance-operator
container:
name: radiance52
image: ladybugtools/radiance:5.2
image: ladybugtools/radiance:5.2
local:
app:
- name: radiance
Expand Down
4 changes: 1 addition & 3 deletions tests/assets/operator.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
# This file is generated by workerbee
name: honeybee-radiance
container:
name: honeybee-radiance
image: ladybugtools/honeybee-radiance-workflow:latest
image: ladybugtools/honeybee-radiance-workflow:latest
local:
app:
- name: radiance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"name": "honeybee-radiance-operator",
"container": {
"name": "honeybee_radiance",
"image": "ladybugtools/honeybee-radiance"
},
"image": "ladybugtools/honeybee-radiance",
"local": {
"app": [
{
Expand Down
4 changes: 1 addition & 3 deletions tests/assets/workflow_example/radiance_operator.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
name: radiance-operator
container:
name: radiance52
image: ladybugtools/radiance:5.2
image: ladybugtools/radiance:5.2
local:
app:
- name: radiance
Expand Down
5 changes: 2 additions & 3 deletions tests/schema/import_from_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def test_parser():
# check operator itself
operator = data['operators'][0]
assert operator['name'] == 'radiance-operator'
assert 'container' in operator
assert operator['container']['name'] == 'radiance52'
assert operator['container']['image'] == 'ladybugtools/radiance:5.2'
assert 'image' in operator
assert operator['image'] == 'ladybugtools/radiance:5.2'
assert 'local' in operator
assert 'app' in operator['local']
# check if app is loaded correctly
Expand Down
15 changes: 5 additions & 10 deletions tests/schema/operator_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from queenbee.schema.operator import Operator, Container, LocalRequirements
from queenbee.schema.operator import Operator, LocalRequirements
import yaml


Expand All @@ -8,11 +8,9 @@ def test_load_operator():

assert operator.name == 'honeybee-radiance'

# check container
container = operator.container
assert isinstance(container, Container)
container.name == 'honeybee-radiance'
container.image == 'ladybugtools/honeybee-radiance-workflow:latest'
# check image
image = operator.image
image == 'ladybugtools/honeybee-radiance-workflow:latest'

# more checks is not really helpful as successful load to Pydantic object means
# the object has been loaded correctly.
Expand All @@ -21,10 +19,7 @@ def test_load_operator():
def test_create_operator():
operator_dict = {
'name': 'honeybee-radiance',
'container': {
'name': 'honeybee-radiance',
'image': 'ladybugtools/honeybee-radiance-workflow:latest'
},
'image': 'ladybugtools/honeybee-radiance-workflow:latest',
'local': {
'app': [
{
Expand Down

0 comments on commit 0fb923b

Please sign in to comment.