コード例 #1
0
def log_slow_calls(f):
    """
    Wrapper to print duration when call takes > 1s
    :param f: Function to wrap
    :return: Wrapped function
    """
    logger = LogHandler.get('extensions', name='etcdconfiguration')

    def new_function(*args, **kwargs):
        """
        Execute function
        :return: Function output
        """
        start = time.time()
        try:
            return f(*args, **kwargs)
        finally:
            key_info = ''
            if 'key' in kwargs:
                key_info = ' (key: {0})'.format(kwargs['key'])
            elif len(args) > 0:
                key_info = ' (key: {0})'.format(args[0])
            duration = time.time() - start
            if duration > 1:
                logger.warning('Call to {0}{1} took {2}s'.format(f.__name__, key_info, duration))
    new_function.__name__ = f.__name__
    new_function.__module__ = f.__module__
    return new_function
コード例 #2
0
    def add_maintenance_service(name, backend_guid, abm_name):
        """
        Add a maintenance service with a specific name
        :param name: Name of the service to add
        :type name: str
        :param backend_guid: Backend for which the maintenance service needs to run
        :type backend_guid: str
        :param abm_name: Name of the ABM cluster
        :type abm_name: str
        """
        if ServiceManager.has_service(name, MaintenanceController._local_client) is False:
            config_location = '/ovs/alba/backends/{0}/maintenance/config'.format(backend_guid)
            alba_config = Configuration.get_configuration_path(config_location)
            node_id = os.environ.get('ASD_NODE_ID')
            params = {'ALBA_CONFIG': alba_config,
                      'LOG_SINK': LogHandler.get_sink_path('alba_maintenance')}
            Configuration.set(config_location, json.dumps({
                'log_level': 'info',
                'albamgr_cfg_url': Configuration.get_configuration_path('/ovs/arakoon/{0}/config'.format(abm_name)),
                'read_preference': [] if node_id is None else [node_id]
            }, indent=4), raw=True)

            ServiceManager.add_service(name=MaintenanceController.MAINTENANCE_PREFIX,
                                       client=MaintenanceController._local_client,
                                       params=params,
                                       target_name=name)
        ServiceManager.start_service(name, MaintenanceController._local_client)
コード例 #3
0
 def setup_logging():
     """
     Configure logging
     :return: None
     """
     if app.debug is False:
         _logger = LogHandler.get('asd-manager', name='flask')
         app.logger.handlers = []
         app.logger.addHandler(_logger.handler)
         app.logger.propagate = False
         wz_logger = logging.getLogger('werkzeug')
         wz_logger.handlers = []
         wz_logger.addHandler(_logger.handler)
         wz_logger.propagate = False
コード例 #4
0
    import json
    from source.tools.configuration.configuration import Configuration
    from source.tools.filemutex import file_mutex
    from source.tools.localclient import LocalClient
    from source.tools.log_handler import LogHandler
    from source.tools.services.service import ServiceManager
    from source.tools.toolbox import Toolbox

    with open(Toolbox.BOOTSTRAP_FILE, 'r') as bootstrap_file:
        NODE_ID = json.load(bootstrap_file)['node_id']
        os.environ['ASD_NODE_ID'] = NODE_ID

    CONFIG_ROOT = '/ovs/alba/asdnodes/{0}/config'.format(NODE_ID)
    CURRENT_VERSION = 1

    _logger = LogHandler.get('asd-manager', name='post-update')

    _logger.info('Executing post-update logic of package openvstorage-sdm')
    with file_mutex('package_update_pu'):
        client = LocalClient('127.0.0.1', username='******')

        key = '{0}/versions'.format(CONFIG_ROOT)
        version = Configuration.get(key) if Configuration.exists(key) else 0

        service_name = 'asd-manager'
        if ServiceManager.has_service(service_name, client) and ServiceManager.get_service_status(service_name, client)[0] is True:
            _logger.info('Stopping asd-manager service')
            ServiceManager.stop_service(service_name, client)

        if version < CURRENT_VERSION:
            try:
コード例 #5
0
'''Arakoon Nursery support'''

#pylint: disable=R0903
# R0903: Too few public methods

import operator

try:
    import cStringIO as StringIO
except ImportError:
    import StringIO

from source.tools.pyrakoon.pyrakoon import protocol, utils
from source.tools.log_handler import LogHandler

LOGGER = LogHandler.get('arakoon_client', 'pyrakoon')

class NurseryConfigType(protocol.Type):
    '''NurseryConfig type'''

    def check(self, value):
        raise NotImplementedError('NurseryConfig can\'t be checked')

    def serialize(self, value):
        raise NotImplementedError('NurseryConfig can\'t be serialized')

    def receive(self):
        buffer_receiver = protocol.STRING.receive()
        request = buffer_receiver.next() #pylint: disable=E1101

        while isinstance(request, protocol.Request):
コード例 #6
0
ファイル: asd.py プロジェクト: openvstorage/alba-asdmanager
    def create_asd(partition_alias):
        """
        Creates and starts an ASD on a given disk
        :param partition_alias: Alias of the partition of a disk  (eg: /dev/disk/by-id/scsi-1ATA_TOSHIBA_MK2002TSKB_92M1KDMHF-part1)
        :type partition_alias: str
        :return: None
        """
        all_asds = {}
        mountpoint = None
        for alias, mtpt in FSTab.read().iteritems():
            all_asds.update(ASDController.list_asds(mtpt))
            if alias == partition_alias:
                mountpoint = mtpt
        if mountpoint is None:
            raise RuntimeError('Failed to retrieve the mountpoint for partition with alias: {0}'.format(partition_alias))

        # Fetch disk information
        disk_size = int(ASDController._local_client.run(['df', '-B', '1', '--output=size', mountpoint]).splitlines()[1])

        # Find out appropriate disk size
        asds = 1.0
        for asd_id in os.listdir(mountpoint):
            if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                asds += 1
        asd_size = int(math.floor(disk_size / asds))
        for asd_id in os.listdir(mountpoint):
            if os.path.isdir('/'.join([mountpoint, asd_id])) and Configuration.exists(ASDController.ASD_CONFIG.format(asd_id)):
                config = json.loads(Configuration.get(ASDController.ASD_CONFIG.format(asd_id), raw=True))
                config['capacity'] = asd_size
                config['rocksdb_block_cache_size'] = int(asd_size / 1024 / 4)
                Configuration.set(ASDController.ASD_CONFIG.format(asd_id), json.dumps(config, indent=4), raw=True)
                try:
                    ServiceManager.send_signal(ASDController.ASD_SERVICE_PREFIX.format(asd_id),
                                               signal.SIGUSR1,
                                               ASDController._local_client)
                except Exception as ex:
                    ASDController._logger.info('Could not send signal to ASD for reloading the quota: {0}'.format(ex))

        # Prepare & start service
        asd_id = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32))
        ASDController._logger.info('Setting up service for disk {0}'.format(partition_alias))
        homedir = '{0}/{1}'.format(mountpoint, asd_id)
        base_port = Configuration.get('{0}/network|port'.format(ASDController.CONFIG_ROOT))
        ips = Configuration.get('{0}/network|ips'.format(ASDController.CONFIG_ROOT))
        used_ports = []
        for asd in all_asds.itervalues():
            used_ports.append(asd['port'])
            if 'rora_port' in asd:
                used_ports.append(asd['rora_port'])
        asd_port = base_port
        rora_port = base_port + 1
        while asd_port in used_ports:
            asd_port += 1
        used_ports.append(asd_port)
        while rora_port in used_ports:
            rora_port += 1

        asd_config = {'home': homedir,
                      'node_id': ASDController.NODE_ID,
                      'asd_id': asd_id,
                      'capacity': asd_size,
                      'log_level': 'info',
                      'port': asd_port,
                      'transport': 'tcp',
                      'rocksdb_block_cache_size': int(asd_size / 1024 / 4)}
        if Configuration.get('/ovs/framework/rdma'):
            asd_config['rora_port'] = rora_port
            asd_config['rora_transport'] = 'rdma'
        if ips is not None and len(ips) > 0:
            asd_config['ips'] = ips

        if Configuration.exists('{0}/extra'.format(ASDController.CONFIG_ROOT)):
            data = Configuration.get('{0}/extra'.format(ASDController.CONFIG_ROOT))
            asd_config.update(data)

        Configuration.set(ASDController.ASD_CONFIG.format(asd_id), json.dumps(asd_config, indent=4), raw=True)

        service_name = ASDController.ASD_SERVICE_PREFIX.format(asd_id)
        params = {'CONFIG_PATH': Configuration.get_configuration_path('/ovs/alba/asds/{0}/config'.format(asd_id)),
                  'SERVICE_NAME': service_name,
                  'LOG_SINK': LogHandler.get_sink_path('alba_asd')}
        os.mkdir(homedir)
        ASDController._local_client.run(['chown', '-R', 'alba:alba', homedir])
        ServiceManager.add_service('alba-asd', ASDController._local_client, params, service_name)
        ASDController.start_asd(asd_id)
コード例 #7
0
 def __init__(self):
     """
     Dummy init method
     """
     self._logger = LogHandler.get('extensions', name='watcher')