Beispiel #1
0
    def _init(self, conf, **kwargs):
        """Set up the necessary ingredients."""
        self.conf = conf
        self.kwargs = kwargs

        self.Plan = kwargs.get('plan_class')
        self.OrderLock = kwargs.get('order_locks')
        self.OrderLockHistory = kwargs.get('order_locks_history')
        self.RegionPlaceholders = kwargs.get('region_placeholders')
        self.CountryLatency = kwargs.get('country_latency')
        self.TriageTool = kwargs.get('triage_tool')

        # Set up the RPC service(s) we want to talk to.
        self.data_service = self.setup_rpc(conf, "data")

        # Set up the cei and optimizer
        self.cei = cei.ConstraintEngineInterface(self.data_service)
        # self.optimizer = optimizer.Optimizer(conf)

        # Set up Music access.
        self.music = db_backend.get_client()
        self.solver_owner_condition = {"solver_owner": socket.gethostname()}
        self.translated_status_condition = {"status": self.Plan.TRANSLATED}
        self.solving_status_condition = {"status": self.Plan.SOLVING}

        if not self.conf.solver.concurrent:
            self._reset_solving_status()
Beispiel #2
0
def plan_prepare(conf):
    music = db_backend.get_client()
    music.keyspace_create(keyspace=conf.keyspace)
    plan_tmp = base.create_dynamic_model(keyspace=conf.keyspace,
                                         baseclass=plan.Plan,
                                         classname="Plan")
    return plan_tmp
 def setUp(self):
     # Initialize music API
     cfg.CONF.set_override('certificate_authority_bundle_file',
                           '../AAF_RootCA.cer', 'music_api')
     music = db_backend.get_client()
     cfg.CONF.set_override('keyspace', 'conductor')
     music.keyspace_create(keyspace=cfg.CONF.keyspace)
     self.order_lock_svc = OrdersLockingService()
Beispiel #4
0
def plan_prepare(conf):
    cfg.CONF.set_override('certificate_authority_bundle_file',
                          '../AAF_RootCA.cer', 'music_api')
    music = db_backend.get_client()
    music.keyspace_create(keyspace=conf.keyspace)
    plan_tmp = base.create_dynamic_model(keyspace=conf.keyspace,
                                         baseclass=plan.Plan,
                                         classname="Plan")
    return plan_tmp
Beispiel #5
0
    def setUp(self):
        # Initialize music API
        music = db_backend.get_client()
        cfg.CONF.set_override('keyspace', 'conductor')
        music.keyspace_create(keyspace=cfg.CONF.keyspace)
        self.sp = SolverRequestParser()

        c1 = access_dist.AccessDistance(_name = 'c1', _type = 't1', _demand_list = ['d1', 'd2'])
        c2 = access_dist.AccessDistance(_name = 'c2', _type = 't1', _demand_list = ['d1'])
        self.sp.constraints = {'c1': c1, 'c2': c2}
        self.sp.demands = {'d1': demand.Demand('d1'), 'd2': demand.Demand('d2')}
Beispiel #6
0
    def __init__(self, conf):

        self.conf = conf

        # Set up Music access.
        self.music = db_backend.get_client()
        self.music.keyspace_create(keyspace=conf.keyspace)

        # Dynamically create a plan class for the specified keyspace
        self.Plan = base.create_dynamic_model(keyspace=conf.keyspace,
                                              baseclass=plan.Plan,
                                              classname="Plan")
        self.OrderLock = base.create_dynamic_model(
            keyspace=conf.keyspace,
            baseclass=order_lock.OrderLock,
            classname="OrderLock")
        self.OrderLockHistory = base.create_dynamic_model(
            keyspace=conf.keyspace,
            baseclass=order_lock_history.OrderLockHistory,
            classname="OrderLockHistory")
        self.RegionPlaceholders = base.create_dynamic_model(
            keyspace=conf.keyspace,
            baseclass=region_placeholders.RegionPlaceholders,
            classname="RegionPlaceholders")
        self.CountryLatency = base.create_dynamic_model(
            keyspace=conf.keyspace,
            baseclass=country_latency.CountryLatency,
            classname="CountryLatency")
        self.TriageTool = base.create_dynamic_model(
            keyspace=conf.keyspace,
            baseclass=triage_tool.TriageTool,
            classname="TriageTool")
        # self.Groups = base.create_dynamic_model(
        #    keyspace=conf.keyspace, baseclass=groups.Groups, classname="Groups")
        # self.GroupRules = base.create_dynamic_model(
        #    keyspace=conf.keyspace, baseclass=group_rules.GroupRules, classname="GroupRules")

        # Initialize Prometheus metrics Endpoint
        # Solver service uses index 1
        PC._init_metrics(1)

        if not self.Plan:
            raise
        if not self.OrderLock:
            raise
        if not self.OrderLockHistory:
            raise
        if not self.RegionPlaceholders:
            raise
        if not self.CountryLatency:
            raise
        if not self.TriageTool:
            raise
Beispiel #7
0
def getTransactionId(keyspace, plan_id):
    """get transaction id from a pariticular plan in MUSIC """

    rows = db_backend.get_client().row_read(keyspace, "plans", "id", plan_id)
    if 'result' in rows:
        rows = rows['result']
    for row_id, row_value in rows.items():
        template = row_value['template']
        if template:
            data = json.loads(template)
            if "transaction-id" in data:
                return data["transaction-id"]
Beispiel #8
0
def music_api(configuration):
    """Create or return a Music API instance"""

    configuration = dict(configuration)
    kwargs = {
        'host': configuration.get('host'),
        'port': configuration.get('port'),
        'version': configuration.get('version'),
        'replication_factor': configuration.get('replication_factor'),
    }
    api_instance = db_backend.get_client(**kwargs)

    # Create the keyspace if necessary
    # TODO(jdandrea): Use oslo.config with a [music] section
    # keyspace = conf.music.get('keyspace')
    # api_instance.create_keyspace(keyspace)
    return api_instance
Beispiel #9
0
    def __init__(self, conf):
        self.conf = conf

        # Set up Music access.
        self.music = db_backend.get_client()
        self.music.keyspace_create(keyspace=conf.keyspace)

        # Dynamically create a plan class for the specified keyspace
        self.Plan = base.create_dynamic_model(
            keyspace=conf.keyspace, baseclass=plan.Plan, classname="Plan")
        self.OrderLock = base.create_dynamic_model(
            keyspace=conf.keyspace, baseclass=order_lock.OrderLock, classname="OrderLock")

        if not self.Plan:
            raise
        if not self.OrderLock:
            raise

        self.insert_healthcheck_plan()
Beispiel #10
0
    def _init(self, conf, **kwargs):
        """Set up the necessary ingredients."""
        self.conf = conf
        self.kwargs = kwargs

        self.Plan = kwargs.get('plan_class')
        self.OrderLock = kwargs.get('order_locks')

        # Set up the RPC service(s) we want to talk to.
        self.data_service = self.setup_rpc(conf, "data")

        # Set up Music access.
        self.music = db_backend.get_client()

        # Number of retries for reservation/release
        self.reservation_retries = self.conf.reservation.reserve_retries

        if not self.conf.reservation.concurrent:
            self._reset_reserving_status()
Beispiel #11
0
    def load_into_country_letancy(self, json_data):
        datamap = collections.OrderedDict()
        group_map = collections.OrderedDict()
        datamap = json.loads(json_data)

        # for i, j in enumerate(datamap):
        #    group_map[j['group']] = j['countries']

        music = db_backend.get_client()

        # for row in group_map:
        #   music.row_create()

        kwargs = {'keyspace': 'conductor_inam', 'table': 'country_latency', 'pk_name': 'id'}
        for row in enumerate(datamap):
            kwargs['pk_value'] = id(row)
            kwargs['values'] = {'country_name': row['country_name'], 'groups': row['groups']}
            music.row_create(**kwargs)

        print(group_map)
Beispiel #12
0
    def _init(self, conf, **kwargs):
        self.conf = conf
        self.Plan = kwargs.get('plan_class')
        self.kwargs = kwargs
        self.opt_schema = load_config_file(
            str(self.conf.controller.opt_schema_file))

        # Set up the RPC service(s) we want to talk to.
        self.data_service = self.setup_rpc(conf, "data")

        # Set up Music access.
        self.music = db_backend.get_client()

        self.translation_owner_condition = {
            "translation_owner": socket.gethostname()
        }

        self.template_status_condition = {"status": self.Plan.TEMPLATE}

        self.translating_status_condition = {"status": self.Plan.TRANSLATING}

        if not self.conf.controller.concurrent:
            self._reset_template_status()
Beispiel #13
0
def get_transport(conf, url=None, optional=False, cache=True):
    """Initialise the Music messaging layer."""
    global TRANSPORTS
    cache_key = url or DEFAULT_URL
    transport = TRANSPORTS.get(cache_key)

    if not transport or not cache:
        try:
            # "Somebody set up us the API." ;)
            # Yes, we know an API is not a transport. Cognitive dissonance FTW!
            # TODO(jdandrea): try/except to catch problems
            keyspace = conf.messaging_server.keyspace
            transport = db_backend.get_client()
            transport.keyspace_create(keyspace=keyspace)
        except Exception:
            if not optional or url:
                # NOTE(sileht): oslo_messaging is configured but unloadable
                # so reraise the exception
                raise
            return None
        else:
            if cache:
                TRANSPORTS[cache_key] = transport
    return transport
Beispiel #14
0
 def __init__(self):
     music = db_backend.get_client()
     print("Music version %s" % music.version())
Beispiel #15
0
 def setUp(self, conf, _requests=None, _begin_time=None):
     self.music = db_backend.get_client()
     self.conf = cfg.CONF
     self.greedy = Greedy(self.conf)
     self._objective = None
Beispiel #16
0
def main():
    """Sample usage of Music."""
    service.prepare_service()
    CONF.set_override('debug', True, 'music_api')
    CONF.set_override('mock', True, 'music_api')
    CONF.set_override('hostnames', ['music2'], 'music_api')
    music = db_backend.get_client()
    print("Music version %s" % music.version())

    # Randomize the name so that we don't step on each other.
    keyspace = 'NewVotingApp' + str(current_time_millis() / 100)
    music.keyspace_create(keyspace)

    # Create the table
    kwargs = {
        'keyspace': keyspace,
        'table': 'votecount',
        'schema': {
            'name': 'text',
            'count': 'varint',
            'PRIMARY KEY': '(name)'
        }
    }
    music.table_create(**kwargs)

    # Candidate data
    data = {'Joe': 5, 'Shankar': 7, 'Gueyoung': 8, 'Matti': 2, 'Kaustubh': 0}

    # Create an entry in the voting table for each candidate
    # and with a vote count of 0.
    kwargs = {'keyspace': keyspace, 'table': 'votecount', 'pk_name': 'name'}
    for name in data:  # We only want the keys
        kwargs['pk_value'] = name
        kwargs['values'] = {'name': name, 'count': 0}
        music.row_create(**kwargs)

    # Update each candidate's count atomically.
    kwargs = {'keyspace': keyspace, 'table': 'votecount', 'pk_name': 'name'}
    for name in data:
        count = data[name]
        kwargs['pk_value'] = name
        kwargs['values'] = {'count': count}
        kwargs['atomic'] = True
        music.row_update(**kwargs)

    # Read all rows
    kwargs = {'keyspace': keyspace, 'table': 'votecount'}
    print(music.row_read(**kwargs))  # Reads all rows

    # Delete Joe, read Matti
    kwargs = {'keyspace': keyspace, 'table': 'votecount', 'pk_name': 'name'}
    kwargs['pk_value'] = 'Joe'
    music.row_delete(**kwargs)
    kwargs['pk_value'] = 'Matti'
    print(music.row_read(**kwargs))

    # Read all rows again
    kwargs = {'keyspace': keyspace, 'table': 'votecount'}
    print(music.row_read(**kwargs))  # Reads all rows

    # Cleanup.
    music.keyspace_delete(keyspace)
Beispiel #17
0
 def setUp(self, conf, _requests=None, _begin_time=None):
     self.music = db_backend.get_client()
     self.conf = cfg.CONF
     self.randomPick = RandomPick(self.conf)