Example #1
0
    def handle(self):
        input = self.request.input

        input.delivery_mode = int(input.delivery_mode)
        input.priority = int(input.priority)
        input.expiration = int(input.expiration) if input.expiration else None

        if not (input.priority >= 0 and input.priority <= 9):
            msg = 'Priority should be between 0 and 9, not [{0}]'.format(
                repr(input.priority))
            raise ValueError(msg)

        with closing(self.odb.session()) as session:
            # Let's see if we already have a definition of that name before committing
            # any stuff into the database.
            existing_one = session.query(OutgoingAMQP.id).\
                filter(ConnDefAMQP.cluster_id==input.cluster_id).\
                filter(OutgoingAMQP.def_id==ConnDefAMQP.id).\
                filter(OutgoingAMQP.name==input.name).\
                first()

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

            try:
                item = OutgoingAMQP()
                item.name = input.name
                item.is_active = input.is_active
                item.def_id = input.def_id
                item.delivery_mode = input.delivery_mode
                item.priority = input.priority
                item.content_type = input.content_type
                item.content_encoding = input.content_encoding
                item.expiration = input.expiration
                item.pool_size = input.pool_size
                item.user_id = input.user_id
                item.app_id = input.app_id

                session.add(item)
                session.commit()

                input.action = OUTGOING.AMQP_CREATE.value
                input.def_name = item.def_.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 outgoing AMQP connection, e:`%s`',
                    format_exc(e))
                session.rollback()

                raise
Example #2
0
File: amqp.py Project: xbx/zato
    def handle(self):
        input = self.request.input

        input.delivery_mode = int(input.delivery_mode)
        input.priority = int(input.priority)

        if not (input.priority >= 0 and input.priority <= 9):
            msg = 'Priority should be between 0 and 9, not [{0}]'.format(
                repr(input.priority))
            raise ValueError(msg)

        with closing(self.odb.session()) as session:
            # Let's see if we already have a definition of that name before committing
            # any stuff into the database.
            existing_one = session.query(OutgoingAMQP.id).\
                filter(ConnDefAMQP.cluster_id==input.cluster_id).\
                filter(OutgoingAMQP.def_id==ConnDefAMQP.id).\
                filter(OutgoingAMQP.name==input.name).\
                first()

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

            try:
                item = OutgoingAMQP()
                item.name = input.name
                item.is_active = input.is_active
                item.def_id = input.def_id
                item.delivery_mode = input.delivery_mode
                item.priority = input.priority
                item.content_type = input.content_type
                item.content_encoding = input.content_encoding
                item.expiration = input.expiration
                item.user_id = input.user_id
                item.app_id = input.app_id

                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 outgoing AMQP connection, e:[{e}]".format(
                    e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Example #3
0
File: amqp.py Project: Adniel/zato
    def handle(self):
        input = self.request.input

        input.delivery_mode = int(input.delivery_mode)
        input.priority = int(input.priority)

        if not(input.priority >= 0 and input.priority <= 9):
            msg = 'Priority should be between 0 and 9, not [{0}]'.format(repr(input.priority))
            raise ValueError(msg)
        
        with closing(self.odb.session()) as session:
            # Let's see if we already have a definition of that name before committing
            # any stuff into the database.
            existing_one = session.query(OutgoingAMQP.id).\
                filter(ConnDefAMQP.cluster_id==input.cluster_id).\
                filter(OutgoingAMQP.def_id==ConnDefAMQP.id).\
                filter(OutgoingAMQP.name==input.name).\
                first()
            
            if existing_one:
                raise Exception('An outgoing AMQP connection [{0}] already exists on this cluster'.format(input.name))
            
            try:
                item = OutgoingAMQP()
                item.name = input.name
                item.is_active = input.is_active
                item.def_id = input.def_id
                item.delivery_mode = input.delivery_mode
                item.priority = input.priority
                item.content_type = input.content_type
                item.content_encoding = input.content_encoding 
                item.expiration = input.expiration
                item.user_id = input.user_id
                item.app_id = input.app_id
                
                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 outgoing AMQP connection, e:[{e}]".format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise 
Example #4
0
File: amqp.py Project: brtsz/zato
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')
            
            core_params = ['cluster_id', 'name', 'is_active', 'def_id', 'delivery_mode', 'priority']
            core_params = _get_params(payload, core_params, 'data.')
            
            optional_params = ['content_type', 'content_encoding', 'expiration', 'user_id', 'app_id']
            optional_params = _get_params(payload, optional_params, 'data.', default_value=None)
        
            priority = int(core_params['priority'])
        
            if not(priority >= 0 and priority <= 9):
                msg = 'Priority should be between 0 and 9, not [{0}]'.format(repr(priority))
                raise ValueError(msg)
            
            name = core_params['name']
            cluster_id = core_params['cluster_id']
            core_params['def_id'] = int(core_params['def_id'])
            
            # Let's see if we already have a definition of that name before committing
            # any stuff into the database.
            existing_one = session.query(OutgoingAMQP.id).\
                filter(ConnDefAMQP.cluster_id==cluster_id).\
                filter(OutgoingAMQP.def_id==ConnDefAMQP.id).\
                filter(OutgoingAMQP.name==name).\
                first()
            
            if existing_one:
                raise Exception('An outgoing AMQP connection[{0}] already exists on this cluster'.format(name))
            
            created_elem = Element('out_amqp')
            
            try:

                core_params['delivery_mode'] = int(core_params['delivery_mode'])
                core_params['priority'] = int(core_params['priority'])
                core_params['is_active'] = is_boolean(core_params['is_active'])
                
                item = OutgoingAMQP()
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.def_id = core_params['def_id']
                item.delivery_mode = core_params['delivery_mode']
                item.priority = core_params['priority']
                item.content_type = optional_params['content_type']
                item.content_encoding = optional_params['content_encoding'] 
                item.expiration = optional_params['expiration']
                item.user_id = optional_params['user_id']
                item.app_id = optional_params['app_id']
                
                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 outgoing AMQP connection, e=[{e}]".format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise