def create_stream(self,
                      encoding='',
                      original=True,
                      stream_definition_id='',
                      name='',
                      description='',
                      url=''):
        '''@brief Creates a new stream. The id string returned is the ID of the new stream in the resource registry.
        @param encoding the encoding for data on this stream
        @param original is the data on this stream from a source or a transform
        @param stream_definition a predefined stream definition type for this stream
        @param name (optional) the name of the stream
        @param description (optional) the description of the stream
        @param url (optional) the url where data from this stream can be found (Not implemented)

        @retval stream_id    str
        '''
        log.debug("Creating stream object")

        stream_obj = Stream(name=name, description=description)
        stream_obj.original = original
        stream_obj.encoding = encoding

        stream_obj.url = url
        stream_id, rev = self.clients.resource_registry.create(stream_obj)

        if stream_definition_id != '':
            self.clients.resource_registry.create_association(
                stream_id, PRED.hasStreamDefinition, stream_definition_id)

        return stream_id
    def create_stream(self, name='', exchange_point='', topic_ids=None, credentials=None, stream_definition_id='', description='', stream_name='', stream_type=''):
        # Argument Validation
        if name and self.clients.resource_registry.find_resources(restype=RT.Stream, name=name, id_only=True)[0]:
            raise Conflict("The named stream '%s' already exists on XP '%s'" % (name, exchange_point))
        validate_true(exchange_point, 'An exchange point must be specified')

        exchange_point_id = None
        if re.match(r'[0-9a-f]{32}', exchange_point):  # It's a uuid
            xp_obj = self.clients.exchange_management.read_exchange_point(exchange_point)
            exchange_point_id = exchange_point
            exchange_point = xp_obj.name
        else:
            self.container.ex_manager.create_xp(exchange_point)
            xp_objs, _ = self.clients.resource_registry.find_resources(restype=RT.ExchangePoint, name=exchange_point, id_only=True)
            if not xp_objs:
                raise BadRequest('failed to create an ExchangePoint: ' + exchange_point)
            exchange_point_id = xp_objs[0]

        topic_ids = topic_ids or []

        if not name: name = create_unique_identifier()

        # Get topic names and topics
        topic_names = []
        associated_topics = []
        for topic_id in topic_ids:
            topic = self.read_topic(topic_id)
            if topic.exchange_point == exchange_point:
                topic_names.append(self._sanitize(topic.name))
                associated_topics.append(topic_id)
            else:
                log.warning('Attempted to attach stream %s to topic %s with different exchange points', name, topic.name)

        stream = Stream(name=name, description=description)
        routing_key = '.'.join([self._sanitize(name)] + topic_names + ['stream'])
        if len(routing_key) > 255:
            raise BadRequest('There are too many topics for this.')

        stream.stream_route.exchange_point = exchange_point
        stream.stream_route.routing_key = routing_key
        #@todo: validate credentials
        stream.stream_route.credentials = credentials
        stream.stream_name = stream_name
        stream.stream_type = stream_type

        stream_id, rev = self.clients.resource_registry.create(stream)

        self._associate_stream_with_exchange_point(stream_id,exchange_point_id)

        if stream_definition_id: #@Todo: what if the stream has no definition?!
            self._associate_stream_with_definition(stream_id, stream_definition_id)

        for topic_id in associated_topics:
            self._associate_topic_with_stream(topic_id, stream_id)

        log.info('Stream %s: %s', name, routing_key)

        return stream_id, stream.stream_route
    def create_stream(self,encoding='', original=True, stream_definition_id='', name='', description='', url=''):
        '''@brief Creates a new stream. The id string returned is the ID of the new stream in the resource registry.
        @param encoding the encoding for data on this stream
        @param original is the data on this stream from a source or a transform
        @param stream_definition a predefined stream definition type for this stream
        @param name (optional) the name of the stream
        @param description (optional) the description of the stream
        @param url (optional) the url where data from this stream can be found (Not implemented)

        @retval stream_id    str
        '''
        log.debug("Creating stream object")

        stream_obj = Stream(name=name, description=description)
        stream_obj.original = original
        stream_obj.encoding = encoding

        stream_obj.url = url
        stream_id, rev = self.clients.resource_registry.create(stream_obj)

        if stream_definition_id != '':
            self.clients.resource_registry.create_association(stream_id, PRED.hasStreamDefinition, stream_definition_id)

        return stream_id
示例#4
0
    def create_stream(self,
                      name='',
                      exchange_point='',
                      topic_ids=None,
                      credentials=None,
                      stream_definition_id='',
                      description=''):
        # Argument Validation
        if name and self.clients.resource_registry.find_resources(
                restype=RT.Stream, name=name, id_only=True)[0]:
            raise Conflict('The named stream already exists')
        validate_true(exchange_point, 'An exchange point must be specified')

        exchange_point_id = None
        try:
            xp_obj = self.clients.exchange_management.read_exchange_point(
                exchange_point)
            exchange_point_id = exchange_point
            exchange_point = xp_obj.name
        except NotFound:
            self.container.ex_manager.create_xp(exchange_point)
            xp_objs, _ = self.clients.resource_registry.find_resources(
                restype=RT.ExchangePoint, name=exchange_point, id_only=True)
            if not xp_objs:
                raise BadRequest('failed to create an ExchangePoint: ' +
                                 exchange_point)
            exchange_point_id = xp_objs[0]

        topic_ids = topic_ids or []

        if not name: name = create_unique_identifier()

        # Get topic names and topics
        topic_names = []
        associated_topics = []
        for topic_id in topic_ids:
            topic = self.read_topic(topic_id)
            if topic.exchange_point == exchange_point:
                topic_names.append(self._sanitize(topic.name))
                associated_topics.append(topic_id)
            else:
                log.warning(
                    'Attempted to attach stream %s to topic %s with different exchange points',
                    name, topic.name)

        stream = Stream(name=name, description=description)
        routing_key = '.'.join([self._sanitize(name)] + topic_names +
                               ['stream'])
        if len(routing_key) > 255:
            raise BadRequest('There are too many topics for this.')

        stream.stream_route.exchange_point = exchange_point
        stream.stream_route.routing_key = routing_key
        #@todo: validate credentials
        stream.stream_route.credentials = credentials

        stream_id, rev = self.clients.resource_registry.create(stream)

        self._associate_stream_with_exchange_point(stream_id,
                                                   exchange_point_id)

        if stream_definition_id:  #@Todo: what if the stream has no definition?!
            self._associate_stream_with_definition(stream_id,
                                                   stream_definition_id)

        for topic_id in associated_topics:
            self._associate_topic_with_stream(topic_id, stream_id)

        log.info('Stream %s: %s', name, routing_key)

        return stream_id, stream.stream_route