Esempio n. 1
0
    def test_register(self):
        PREFIX = self.PREFIX
        name = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        options = OPTIONS

        registry.register(name, version, description, template, options)

        ret_name = registry._kv.get('{}/{}/{}/name'.format(
            PREFIX, name, version))
        ret_version = registry._kv.get('{}/{}/{}/version'.format(
            PREFIX, name, version))
        ret_description = registry._kv.get('{}/{}/{}/description'.format(
            PREFIX, name, version))
        ret_template = registry._kv.get('{}/{}/{}/template'.format(
            PREFIX, name, version))
        ret_options = registry._kv.get('{}/{}/{}/options'.format(
            PREFIX, name, version))

        self.assertEqual(ret_name, name)
        self.assertEqual(ret_version, version)
        self.assertEqual(ret_description, description)
        self.assertEqual(ret_template, template)
        self.assertEqual(ret_options, options)
    def test_get_optional_attributes(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename, version, description,
                          template, templateopts, templatetype='json+jinja2')
        user = '******'
        options = {'slaves.number': 1}
        cluster = registry.instantiate(user, servicename, version, options)

        nodes = cluster.nodes
        for node in nodes:
            if(registry.parse_endpoint_last_element(str(node)) == "master0"):
                required_node = node.get("required_node")
                expected = None
                self.assertEqual(required_node, expected)

                custom_disks = node.get("use_custom_disks")
                expected = "True"
                self.assertEqual(custom_disks, expected)
            elif(registry.parse_endpoint_last_element(str(node)) == "master1"):
                required_node = node.get("required_node")
                expected = "c13-1"
                self.assertEqual(required_node, expected)

                custom_disks = node.get("use_custom_disks")
                expected = None
                self.assertEqual(custom_disks, expected)
            elif (registry.parse_endpoint_last_element(str(node)) == "slave0"):
                pass
            else:
                raise Exception("Unidentified node")
Esempio n. 3
0
    def __init__(cls, name, bases, attrs):
        super(StateMachineMetaclass, cls).__init__(name, bases, attrs)
        registry.register(cls)
        cls.states = []
        cls.transitions = []
        cls.states_map = {}
        cls.add_inherited(bases)
        cls.add_from_attributes(attrs)

        for state in cls.states:
            setattr(cls, 'is_{}'.format(state.identifier),
                    check_state_factory(state))
Esempio n. 4
0
    def _add_sample_service_instance(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename, version, description, template,
                          templateopts)
        user = '******'

        options = {'slaves.number': 1}
        cluster = registry.instantiate(user, servicename, version, options)
        return cluster
    def _add_sample_service_instance(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename, version, description,
                          template, templateopts)
        user = '******'

        options = {'slaves.number': 1}
        cluster = registry.instantiate(user, servicename, version, options)
        return cluster
Esempio n. 6
0
    def test_get_resources_names(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename,
                          version,
                          description,
                          template,
                          templateopts,
                          templatetype='json+jinja2')
        user = '******'
        options = {'slaves.number': 1}
        cluster = registry.instantiate(user, servicename, version, options)

        nodes = cluster.nodes
        for node in nodes:
            if (registry.parse_endpoint_last_element(str(node)) == "master0"):
                self.assertEqual(node.name, "master0")

                disks = node.disks
                disk_names = [disk.name for disk in disks]
                self.assertEqual(sorted(disk_names), ["disk2", "disk3"])

                networks = node.networks
                network_names = [network.name for network in networks]
                network_types = [network.networkname for network in networks]
                self.assertEqual(sorted(network_names), ["eth0", "eth1"])
                self.assertEqual(sorted(network_types), ["admin", "storage"])

            elif (registry.parse_endpoint_last_element(
                    str(node)) == "master1"):
                self.assertEqual(node.name, "master1")

                disks = node.disks
                self.assertEqual(disks, "2")

                networks = node.networks
                network_names = [network.name for network in networks]
                network_types = [network.networkname for network in networks]
                self.assertEqual(sorted(network_names),
                                 ["eth0", "eth1", "eth2"])
                self.assertEqual(sorted(network_types),
                                 ["admin", "heartbeat", "storage"])

            elif (registry.parse_endpoint_last_element(str(node)) == "slave0"):
                self.assertEqual(node.name, "slave0")

            else:
                raise Exception("Unidentified node")
Esempio n. 7
0
def registerHandlers(project=None):
    """Read the project handlers from the init file handler parameters, and add to the registry."""

    # Get the project names
    projectOption = config.get('initialize', 'project_options')
    projectSpecs = splitRecord(projectOption)
    projectRegistry = getRegistry(ESGCET_PROJECT_HANDLER_GROUP)
    formatRegistry = getRegistry(ESGCET_FORMAT_HANDLER_GROUP)
    metadataRegistry = getRegistry(ESGCET_METADATA_HANDLER_GROUP)
    threddsRegistry = getRegistry(ESGCET_THREDDS_CATALOG_HOOK_GROUP)

    for projectName, projectDesc, search_order in projectSpecs:
        # process only the given project
        if (project is not None) and (projectName != project):
            continue

        # For each project: get the handler
        handler = config.get('project:'+projectName, HANDLER_OPTION, default=None)
        handlerName = config.get('project:'+projectName, PROJECT_NAME_OPTION, default=None)

        # Get the handler class and register it
        if handlerName is not None:
            registerHandlerName(projectRegistry, projectName, handlerName)
            setRegisterSearchOrder(projectName, search_order)
        elif handler is not None:
            m, cls = handler.split(':')
            register(projectRegistry, projectName, m, cls)
            setRegisterSearchOrder(projectName, search_order)
        else:
            info("No project handler spec found for project %s"%projectName)

        # Get the format handler class and register it
        formatHandlerName = config.get('project:'+projectName, FORMAT_NAME_OPTION, default=None)
        if formatHandlerName is not None:
            registerHandlerName(formatRegistry, projectName, formatHandlerName)
        else:
            registerHandlerName(formatRegistry, projectName, DEFAULT_FORMAT_NAME_OPTION)

        # Get the metadata handler class and register it
        metadataHandlerName = config.get('project:'+projectName, METADATA_NAME_OPTION, default=None)
        if metadataHandlerName is not None:
            registerHandlerName(metadataRegistry, projectName, metadataHandlerName)
        else:
            registerHandlerName(metadataRegistry, projectName, DEFAULT_METADATA_NAME_OPTION)

        # Get the thredds catalog hook if any
        threddsCatalogHookName = config.get('project:'+projectName, THREDDS_CATALOG_HOOK_OPTION, default=None)
        if threddsCatalogHookName is not None:
            registerHandlerName(threddsRegistry, projectName, threddsCatalogHookName)
Esempio n. 8
0
def register_product():
    """Register a new product"""
    if request.is_json:
        data = request.get_json()
        required_fields = ('name', 'version', 'description', 'logo_url')
        if utils.validate(data, required_fields=required_fields):
            name = data['name']
            version = data['version']
            description = data['description']
            logo_url = data['logo_url']
            registry.register(name, version, description, logo_url=logo_url)
            location = url_for('api.get_product', name=name, version=version,
                               _external=True)
            return '', 201, {'Location': location}
    abort(400)
Esempio n. 9
0
    def test_get_product(self):
        name = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        options = OPTIONS
        registry.register(name, version, description, template, options)

        service = registry.get_product(name, version)

        self.assertEqual(service.name, name)
        self.assertEqual(service.version, version)
        self.assertEqual(service.description, description)
        self.assertEqual(service.template, template)
        self.assertEqual(service.options, options)
    def test_get_product(self):
        name = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        options = OPTIONS
        registry.register(name, version, description, template, options)

        service = registry.get_product(name, version)

        self.assertEqual(service.name, name)
        self.assertEqual(service.version, version)
        self.assertEqual(service.description, description)
        self.assertEqual(service.template, template)
        self.assertEqual(service.options, options)
    def test_add_instance_jsontemplate(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename, version, description,
                          template, templateopts, templatetype='json+jinja2')
        user = '******'
        options = {'slaves.number': 2}
        cluster = registry.instantiate(user, servicename, version, options)

        ## expected 4 nodes: 2 slaves + 2 masters
        self.assertEqual(len(cluster.nodes), options['slaves.number'] + 2)
        self.assertEqual(len(cluster.services), 2)
        self.assertEqual(cluster.nodes[0].networks[0].networkname, 'admin')
    def test_get_resources_names(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename, version, description,
                          template, templateopts, templatetype='json+jinja2')
        user = '******'
        options = {'slaves.number': 1}
        cluster = registry.instantiate(user, servicename, version, options)

        nodes = cluster.nodes
        for node in nodes:
            if (registry.parse_endpoint_last_element(str(node)) == "master0"):
                self.assertEqual(node.name, "master0")

                disks = node.disks
                disk_names = [disk.name for disk in disks]
                self.assertEqual(sorted(disk_names), ["disk2", "disk3"])

                networks = node.networks
                network_names = [network.name for network in networks]
                network_types = [network.networkname for network in networks]
                self.assertEqual(sorted(network_names), ["eth0", "eth1"])
                self.assertEqual(sorted(network_types), ["admin", "storage"])



            elif (registry.parse_endpoint_last_element(str(node)) == "master1"):
                self.assertEqual(node.name, "master1")

                disks = node.disks
                self.assertEqual(disks, "2")

                networks = node.networks
                network_names = [network.name for network in networks]
                network_types = [network.networkname for network in networks]
                self.assertEqual(sorted(network_names), ["eth0", "eth1", "eth2"])
                self.assertEqual(sorted(network_types), ["admin", "heartbeat", "storage"])

            elif (registry.parse_endpoint_last_element(str(node)) == "slave0"):
                self.assertEqual(node.name, "slave0")

            else:
                raise Exception("Unidentified node")
Esempio n. 13
0
def registerHandlers():
    """Read the project handlers from the init file handler parameters, and add to the registry."""
    # Get the project names
    projectOption = config.get('initialize', 'project_options')
    projectSpecs = splitRecord(projectOption)
    projectRegistry = getRegistry(ESGCET_PROJECT_HANDLER_GROUP)
    formatRegistry = getRegistry(ESGCET_FORMAT_HANDLER_GROUP)
    metadataRegistry = getRegistry(ESGCET_METADATA_HANDLER_GROUP)
    threddsRegistry = getRegistry(ESGCET_THREDDS_CATALOG_HOOK_GROUP)
    for projectName, projectDesc, search_order in projectSpecs:

        # For each project: get the handler
        handler = config.get('project:'+projectName, HANDLER_OPTION, default=None)
        handlerName = config.get('project:'+projectName, PROJECT_NAME_OPTION, default=None)
        
        # Get the handler class and register it
        if handlerName is not None:
            registerHandlerName(projectRegistry, projectName, handlerName)
            setRegisterSearchOrder(projectName, search_order)
        elif handler is not None:
            m, cls = handler.split(':')
            register(projectRegistry, projectName, m, cls)
            setRegisterSearchOrder(projectName, search_order)
        else:
            info("No project handler spec found for project %s"%projectName)

        # Get the format handler class and register it
        formatHandlerName = config.get('project:'+projectName, FORMAT_NAME_OPTION, default=None)
        if formatHandlerName is not None:
            registerHandlerName(formatRegistry, projectName, formatHandlerName)
        else:
            registerHandlerName(formatRegistry, projectName, DEFAULT_FORMAT_NAME_OPTION)

        # Get the metadata handler class and register it
        metadataHandlerName = config.get('project:'+projectName, METADATA_NAME_OPTION, default=None)
        if metadataHandlerName is not None:
            registerHandlerName(metadataRegistry, projectName, metadataHandlerName)
        else:
            registerHandlerName(metadataRegistry, projectName, DEFAULT_METADATA_NAME_OPTION)

        # Get the thredds catalog hook if any
        threddsCatalogHookName = config.get('project:'+projectName, THREDDS_CATALOG_HOOK_OPTION, default=None)
        if threddsCatalogHookName is not None:
            registerHandlerName(threddsRegistry, projectName, threddsCatalogHookName)
Esempio n. 14
0
    def test_add_instance_yamltemplate(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATEYAML
        templateopts = OPTIONS
        registry.register(servicename,
                          version,
                          description,
                          template,
                          templateopts,
                          templatetype='yaml+jinja2')
        user = '******'
        options = {'slaves.number': 2}
        cluster = registry.instantiate(user, servicename, version, options)

        ## expected 4 nodes: 2 slaves + 2 masters
        self.assertEqual(len(cluster.nodes), options['slaves.number'] + 2)
        self.assertEqual(len(cluster.services), 2)
        self.assertEqual(cluster.nodes[0].networks[0].networkname, 'admin')
    def test_register(self):
        PREFIX = self.PREFIX
        name = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        options = OPTIONS

        registry.register(name, version, description, template, options)

        ret_name = registry._kv.get('{}/{}/{}/name'.format(PREFIX, name, version))
        ret_version = registry._kv.get('{}/{}/{}/version'.format(PREFIX, name, version))
        ret_description = registry._kv.get('{}/{}/{}/description'.format(PREFIX, name, version))
        ret_template = registry._kv.get('{}/{}/{}/template'.format(PREFIX, name, version))
        ret_options = registry._kv.get('{}/{}/{}/options'.format(PREFIX, name, version))

        self.assertEqual(ret_name, name)
        self.assertEqual(ret_version, version)
        self.assertEqual(ret_description, description)
        self.assertEqual(ret_template, template)
        self.assertEqual(ret_options, options)
Esempio n. 16
0
    def test_get_optional_attributes(self):
        servicename = self.servicename
        version = "0.1.0"
        description = "Unit test"
        template = TEMPLATE
        templateopts = OPTIONS
        registry.register(servicename,
                          version,
                          description,
                          template,
                          templateopts,
                          templatetype='json+jinja2')
        user = '******'
        options = {'slaves.number': 1}
        cluster = registry.instantiate(user, servicename, version, options)

        nodes = cluster.nodes
        for node in nodes:
            if (registry.parse_endpoint_last_element(str(node)) == "master0"):
                required_node = node.get("required_node")
                expected = None
                self.assertEqual(required_node, expected)

                custom_disks = node.get("use_custom_disks")
                expected = "True"
                self.assertEqual(custom_disks, expected)
            elif (registry.parse_endpoint_last_element(
                    str(node)) == "master1"):
                required_node = node.get("required_node")
                expected = "c13-1"
                self.assertEqual(required_node, expected)

                custom_disks = node.get("use_custom_disks")
                expected = None
                self.assertEqual(custom_disks, expected)
            elif (registry.parse_endpoint_last_element(str(node)) == "slave0"):
                pass
            else:
                raise Exception("Unidentified node")
Esempio n. 17
0
 def __new__(cls, name, bases, namespace, **kwargs):
     ret = super().__new__(cls, name, bases, namespace)
     if bases != tuple() and bases != (object, ):
         registry.register(ret)
     return ret
def new_command_cls(name):
    cls = type(name, (), {'run': lambda self: print('good')})
    registry.register(cls)
    return cls
Esempio n. 19
0
 def register(cls):
     registry.register(cls)
Esempio n. 20
0
from bilstm.model import BiLSTMEncoder
from pretrained import EmbeddingBlock
from decepticon import Decepticon

from registry import register


__all__ = [
    register(BiLSTMEncoder, name="bilstm"),
    register(Decepticon, name="decepticon"),
    register(EmbeddingBlock, name="pretrained", default=True)
]
Esempio n. 21
0
 def __new__(cls, name, bases, namespace, **kwargs):
     ret = super().__new__(cls, name, bases, namespace)
     if ret.__name__ != 'CommandBase':
         registry.register(ret)
     return ret
Esempio n. 22
0
	def decorator(f):
		options['method'] = f
		register(name, options)
		return f
# -*- encoding: utf-8 -*-
from registry import register, ls


class CommandA:
    pass


register(CommandA)
ls()
class RandomCreativity(object):
    """A randomly (not really) creative style developer"""
    
    def __init__(self, sigma_factor=0.1, flip_chance=0.02):
        self._sd_factor = sigma_factor
        self._flip_chance = flip_chance

    def develop(self, style, name="", description=""):
        """Takes a style and create a new one"""
        new_progessions = list(map(self.randomize_progression, style.progressions))
        return HarmonicStyle(name, description, new_progessions)

    def randomize_progression(self, progression):
        """Takes a ChordProgression and applies some random changes to it"""
        new_weight = random.gauss(progression.weight, self._sd_factor*progression.weight)
        new_chords = list(map(self.randomize_chord, progression.chords))
        return ChordProgression(new_weight, new_chords, description="NA")

    def randomize_chord(self, chord):
        """Takes a Chord and applies some random changes to it"""
        new_notes = set(chord.get_notes())
        for i in range(12):
            if random.random() < self._flip_chance:
                if i in new_notes:
                    new_notes.remove(i)
                else:
                    new_notes.add(i)
        return Chord(new_notes)

registry.register(RandomCreativity)
Esempio n. 25
0
import registry

registry.register('my name')
for name in registry.registered_names():
    print(name)
Esempio n. 26
0
def new_command_cls(name, run):
    cls = type(name, (CommandBase, ), {'run': run})
    registry.register(cls)
    return cls
Esempio n. 27
0
# -*- coding: utf-8 -*-


from iso19139_2007 import Iso19139_2007Manager
import registry
registry.register(Iso19139_2007Manager(), True)
Esempio n. 28
0
import registry

registry.register('reg value A')

print('checking after update 1')
for name in registry.registered_names():
    print(name)

import registry  #registry.py is imported only once

registry.register('reg value B')

print('checking after update 2')
for name in registry.registered_names():
    print(name)
Esempio n. 29
0
def command(cls):
    registry.register(cls)
    return cls
Esempio n. 30
0
        for x in range(0, 100):
            if False:
                pass
        if True:
            if True:
                pass
            else:
                pass
        for x in range(0, 100):
            if False:
                pass
        if True:
            if True:
                pass
            else:
                pass
        for x in range(0, 100):
            if False:
                pass
        if True:
            if True:
                pass
            else:
                pass
        for x in range(0, 100):
            if False:
                pass


registry.register(SpecificExercise)
        r_chord = self.randomize_chord(chord)
        #return r_chord.transpose((binom_transp() * 7) % 12)
        return r_chord

    def randomize_progression(self, progression):
        """Takes a ChordProgression and applies some random changes to it"""
        new_weight = random.gauss(progression.weight, self._sd_factor*progression.weight)
        new_chords = list(map(self.randomize_chord, progression.chords))
        return ChordProgression(new_weight, new_chords, description="NA")

    def randomize_chord(self, chord):
        """Takes a Chord and applies some random changes to it"""
        new_notes = set(chord.get_notes())
        for i in range(12):
            if random.random() < self._flip_chance:
                if i in new_notes:
                    new_notes.remove(i)
                else:
                    new_notes.add(i)
        return Chord(new_notes)

def binom_transp ():
    sum = 0
    for _ in range(6):
        if random.random() < 0.5:
            sum += 1
    return sum - 6


registry.register(SimpleCreativity)