Skip to content

Commit

Permalink
Added property key to Abstract.ScriptAdapter (#167)
Browse files Browse the repository at this point in the history
Also added impementation and tests to verify that existing functionality isn't changed
  • Loading branch information
kcathey committed Jan 16, 2019
1 parent a49be2a commit e69dffa
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 12 deletions.
10 changes: 10 additions & 0 deletions maestrowf/abstracts/interfaces/scriptadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,13 @@ def submit(self, step, path, cwd, job_map=None, env=None):
:returns: The return code of the submission command and job identiifer.
"""
pass

@property
@abstractmethod
def key(self):
"""
The key to be used in workflow specification to describe the adapter.
This is used to register the adapter in the ScriptAdapterFactory and when writing the workflow specification.
"""
pass
4 changes: 4 additions & 0 deletions maestrowf/interfaces/script/fluxscriptadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def get_environment():
class SpectrumFluxScriptAdapter(SchedulerScriptAdapter):
"""Interface class for the flux scheduler (on Spectrum MPI)."""

key = "flux-spectrum"

def __init__(self, **kwargs):
"""
Initialize an instance of the FluxScriptAdapter.
Expand Down Expand Up @@ -481,6 +483,8 @@ def _write_script(self, ws_path, step):
class FluxScriptAdapter(SchedulerScriptAdapter):
"""Interface class for the flux scheduler (on Spectrum MPI)."""

key = "flux"

def __init__(self, **kwargs):
"""
Initialize an instance of the FluxScriptAdapter.
Expand Down
2 changes: 2 additions & 0 deletions maestrowf/interfaces/script/localscriptadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@


class LocalScriptAdapter(ScriptAdapter):
key = "local"

"""
A ScriptAdapter class for interfacing for local execution.
"""
Expand Down
2 changes: 2 additions & 0 deletions maestrowf/interfaces/script/slurmscriptadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
class SlurmScriptAdapter(SchedulerScriptAdapter):
"""A ScriptAdapter class for interfacing with the SLURM scheduler."""

key = "slurm"

def __init__(self, **kwargs):
"""
Initialize an instance of the SlurmScriptAdapter.
Expand Down
28 changes: 28 additions & 0 deletions tests/interfaces/script/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
###############################################################################
# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory
# Written by Francesco Di Natale, dinatale3@llnl.gov.
#
# LLNL-CODE-734340
# All rights reserved.
# This file is part of MaestroWF, Version: 1.0.0.
#
# For details, see https://github.com/LLNL/maestrowf.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
37 changes: 37 additions & 0 deletions tests/interfaces/script/test_fluxscriptadapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###############################################################################
# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory
# Written by Francesco Di Natale, dinatale3@llnl.gov.
#
# LLNL-CODE-734340
# All rights reserved.
# This file is part of MaestroWF, Version: 1.0.0.
#
# For details, see https://github.com/LLNL/maestrowf.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
from maestrowf.interfaces.script.fluxscriptadapter import FluxScriptAdapter, SpectrumFluxScriptAdapter


def test_flux_adapter():
assert(FluxScriptAdapter.key == 'flux')


def test_flux_spectrum_adapter():
assert(SpectrumFluxScriptAdapter.key == 'flux-spectrum')
33 changes: 33 additions & 0 deletions tests/interfaces/script/test_localscriptadapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
###############################################################################
# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory
# Written by Francesco Di Natale, dinatale3@llnl.gov.
#
# LLNL-CODE-734340
# All rights reserved.
# This file is part of MaestroWF, Version: 1.0.0.
#
# For details, see https://github.com/LLNL/maestrowf.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
from maestrowf.interfaces.script.localscriptadapter import LocalScriptAdapter


def test_local_adapter():
assert(LocalScriptAdapter.key == 'local')
33 changes: 33 additions & 0 deletions tests/interfaces/script/test_slurmscriptadapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
###############################################################################
# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory
# Written by Francesco Di Natale, dinatale3@llnl.gov.
#
# LLNL-CODE-734340
# All rights reserved.
# This file is part of MaestroWF, Version: 1.0.0.
#
# For details, see https://github.com/LLNL/maestrowf.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
from maestrowf.interfaces.script.slurmscriptadapter import SlurmScriptAdapter


def test_slurm_adapter():
assert(SlurmScriptAdapter.key == 'slurm')
24 changes: 12 additions & 12 deletions tests/interfaces/test_script_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ def test_get_valid_adapters():

def test_local_adapter_in_factory():
saf = ScriptAdapterFactory
assert(saf.factories['local'] == LocalScriptAdapter)
assert('local' in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter('local') == LocalScriptAdapter)
assert(saf.factories[LocalScriptAdapter.key] == LocalScriptAdapter)
assert(LocalScriptAdapter.key in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter(LocalScriptAdapter.key) == LocalScriptAdapter)


def test_slurm_adapter_in_factory():
saf = ScriptAdapterFactory
assert(saf.factories['slurm'] == SlurmScriptAdapter)
assert('slurm' in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter('slurm') == SlurmScriptAdapter)
assert(saf.factories[SlurmScriptAdapter.key] == SlurmScriptAdapter)
assert(SlurmScriptAdapter.key in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter(SlurmScriptAdapter.key) == SlurmScriptAdapter)


def test_flux_adapter_in_factory():
saf = ScriptAdapterFactory
assert(saf.factories['flux'] == FluxScriptAdapter)
assert('flux' in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter('flux') == FluxScriptAdapter)
assert(saf.factories[FluxScriptAdapter.key] == FluxScriptAdapter)
assert(FluxScriptAdapter.key in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter(FluxScriptAdapter.key) == FluxScriptAdapter)


def test_flux_spectrum_adapter_in_factory():
saf = ScriptAdapterFactory
assert(saf.factories['flux-spectrum'] == SpectrumFluxScriptAdapter)
assert('flux-spectrum' in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter('flux-spectrum') == SpectrumFluxScriptAdapter)
assert(saf.factories[SpectrumFluxScriptAdapter.key] == SpectrumFluxScriptAdapter)
assert(SpectrumFluxScriptAdapter.key in ScriptAdapterFactory.get_valid_adapters())
assert(ScriptAdapterFactory.get_adapter(SpectrumFluxScriptAdapter.key) == SpectrumFluxScriptAdapter)

0 comments on commit e69dffa

Please sign in to comment.