Ejemplo n.º 1
0
    def create_xs(self,
                  name,
                  use_ems=True,
                  exchange_type='topic',
                  durable=False,
                  auto_delete=True):
        log.debug("ExchangeManager.create_xs: %s", name)
        xs = ExchangeSpace(self,
                           name,
                           exchange_type=exchange_type,
                           durable=durable,
                           auto_delete=auto_delete)

        self.xs_by_name[name] = xs

        if use_ems and self._ems_available():
            log.debug("Using EMS to create_xs")
            # create a RR object
            xso = ResExchangeSpace(name=name)
            xso_id = self._ems_client.create_exchange_space(xso, self.org_id)

            log.debug("Created RR XS object, id: %s", xso_id)
        else:
            xs.declare()

        return xs
Ejemplo n.º 2
0
    def create_xs(self,
                  name,
                  use_ems=True,
                  exchange_type='topic',
                  durable=False,
                  auto_delete=True):
        log.debug("ExchangeManager.create_xs: %s", name)
        xs = ExchangeSpace(self,
                           self._priviledged_transport,
                           name,
                           exchange_type=exchange_type,
                           durable=durable,
                           auto_delete=auto_delete)

        if use_ems and self._ems_available():
            log.debug("Using EMS to create_xs")
            org_id = self._bootstrap_default_org()
            if org_id is None:
                raise ExchangeManagerError(
                    "Could not find org, refusing to create_xs")

            # create a RR object
            xso = ResExchangeSpace(name=name)

            xso_id = self._ems_client.create_exchange_space(
                xso, org_id, headers=self._build_security_headers())

            log.debug("Created RR XS object, id: %s", xso_id)
        else:
            self._ensure_default_declared()
            xs.declare()

        self.xs_by_name[name] = xs

        return xs
Ejemplo n.º 3
0
    def on_initial_bootstrap(self, process, config, **kwargs):
        """
        Bootstraps initial objects in the system from configuration (pyon.yml) via
        EMS calls.
        """

        # get default org_id
        # @TODO: single org assumed for now
        org_ids = process.container.resource_registry.find_resources(
            RT.Org, id_only=True)
        if not (len(org_ids) and len(org_ids[0]) == 1):
            raise StandardError("Could not determine org_id")

        org_id = org_ids[0][0]

        ems_client = ExchangeManagementServiceProcessClient(process=process)

        #
        # Create XSs and XPs
        #
        for xsname, xsdict in config.get_safe('exchange_spaces',
                                              {}).iteritems():
            xso = ResExchangeSpace(name=xsname)
            xso_id = ems_client.create_exchange_space(xso, org_id)

            log.info("ExchangeSpace %s, id %s", xsname, xso_id)

            for xpname, xpopts in xsdict.get('exchange_points',
                                             {}).iteritems():

                # @TODO: some translation for types CFG currentl has it as "topic_tree" and we've been using "ttree"
                ttype = xpopts.get('type', 'topic_tree')
                if ttype == "topic_tree":
                    ttype = "ttree"

                xpo = ResExchangePoint(name=xpname, topology_type=ttype)
                xpo_id = ems_client.create_exchange_point(xpo, xso_id)

                log.info("\tExchangePoint %s, id %s", xpname, xpo_id)

            #
            # Create and associate brokers with XSs
            #
            for brokername in xsdict.get('brokers', []):
                xbo = ResExchangeBroker(name=brokername)
                xbo_id = ems_client.create_exchange_broker(xbo)

                log.info("\tExchangeBroker %s, id %s", brokername, xbo_id)

                # directly associate broker with XS
                # @TODO: should EMS provide this?
                # first find out if the assoc exists already
                assocs = process.container.resource_registry.find_associations(
                    xso_id, PRED.hasExchangeBroker, id_only=True)
                if len(assocs) > 0:
                    continue
                process.container.resource_registry.create_association(
                    xso_id, PRED.hasExchangeBroker, xbo_id)
Ejemplo n.º 4
0
    def on_initial_bootstrap(self, process, config, **kwargs):
        """
        Bootstraps initial objects in the system from configuration (pyon.yml) via
        EMS calls.
        """
        # Get ION Org
        root_org_name = config.get_safe('system.root_org' , "ION")
        org_ids, _ = process.container.resource_registry.find_resources(restype=RT.Org, name=root_org_name, id_only=True)
        if not org_ids or len(org_ids) > 1:
            raise StandardError("Could not determine root Org")

        org_id = org_ids[0]

        ems_client = ExchangeManagementServiceProcessClient(process=process)


        # Create XSs and XPs resource objects
        xs_by_name = {}   # Name to resource ID mapping for ExchangeSpace
        xs_defs = config.get_safe("exchange.exchange_spaces", {})
        for xsname, xsdict in xs_defs.iteritems():
            xso = ResExchangeSpace(name=xsname, description=xsdict.get("description", ""))
            xso_id = ems_client.create_exchange_space(xso, org_id)
            xs_by_name[xsname] = xso_id

            log.info("ExchangeSpace %s, id %s", xsname, xso_id)

            for xpname, xpopts in xsdict.get("exchange_points", {}).iteritems():

                # Translation for types. CFG currently has it as "topic_tree" and Pyon uses "ttree"
                xpo = ResExchangePoint(name=xpname, description=xpopts.get("description", ""),
                                       topology_type=xpopts.get('type', 'ttree'))
                xpo_id = ems_client.create_exchange_point(xpo, xso_id)

                log.info("\tExchangePoint %s, id %s", xpname, xpo_id)

        # Create XSs and XPs resource objects
        for brokername, bdict in config.get_safe("exchange.exchange_brokers", {}).iteritems():
            xbo = ResExchangeBroker(name=brokername, description=bdict.get("description", ""))
            xbo_id = ems_client.create_exchange_broker(xbo)

            log.info("\tExchangeBroker %s, id %s", brokername, xbo_id)

            for xs_name in bdict.get("join_xs", []):
                if xs_name in xs_by_name:
                    xs_id = xs_by_name[xs_name]
                    # directly associate broker with XS
                    # @TODO: should EMS provide this?
                    # first find out if the assoc exists already
                    assocs = process.container.resource_registry.find_associations(xso_id, PRED.hasExchangeBroker, id_only=True)
                    if len(assocs) > 0:
                        continue
                    process.container.resource_registry.create_association(xso_id, PRED.hasExchangeBroker, xbo_id)
                else:
                    log.warn("ExchangeSpace %s unknown. Broker %s cannot join", xs_name, brokername)

            for xp_name in bdict.get("join_xp", []):
                pass
Ejemplo n.º 5
0
    def on_initial_bootstrap(self, process, config, **kwargs):
        """
        Bootstraps initial objects in the system from configuration (pyon.yml) via
        EMS calls.
        """
        rr = process.container.resource_registry
        ems_client = ExchangeManagementServiceProcessClient(process=process)

        # Get ION Org
        root_org_name = config.get_safe('system.root_org', "ION")
        org_ids, _ = rr.find_resources(restype=RT.Org,
                                       name=root_org_name,
                                       id_only=True)
        if not org_ids or len(org_ids) > 1:
            raise StandardError("Could not determine root Org")
        org_id = org_ids[0]

        # Create XSs and XPs resource objects
        xs_by_name = {}  # Name to resource ID mapping for ExchangeSpace
        xs_defs = config.get_safe("exchange.exchange_spaces", {})
        for xsname, xsdict in xs_defs.iteritems():
            xso = ResExchangeSpace(name=xsname,
                                   description=xsdict.get("description", ""))
            xso_id = ems_client.create_exchange_space(xso, org_id)
            xs_by_name[xsname] = xso_id

            log.info("ExchangeSpace %s, id %s", xsname, xso_id)

            for xpname, xpopts in xsdict.get("exchange_points",
                                             {}).iteritems():
                xpo = ResExchangePoint(
                    name=xpname,
                    description=xpopts.get("description", ""),
                    topology_type=xpopts.get('type', 'ttree'))
                xpo_id = ems_client.create_exchange_point(xpo, xso_id)

                log.info("\tExchangePoint %s, id %s", xpname, xpo_id)

        # Create XSs and XPs resource objects
        for brokername, bdict in config.get_safe("exchange.exchange_brokers",
                                                 {}).iteritems():
            xbo = ResExchangeBroker(name=brokername,
                                    description=bdict.get("description", ""))
            xbo_id = ems_client.create_exchange_broker(xbo)
            log.info("\tExchangeBroker %s, id %s", brokername, xbo_id)

            for xs_name in bdict.get("join_xs", None) or []:
                if xs_name in xs_by_name:
                    xs_id = xs_by_name[xs_name]
                    ems_client.add_exchange_space_to_exchange_broker(
                        xs_id, xbo_id)
                else:
                    log.warn("ExchangeSpace %s unknown. Broker %s cannot join",
                             xs_name, brokername)

            for xp_name in bdict.get("join_xp", None) or []:
                pass