How to use the pystachio.Required function in pystachio

To help you get started, we’ve selected a few pystachio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / aurora / src / main / python / apache / aurora / common / clusters.py View on Github external
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:
github apache / aurora / src / python / twitter / aurora / common / clusters.py View on Github external
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)
github apache / aurora / src / main / python / apache / aurora / client / api / command_runner.py View on Github external
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):
github apache / aurora / src / main / python / apache / aurora / client / api / command_runner.py View on Github external
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
github apache / aurora / src / main / python / apache / thermos / config / schema_base.py View on Github external
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)
github apache / aurora / src / main / python / apache / thermos / config / schema_base.py View on Github external
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')
github apache / aurora / src / python / twitter / thermos / config / schema_base.py View on Github external
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
github apache / aurora / src / python / twitter / thermos / config / schema_base.py View on Github external
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}}')
github apache / aurora / src / main / python / apache / thermos / config / schema_base.py View on Github external
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')