Beispiel #1
0
def create_apps(zkclient, app_id, app, count):
    """Schedules new apps."""
    instance_ids = []
    acl = zkutils.make_role_acl('servers', 'rwcd')
    for _idx in range(0, count):
        node_path = zkutils.put(zkclient,
                                _app_node(app_id, existing=False),
                                app,
                                sequence=True,
                                acl=[acl])
        instance_id = os.path.basename(node_path)

        # Create task for the app, and put it in pending state.
        # TODO: probably need to create PendingEvent and use to_data method.
        task_node = z.path.trace(
            instance_id, '{time},{hostname},pending,{data}'.format(
                time=time.time(), hostname=sysinfo.hostname(), data='created'))
        try:
            zkclient.create(task_node, b'', acl=[_SERVERS_ACL], makepath=True)
        except kazoo.client.NodeExistsError:
            pass

        instance_ids.append(instance_id)

    return instance_ids
Beispiel #2
0
def create_apps(zkclient, app_id, app, count, created_by=None):
    """Schedules new apps."""
    instance_ids = []
    acl = zkutils.make_role_acl('servers', 'rwcda')
    for _idx in range(0, count):
        node_path = zkutils.put(zkclient,
                                _app_node(app_id, existing=False),
                                app,
                                sequence=True,
                                acl=[acl])
        instance_id = os.path.basename(node_path)
        instance_ids.append(instance_id)

        appevents.post_zk(
            zkclient,
            traceevents.PendingTraceEvent(
                instanceid=instance_id,
                why='%s:created' % created_by if created_by else 'created',
                payload=''))

    return instance_ids
Beispiel #3
0
import logging

import kazoo

from treadmill import zknamespace as z
from treadmill import zkutils

from . import backend

_LOGGER = logging.getLogger(__name__)

# ACL which allows all servers in the cell to full control over node.
#
# Set in /finished, /servers
_SERVERS_ACL = zkutils.make_role_acl('servers', 'rwcda')
# Delete only servers ACL
_SERVERS_ACL_DEL = zkutils.make_role_acl('servers', 'd')


class ZkReadonlyBackend(backend.Backend):
    """Implements readonly Zookeeper based storage."""

    def __init__(self, zkclient):
        self.zkclient = zkclient
        super(ZkReadonlyBackend, self).__init__()

    def list(self, path):
        """Return path listing."""
        try:
            return self.zkclient.get_children(path)
Beispiel #4
0
from treadmill import exc
from treadmill import cgroups
from treadmill import supervisor
from treadmill import sysinfo
from treadmill import utils
from treadmill import subproc
from treadmill import zkutils
from treadmill import appevents

from treadmill import zknamespace as z

from treadmill.apptrace import events as traceevents

_LOGGER = logging.getLogger(__name__)

_SERVERS_ACL = zkutils.make_role_acl('servers', 'rwcd')

_INVALID_IDENTITY = sys.maxsize

# Max number of restart in a min, after which the app will not be restarted.
_MAX_RESTART_RATE = 5
_RESTART_RATE_INTERVAL = 60

# Time to wait when registering endpoints in case previous ephemeral
# endpoint is still present.
_EPHEMERAL_RETRY_INTERVAL = 5


def _create_ephemeral_with_retry(zkclient, path, data):
    """Create ephemeral node with retry."""
    prev_data = None