Пример #1
0
    def handle(self):
        input = self.request.input

        with closing(self.odb.session()) as session:
            # Let's see if we already have an account 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).\
                filter(ChannelAMQP.id!=input.id).\
                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 = session.query(ChannelAMQP).filter_by(id=input.id).one()
                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()

                self.delete_channel(item)
                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 update the AMQP definition, e:[{e}]'.format(
                    e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Пример #2
0
 def handle(self):
     input = self.request.input
     
     with closing(self.odb.session()) as session:
         # Let's see if we already have an account 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).\
             filter(ChannelAMQP.id!=input.id).\
             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.name==input.service).\
             first()
         
         if not service:
             msg = 'Service [{0}] does not exist on this cluster'.format(input.service)
             raise Exception(msg)
         
         try:
             item = session.query(ChannelAMQP).filter_by(id=input.id).one()
             old_name = item.name
             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()
             
             self.delete_channel(item)
             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 update the AMQP definition, e:[{e}]'.format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise  
Пример #3
0
Файл: amqp.py Проект: brtsz/zato
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')
            
            params = ['cluster_id', 'name', 'is_active', 'def_id', 'queue', 
                      'consumer_tag_prefix', 'service']
            params = _get_params(payload, params, 'data.')
            
            name = params['name']
            cluster_id = params['cluster_id']
            service_name = params['service']
            params['def_id'] = int(params['def_id'])
            
            # 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==cluster_id).\
                filter(ChannelAMQP.def_id==ConnDefAMQP.id).\
                filter(ChannelAMQP.name==name).\
                first()
            
            if existing_one:
                raise Exception('An AMQP channel [{0}] already exists on this cluster'.format(name))
            
            # Is the service's name correct?
            service = session.query(Service).\
                filter(Cluster.id==cluster_id).\
                filter(Service.name==service_name).first()
            
            if not service:
                msg = 'Service [{0}] does not exist on this cluster'.format(service_name)
                raise Exception(msg)
            
            created_elem = Element('channel_amqp')
            
            try:

                params['is_active'] = is_boolean(params['is_active'])
                
                item = ChannelAMQP()
                item.name = params['name']
                item.is_active = params['is_active']
                item.queue = params['queue']
                item.consumer_tag_prefix = params['consumer_tag_prefix']
                item.def_id = params['def_id']
                item.service = service
                
                session.add(item)
                session.commit()
                
                created_elem.id = item.id
                start_connector(self.server.repo_location, item.id, item.def_id)
                
                return ZATO_OK, etree.tostring(created_elem)
                
            except Exception, e:
                msg = 'Could not create an AMQP channel, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise