Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from collections import Mapping
from contextlib import contextmanager
from pystachio import Required, String
from twitter.common.collections import maybe_list
from .cluster import Cluster
__all__ = (
'CLUSTERS',
'Clusters',
)
class NameTrait(Cluster.Trait):
name = Required(String) # noqa
class Clusters(Mapping):
class Error(Exception): pass
class ClusterExists(Error): pass
class ClusterNotFound(KeyError, Error): pass
class UnknownFormatError(Error): pass
class ParseError(Error): pass
@classmethod
def from_file(cls, filename):
return cls(list(cls.iter_clusters(filename)))
@classmethod
def iter_clusters(cls, filename):
with open(filename) as fp:
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False
__all__ = (
'CLUSTERS',
'Clusters',
)
class NameTrait(Cluster.Trait):
name = Required(String)
Parser = namedtuple('Parser', 'loader exception')
class Clusters(Mapping):
class Error(Exception): pass
class ClusterExists(Error): pass
class ClusterNotFound(KeyError, Error): pass
class UnknownFormatError(Error): pass
class ParseError(Error): pass
LOADERS = {'.json': Parser(json.load, ValueError)}
if HAS_YAML:
LOADERS['.yml'] = Parser(yaml.load, yaml.parser.ParserError)
from pystachio import Environment, Required, String
from twitter.common import log
from apache.aurora.client.api import AuroraClientAPI
from apache.aurora.client.base import AURORA_V2_USER_AGENT_NAME, combine_messages
from apache.aurora.common.cluster import Cluster
from apache.aurora.config.schema.base import MesosContext
from apache.thermos.config.schema import ThermosContext
from gen.apache.aurora.api.constants import LIVE_STATES
from gen.apache.aurora.api.ttypes import JobKey, ResponseCode, TaskQuery
class CommandRunnerTrait(Cluster.Trait):
slave_root = Required(String) # noqa
slave_run_directory = Required(String) # noqa
class DistributedCommandRunner(object):
@classmethod
def make_executor_path(cls, cluster, executor_name):
parameters = cls.sandbox_args(cluster)
parameters.update(executor_name=executor_name)
return posixpath.join(
'%(slave_root)s',
'slaves/*/frameworks/*/executors/%(executor_name)s/runs',
'%(slave_run_directory)s'
) % parameters
@classmethod
def thermos_sandbox(cls, cluster, executor_sandbox=False):
from pystachio import Environment, Required, String
from twitter.common import log
from apache.aurora.client.api import AuroraClientAPI
from apache.aurora.client.base import AURORA_V2_USER_AGENT_NAME, combine_messages
from apache.aurora.common.cluster import Cluster
from apache.aurora.config.schema.base import MesosContext
from apache.thermos.config.schema import ThermosContext
from gen.apache.aurora.api.constants import LIVE_STATES
from gen.apache.aurora.api.ttypes import JobKey, ResponseCode, TaskQuery
class CommandRunnerTrait(Cluster.Trait):
slave_root = Required(String) # noqa
slave_run_directory = Required(String) # noqa
class DistributedCommandRunner(object):
@classmethod
def make_executor_path(cls, cluster, executor_name):
parameters = cls.sandbox_args(cluster)
parameters.update(executor_name=executor_name)
return posixpath.join(
'%(slave_root)s',
'slaves/*/frameworks/*/executors/%(executor_name)s/runs',
'%(slave_run_directory)s'
) % parameters
@classmethod
LoggerDestination = Enum('file', 'console', 'both', 'none')
LoggerMode = Enum('standard', 'rotate')
class Logger(Struct):
destination = Default(LoggerDestination, LoggerDestination('file'))
mode = Default(LoggerMode, LoggerMode('standard'))
rotate = RotatePolicy
class Process(Struct):
cmdline = Required(String)
name = Required(String)
# This is currently unused but reserved for future use by Thermos.
resources = Resources
# optionals
max_failures = Default(Integer, 1) # maximum number of failed process runs
# before process is failed.
daemon = Default(Boolean, False)
ephemeral = Default(Boolean, False)
min_duration = Default(Integer, 5) # integer seconds
final = Default(Boolean, False) # if this process should be a finalizing process
# that should always be run after regular processes
logger = Default(Logger, Empty)
TB = 1024 * GB
class ThermosContext(Struct):
# TODO(wickman) Move the underlying replacement mechanism to %port% replacements
ports = Map(String, Integer)
# TODO(wickman) Move the underlying replacement mechanism to %task_id%
task_id = String
# TODO(wickman) Move underlying mechanism to %user%
user = String
class Resources(Struct):
cpu = Required(Float)
ram = Required(Integer)
disk = Required(Integer)
gpu = Default(Integer, 0)
class Constraint(Struct):
order = List(String)
class RotatePolicy(Struct):
log_size = Default(Integer, 100*MB)
backups = Default(Integer, 5)
LoggerDestination = Enum('file', 'console', 'both', 'none')
class ThermosContext(Struct):
# TODO(wickman) Move the underlying replacement mechanism to %port% replacements
ports = Map(String, Integer)
# TODO(wickman) Move the underlying replacement mechanism to %task_id%
task_id = String
# TODO(wickman) Move underlying mechanism to %user%
user = String
class Resources(Struct):
cpu = Required(Float)
ram = Required(Integer)
disk = Required(Integer)
class Constraint(Struct):
order = List(String)
class Process(Struct):
cmdline = Required(String)
name = Required(String)
# This is currently unused but reserved for future use by Thermos.
resources = Resources
# optionals
max_failures = Default(Integer, 1) # maximum number of failed process runs
user = String
class Resources(Struct):
cpu = Required(Float)
ram = Required(Integer)
disk = Required(Integer)
class Constraint(Struct):
order = List(String)
class Process(Struct):
cmdline = Required(String)
name = Required(String)
# This is currently unused but reserved for future use by Thermos.
resources = Resources
# optionals
max_failures = Default(Integer, 1) # maximum number of failed process runs
# before process is failed.
daemon = Default(Boolean, False)
ephemeral = Default(Boolean, False)
min_duration = Default(Integer, 5) # integer seconds
final = Default(Boolean, False) # if this process should be a finalizing process
# that should always be run after regular processes
class Task(Struct):
name = Default(String, '{{processes[0].name}}')
class ThermosContext(Struct):
# TODO(wickman) Move the underlying replacement mechanism to %port% replacements
ports = Map(String, Integer)
# TODO(wickman) Move the underlying replacement mechanism to %task_id%
task_id = String
# TODO(wickman) Move underlying mechanism to %user%
user = String
class Resources(Struct):
cpu = Required(Float)
ram = Required(Integer)
disk = Required(Integer)
gpu = Default(Integer, 0)
class Constraint(Struct):
order = List(String)
class RotatePolicy(Struct):
log_size = Default(Integer, 100*MB)
backups = Default(Integer, 5)
LoggerDestination = Enum('file', 'console', 'both', 'none')
LoggerMode = Enum('standard', 'rotate')