def test_xn_declare_then_delete_xs(self):

        # xn needs an xs first
        exchange_space = ExchangeSpace(name="bozo")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_name = ExchangeName(name='shnoz', xn_type="XN_PROCESS")
        enid = self.ems.declare_exchange_name(exchange_name, esid)

        # delete the XS
        self.ems.delete_exchange_space(esid)

        # no longer should have assoc from XS to XN
        xnlist, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                          PRED.hasExchangeName,
                                          enid,
                                          id_only=True)
        self.assertEquals(len(xnlist), 0)

        # cleanup: delete the XN (assoc already removed, so we reach into the implementation here)
        # @TODO: reaching into ex manager for transport is clunky
        self.rr.delete(enid)
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        xn = exchange.ExchangeName(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_name.name, xs)
        self.container.ex_manager.delete_xn(xn, use_ems=False)
    def test_xp_create_then_delete_xs(self):

        # xp needs an xs first
        exchange_space = ExchangeSpace(name="doink")
        esid = self.ems.create_exchange_space(exchange_space, self.org_id)

        exchange_point = ExchangePoint(name="hammer")
        epid = self.ems.create_exchange_point(exchange_point, esid)

        # delete xs
        self.ems.delete_exchange_space(esid)

        # should no longer have an association
        xslist2, _ = self.rr.find_subjects(RT.ExchangeSpace,
                                           PRED.hasExchangePoint,
                                           epid,
                                           id_only=True)
        self.assertEquals(len(xslist2), 0)

        # TEST ONLY: have to clean up the xp or we leave junk on the broker
        # we have to do it manually because the xs is gone
        #self.ems.delete_exchange_point(epid)
        # @TODO: reaching into ex manager for transport is clunky
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        xp = exchange.ExchangePoint(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_point.name, xs, 'ttree')
        self.container.ex_manager.delete_xp(xp, use_ems=False)
    def delete_exchange_point(self, exchange_point_id=''):
        """Delete an existing exchange point resource.

        @param exchange_point_id    str
        @throws NotFound    object with specified id does not exist
        """
        exchange_point = self.clients.resource_registry.read(exchange_point_id)
        if not exchange_point:
            raise NotFound("Exchange Point %s does not exist" %
                           exchange_point_id)

        # get associated XS first
        exchange_space_list, assoc_list = self.clients.resource_registry.find_subjects(
            RT.ExchangeSpace, PRED.hasExchangePoint, exchange_point_id)
        if not len(exchange_space_list) == 1:
            raise NotFound(
                "Associated Exchange Space to Exchange Point %s does not exist"
                % exchange_point_id)

        exchange_space = exchange_space_list[0]

        # delete association to XS
        for assoc in assoc_list:
            self.clients.resource_registry.delete_association(assoc._id)

        # delete from RR
        self.clients.resource_registry.delete(exchange_point_id)

        # call container API
        xs = exchange.ExchangeSpace(self.container.ex_manager,
                                    exchange_space.name)
        xp = exchange.ExchangePoint(self.container.ex_manager,
                                    exchange_point.name, xs, 'ttree')
        self.container.ex_manager.delete_xp(xp, use_ems=False)
    def create_exchange_point(self, exchange_point=None, exchange_space_id=''):
        """Create an exchange point resource within the exchange space provided by the id.

        @param exchange_point    ExchangePoint
        @param exchange_space_id    str
        @retval exchange_point_id    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """
        exchange_space = self.read_exchange_space(exchange_space_id)
        exchange_point_id, _ver = self.clients.resource_registry.create(
            exchange_point)

        aid = self.clients.resource_registry.create_association(
            exchange_space_id, PRED.hasExchangePoint, exchange_point_id)

        # call container API
        xs = exchange.ExchangeSpace(self.container.ex_manager,
                                    exchange_space.name)
        self.container.ex_manager.create_xp(
            exchange_point.name,
            xs,
            xptype=exchange_point.topology_type,
            use_ems=False)

        return exchange_point_id
예제 #5
0
    def undeclare_exchange_name(self, canonical_name='', exchange_space_id=''):
        """Remove an exhange nane resource

        @param canonical_name    str
        @param exchange_space_id    str
        @retval success    bool
        @throws NotFound    object with specified id does not exist
        """
        # @TODO: currently we are using the exchange_name's id as the canonical name
        # and exchange_space_id is unused?
        exchange_name = self.container.resource_registry.read(canonical_name)
        if not exchange_name:
            raise NotFound("Exchange Name with id %s does not exist" %
                           canonical_name)

        exchange_name_id = exchange_name._id  # yes, this should be same, but let's make it look cleaner

        # get associated XS first
        exchange_space_list, assoc_list = self.container.resource_registry.find_subjects(
            RT.ExchangeSpace, PRED.hasExchangeName, exchange_name_id)
        if not len(exchange_space_list) == 1:
            raise NotFound(
                "Associated Exchange Space to Exchange Name %s does not exist"
                % exchange_name_id)

        exchange_space = exchange_space_list[0]

        # remove association between itself and XS
        _, assocs = self.container.resource_registry.find_subjects(
            RT.ExchangeSpace,
            PRED.hasExchangeName,
            exchange_name_id,
            id_only=True)
        for assoc in assocs:
            self.container.resource_registry.delete_association(assoc._id)

        # remove XN
        self.container.resource_registry.delete(exchange_name_id)

        # call container API
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        xn = exchange.ExchangeName(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_name.name, xs)  # type doesn't matter here
        self.container.ex_manager.delete_xn(xn, use_ems=False)
예제 #6
0
    def declare_exchange_name(self, exchange_name=None, exchange_space_id=''):
        """Create an Exchange Name resource resource

        @param exchange_name    ExchangeName
        @param exchange_space_id    str
        @retval canonical_name    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """
        # get xntype and translate @TODO should we just consolidate these to be the same?
        typemap = {
            'XN_SERVICE': 'service',
            'XN_PROCESS': 'process',
            'XN_QUEUE': 'queue'
        }
        if not exchange_name.xn_type in typemap:
            raise BadRequest("Unknown exchange name type: %s" %
                             exchange_name.xn_type)

        xns, assocs = self.container.resource_registry.find_objects(
            subject=exchange_space_id,
            predicate=PRED.hasExchangeName,
            id_only=False)
        exchange_name_id = None
        for xn in xns:
            if xn.name == exchange_name.name and xn.xn_type == exchange_name.xn_type:
                exchange_name_id = xn._id

        xntype = typemap[exchange_name.xn_type]

        exchange_space = self.read_exchange_space(exchange_space_id)
        if not exchange_name_id:
            exchange_name_id, rev = self.container.resource_registry.create(
                exchange_name)

            aid = self.container.resource_registry.create_association(
                exchange_space_id, PRED.hasExchangeName, exchange_name_id)

        # call container API
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        self.container.ex_manager._create_xn(xntype,
                                             exchange_name.name,
                                             xs,
                                             use_ems=False)

        return exchange_name_id  #QUestion - is this the correct canonical name?
예제 #7
0
    def delete_exchange_space(self, exchange_space_id=''):
        """Deletes an existing exchange space resource for the provided id.

        @param exchange_space_id    str
        @throws NotFound    object with specified id does not exist
        """
        exchange_space = self.container.resource_registry.read(
            exchange_space_id)
        if not exchange_space:
            raise NotFound("Exchange Space %s does not exist" %
                           exchange_space_id)

        # remove association between itself and org
        _, assocs = self.container.resource_registry.find_subjects(
            RT.Org, PRED.hasExchangeSpace, exchange_space_id, id_only=True)
        for assoc in assocs:
            self.container.resource_registry.delete_association(assoc._id)

        # delete assocs to XNs
        _, assocs = self.container.resource_registry.find_objects(
            exchange_space_id, PRED.hasExchangeName, id_only=True)
        for assoc in assocs:
            self.container.resource_registry.delete_association(assoc._id)

        # delete assocs to XPs
        _, assocs = self.container.resource_registry.find_objects(
            exchange_space_id, PRED.hasExchangePoint, id_only=True)
        for assoc in assocs:
            self.container.resource_registry.delete_association(assoc._id)

        # delete assocs to XBs
        _, assocs = self.container.resource_registry.find_objects(
            exchange_space_id, PRED.hasExchangeBroker, id_only=True)
        for assoc in assocs:
            self.container.resource_registry.delete_association(assoc._id)

        # delete XS now
        self.container.resource_registry.delete(exchange_space_id)

        # call container API to delete @TODO this is clunky
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        self.container.ex_manager.delete_xs(xs, use_ems=False)
예제 #8
0
    def create_exchange_point(self, exchange_point=None, exchange_space_id=''):
        """Create an exchange point resource within the exchange space provided by the id.

        @param exchange_point    ExchangePoint
        @param exchange_space_id    str
        @retval exchange_point_id    str
        @throws BadRequest    if object passed has _id or _rev attribute
        """

        xs_xps, assocs = self.container.resource_registry.find_objects(
            subject=exchange_space_id,
            predicate=PRED.hasExchangePoint,
            id_only=False)
        exchange_point_id = None
        for xs_xp in xs_xps:
            if xs_xp.name == exchange_point.name and xs_xp.topology_type == exchange_point.topology_type:
                exchange_point_id = xs_xp._id

        exchange_space = self.read_exchange_space(exchange_space_id)
        if not exchange_point_id:
            exchange_point_id, _ver = self.container.resource_registry.create(
                exchange_point)

            self.container.resource_registry.create_association(
                exchange_space_id, PRED.hasExchangePoint, exchange_point_id)

        # call container API
        xs = exchange.ExchangeSpace(
            self.container.ex_manager,
            self.container.ex_manager._priviledged_transport,
            exchange_space.name)
        self.container.ex_manager.create_xp(
            exchange_point.name,
            xs,
            xptype=exchange_point.topology_type,
            use_ems=False)

        return exchange_point_id