Exemple #1
0
    def handle(self):
        with closing(self.odb.session()) as session:
            input = self.request.input

            # Let's see if we already have a channel of that name before committing
            # any stuff into the database.
            existing_one = session.query(ChannelAMQP.id).\
                filter(ConnDefAMQP.cluster_id==input.cluster_id).\
                filter(ChannelAMQP.def_id==ConnDefAMQP.id).\
                filter(ChannelAMQP.name==input.name).\
                first()

            if existing_one:
                raise Exception(
                    'An AMQP channel `{}` already exists on this cluster'.
                    format(input.name))

            # Is the service's name correct?
            service = session.query(Service).\
                filter(Cluster.id==input.cluster_id).\
                filter(Service.cluster_id==Cluster.id).\
                filter(Service.name==input.service).\
                first()

            if not service:
                msg = 'Service `{}` does not exist on this cluster'.format(
                    input.service)
                raise Exception(msg)

            try:
                item = ChannelAMQP()
                item.name = input.name
                item.is_active = input.is_active
                item.queue = input.queue
                item.consumer_tag_prefix = input.consumer_tag_prefix
                item.def_id = input.def_id
                item.service = service
                item.pool_size = input.pool_size
                item.ack_mode = input.ack_mode
                item.prefetch_count = input.prefetch_count
                item.data_format = input.data_format

                session.add(item)
                session.commit()

                input.action = CHANNEL.AMQP_CREATE.value
                input.def_name = item.def_.name
                input.id = item.id
                input.service_name = service.name
                self.broker_client.publish(input)

                self.response.payload.id = item.id
                self.response.payload.name = item.name

            except Exception, e:
                self.logger.error('Could not create an AMQP channel, e:`%s`',
                                  format_exc(e))
                session.rollback()

                raise
Exemple #2
0
 def setUp(self):
     self.service_class = Delete
     self.sio = self.service_class.SimpleIO
     self.id = rand_int()
     self.name = rand_string()
     self.mock_data = {
         'odb': [{'session.query.filter.one': ChannelAMQP(self.id, self.name)}
                 ]
         }
Exemple #3
0
    def handle(self):
        with closing(self.odb.session()) as session:
            input = self.request.input

            # Let's see if we already have a channel of that name before committing
            # any stuff into the database.
            existing_one = session.query(ChannelAMQP.id).\
                filter(ConnDefAMQP.cluster_id==input.cluster_id).\
                filter(ChannelAMQP.def_id==ConnDefAMQP.id).\
                filter(ChannelAMQP.name==input.name).\
                first()

            if existing_one:
                raise Exception(
                    'An AMQP channel [{0}] already exists on this cluster'.
                    format(input.name))

            # Is the service's name correct?
            service = session.query(Service).\
                filter(Cluster.id==input.cluster_id).\
                filter(Service.cluster_id==Cluster.id).\
                filter(Service.name==input.service).\
                first()

            if not service:
                msg = 'Service [{0}] does not exist on this cluster'.format(
                    input.service)
                raise Exception(msg)

            try:
                item = ChannelAMQP()
                item.name = input.name
                item.is_active = input.is_active
                item.queue = input.queue
                item.consumer_tag_prefix = input.consumer_tag_prefix
                item.def_id = input.def_id
                item.service = service
                item.data_format = input.data_format

                session.add(item)
                session.commit()

                if item.is_active:
                    start_connector(self.server.repo_location, item.id,
                                    item.def_id)

                self.response.payload.id = item.id
                self.response.payload.name = item.name

            except Exception, e:
                msg = 'Could not create an AMQP channel, e:[{e}]'.format(
                    e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Exemple #4
0
 def setUp(self):
     self.service_class = Edit
     self.sio = self.service_class.SimpleIO
     self.id = rand_int()
     self.def_id = rand_int()
     self.name = rand_string()
     self.mock_data = {
         'odb': [{'session.query.filter.filter.filter.filter.first': False},
                 {'session.query.filter.filter.first': Service()},
                 {'session.query.filter_by.one': ChannelAMQP(self.id)},
                 ]
         }