Esempio n. 1
0
    def handle(self):
        input = self.request.input

        with closing(self.odb.session()) as session:

            existing_one = session.query(PubSubEndpoint.id).\
                filter(PubSubEndpoint.cluster_id==input.cluster_id).\
                filter(PubSubEndpoint.name==input.name).\
                first()

            if existing_one:
                raise Conflict(self.cid, 'Endpoint `{}` already exists'.format(input.name))

            endpoint = PubSubEndpoint()
            endpoint.cluster_id = input.cluster_id
            endpoint.name = input.name
            endpoint.is_active = input.is_active
            endpoint.is_internal = input.is_internal
            endpoint.endpoint_type = input.endpoint_type
            endpoint.role = input.role
            endpoint.topic_patterns = input.topic_patterns
            endpoint.security_id = input.security_id
            endpoint.service_id = input.service_id
            endpoint.ws_channel_id = input.ws_channel_id

            session.add(endpoint)
            session.commit()

            input.action = PUBSUB.ENDPOINT_CREATE.value
            input.id = endpoint.id
            self.broker_client.publish(input)

            self.response.payload.id = endpoint.id
            self.response.payload.name = self.request.input.name
Esempio n. 2
0
    def add_pubsub_service_endpoint(self,
                                    _name=PUBSUB.SERVICE_SUBSCRIBER.NAME):

        existing = self.session.query(PubSubEndpoint.id).\
            filter(PubSubEndpoint.name==_name).\
            first()

        if not existing:

            endpoint = PubSubEndpoint()
            endpoint.name = _name
            endpoint.is_internal = True
            endpoint.role = PUBSUB.ROLE.SUBSCRIBER.id
            endpoint.topic_patterns = PUBSUB.SERVICE_SUBSCRIBER.TOPICS_ALLOWED
            endpoint.endpoint_type = PUBSUB.ENDPOINT_TYPE.SERVICE.id

            if self.cluster:
                endpoint.cluster = self.cluster
            else:
                endpoint.cluster_id = self.cluster_id

            self.session.add(endpoint)