Exemple #1
0
    def create_subscription(self,
                            name='',
                            stream_ids=None,
                            exchange_points=None,
                            topic_ids=None,
                            exchange_name='',
                            credentials=None,
                            description=''):
        stream_ids = stream_ids or []
        exchange_points = exchange_points or []
        topic_ids = topic_ids or []

        exchange_name = exchange_name or name
        validate_true(exchange_name, 'Clients must provide an exchange name')
        log.info('Creating Subscription %s for %s <- %s', name, exchange_name,
                 stream_ids or exchange_points or topic_ids)

        if not name: name = create_unique_identifier()

        if stream_ids:
            validate_is_instance(stream_ids, list,
                                 'stream ids must be in list format')

        if exchange_points:
            validate_is_instance(exchange_points, list,
                                 'exchange points must be in list format')

        if topic_ids:
            validate_is_instance(topic_ids, list,
                                 'topic ids must be in list format')

        subscription = Subscription(name=name, description=description)
        subscription.exchange_points = exchange_points
        subscription.exchange_name = exchange_name

        subscription_id, rev = self.clients.resource_registry.create(
            subscription)
        self.container.ex_manager.create_xn_queue(exchange_name)
        xn_ids, _ = self.clients.resource_registry.find_resources(
            restype=RT.ExchangeName, name=exchange_name, id_only=True)
        if xn_ids:
            xn_id = xn_ids[0]
            self.clients.resource_registry.create_association(
                xn_id, PRED.hasSubscription, subscription_id)

        #---------------------------------
        # Associations
        #---------------------------------

        for stream_id in stream_ids:
            self._associate_stream_with_subscription(stream_id,
                                                     subscription_id)

        for topic_id in topic_ids:
            self._associate_topic_with_subscription(topic_id, subscription_id)

        return subscription_id
Exemple #2
0
    def test_ingestion_config_crud(self):
        ingestion_config_id = self.create_ingest_config()

        ingestion_config = self.ingestion_management.read_ingestion_configuration(
            ingestion_config_id)
        self.assertTrue(ingestion_config.name == self.ingest_name)
        self.assertTrue(ingestion_config.queues[0].name == 'test')
        self.assertTrue(ingestion_config.queues[0].type == 'testdata')

        ingestion_config.name = 'another'

        self.ingestion_management.update_ingestion_configuration(
            ingestion_config)

        # Create an association just to make sure that it will delete them
        sub = Subscription()
        sub_id, _ = self.resource_registry.create(sub)
        assoc_id, _ = self.resource_registry.create_association(
            subject=ingestion_config_id,
            predicate=PRED.hasSubscription,
            object=sub_id)

        self.ingestion_management.delete_ingestion_configuration(
            ingestion_config_id)

        with self.assertRaises(NotFound):
            self.resource_registry.read(assoc_id)
    def create_subscription(self, name='', stream_ids=None, exchange_points=None, topic_ids=None, exchange_name='', credentials=None, description='', data_product_ids=[]):
        stream_ids       = stream_ids or []
        exchange_points  = exchange_points or []
        topic_ids        = topic_ids or []
        data_product_ids = data_product_ids or []

        exchange_name = exchange_name or name
        validate_true(exchange_name, 'Clients must provide an exchange name')
        log.info('Creating Subscription %s for %s <- %s', name, exchange_name, stream_ids or exchange_points or topic_ids)

        if not name: name = create_unique_identifier()

        if stream_ids:
            validate_is_instance(stream_ids, list, 'stream ids must be in list format')

        if exchange_points:
            validate_is_instance(exchange_points, list, 'exchange points must be in list format')

        if topic_ids:
            validate_is_instance(topic_ids, list, 'topic ids must be in list format')


        subscription = Subscription(name=name, description=description)
        subscription.exchange_points = exchange_points
        subscription.exchange_name   = exchange_name

        subscription_id, rev = self.clients.resource_registry.create(subscription)
        self.container.ex_manager.create_xn_queue(exchange_name)
        xn_ids, _ = self.clients.resource_registry.find_resources(restype=RT.ExchangeName, name=exchange_name, id_only=True)
        if xn_ids:
            xn_id = xn_ids[0]
            self.clients.resource_registry.create_association(xn_id, PRED.hasSubscription, subscription_id)

        #---------------------------------
        # Associations
        #---------------------------------

        for stream_id in stream_ids:
            self._associate_stream_with_subscription(stream_id, subscription_id)
        
        for topic_id in topic_ids:
            self._associate_topic_with_subscription(topic_id, subscription_id)

        for data_product_id in data_product_ids:
            self._associate_data_product_with_subscription(data_product_id, subscription_id)
        
        return subscription_id
Exemple #4
0
    def test_read_and_update_subscription(self):
        # Mocks
        subscription_obj = Subscription()
        subscription_obj.query = StreamQuery(['789'])
        subscription_obj.is_active=False
        subscription_obj.subscription_type = SubscriptionTypeEnum.STREAM_QUERY
        self.mock_read.return_value = subscription_obj

        self.mock_find_objects.return_value = (['789'],['This here is an association'])
        self.mock_update.return_value = ('not important','even less so')
        # Execution
        query = StreamQuery(['123'])
        retval = self.pubsub_service.update_subscription('subscription_id', query)

        # Assertions
        self.mock_read.assert_called_once_with('subscription_id','')
        self.mock_find_objects.assert_called_once_with('subscription_id',PRED.hasStream,'',True)
        self.mock_delete_association.assert_called_once_with('This here is an association')
        self.mock_create_association.assert_called_once_with('subscription_id',PRED.hasStream,'123',None)
        self.assertTrue(self.mock_update.call_count == 1, 'update was not called')
    def create_subscription(self, name='', stream_ids=None, exchange_points=None, topic_ids=None, exchange_name='', credentials=None, description=''):
        stream_ids      = stream_ids or []
        exchange_points = exchange_points or []
        topic_ids       = topic_ids or []

        exchange_name = exchange_name or name
        validate_true(exchange_name, 'Clients must provide an exchange name')
        log.info('Creating Subscription %s for %s <- %s', name, exchange_name, stream_ids or exchange_points or topic_ids)

        if not name: name = create_unique_identifier()

        if stream_ids:
            validate_is_instance(stream_ids, list, 'stream ids must be in list format')

        if exchange_points:
            validate_is_instance(exchange_points, list, 'exchange points must be in list format')

        if topic_ids:
            validate_is_instance(topic_ids, list, 'topic ids must be in list format')


        subscription = Subscription(name=name, description=description)
        subscription.exchange_points = exchange_points
        subscription.exchange_name   = exchange_name

        subscription_id, rev = self.clients.resource_registry.create(subscription)

        #---------------------------------
        # Associations
        #---------------------------------
        
        for stream_id in stream_ids:
            self._associate_stream_with_subscription(stream_id, subscription_id)
        
        for topic_id in topic_ids:
            self._associate_topic_with_subscription(topic_id, subscription_id)
        
        return subscription_id
    def create_subscription(self, query=None, exchange_name='', name='', description=''):
        '''
        @brief Create a new subscription. The id string returned is the ID of the new subscription
        in the resource registry.
        @param query is a subscription query object (Stream Query, Exchange Query, etc...)
        @param exchange_name is the name (queue) where messages will be delivered for this subscription
        @param name (optional) is the name of the subscription
        @param description (optional) is the description of the subscription

        @param query    Unknown
        @param exchange_name    str
        @param name    str
        @param description    str
        @retval subscription_id    str
        @throws BadRequestError    Throws when the subscription query object type is not found
        '''
        log.debug("Creating subscription object")
        subscription = Subscription(name, description=description)
        subscription.exchange_name = exchange_name
        subscription.query = query
        if isinstance(query, StreamQuery):
            subscription.subscription_type = SubscriptionTypeEnum.STREAM_QUERY
        elif isinstance(query, ExchangeQuery):
            subscription.subscription_type = SubscriptionTypeEnum.EXCHANGE_QUERY
        else:
            raise BadRequest("Query type does not exist")

        subscription_id, _ = self.clients.resource_registry.create(subscription)

        #we need the stream_id to create the association between the
        #subscription and stream.
        if subscription.subscription_type == SubscriptionTypeEnum.STREAM_QUERY:
            for stream_id in subscription.query.stream_ids:
                self.clients.resource_registry.create_association(subscription_id, PRED.hasStream, stream_id)

        return subscription_id
    def create_subscription(self,
                            query=None,
                            exchange_name='',
                            name='',
                            description=''):
        '''
        @brief Create a new subscription. The id string returned is the ID of the new subscription
        in the resource registry.
        @param query is a subscription query object (Stream Query, Exchange Query, etc...)
        @param exchange_name is the name (queue) where messages will be delivered for this subscription
        @param name (optional) is the name of the subscription
        @param description (optional) is the description of the subscription

        @param query    Unknown
        @param exchange_name    str
        @param name    str
        @param description    str
        @retval subscription_id    str
        @throws BadRequestError    Throws when the subscription query object type is not found
        '''
        log.debug("Creating subscription object")
        subscription = Subscription(name, description=description)
        subscription.exchange_name = exchange_name
        subscription.query = query
        if isinstance(query, StreamQuery):
            subscription.subscription_type = SubscriptionTypeEnum.STREAM_QUERY
        elif isinstance(query, ExchangeQuery):
            subscription.subscription_type = SubscriptionTypeEnum.EXCHANGE_QUERY
        else:
            raise BadRequest("Query type does not exist")

        subscription_id, _ = self.clients.resource_registry.create(
            subscription)

        #we need the stream_id to create the association between the
        #subscription and stream.
        if subscription.subscription_type == SubscriptionTypeEnum.STREAM_QUERY:
            for stream_id in subscription.query.stream_ids:
                self.clients.resource_registry.create_association(
                    subscription_id, PRED.hasStream, stream_id)

        return subscription_id