示例#1
0
文件: jms_wmq.py 项目: 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 = ['expiration']
            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'])
            
            existing_one = session.query(OutgoingWMQ.id).\
                filter(ConnDefWMQ.cluster_id==cluster_id).\
                filter(OutgoingWMQ.def_id==ConnDefWMQ.id).\
                filter(OutgoingWMQ.name==name).\
                first()
            
            if existing_one:
                raise Exception('An outgoing JMS WebSphere MQ connection [{0}] already exists on this cluster'.format(name))
            
            created_elem = Element('out_jms_wmq')
            
            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 = OutgoingWMQ()
                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.expiration = optional_params['expiration']
                
                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 JMS WebSphere MQ connection, 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:
            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)

            existing_one = session.query(OutgoingWMQ.id).\
                filter(ConnDefWMQ.cluster_id==input.cluster_id).\
                filter(OutgoingWMQ.def_id==ConnDefWMQ.id).\
                filter(OutgoingWMQ.name==input.name).\
                first()

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

            try:
                item = OutgoingWMQ()
                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.expiration = input.expiration

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

                raise
示例#3
0
 def handle(self):
     input = self.request.input
     with closing(self.odb.session()) as session:
         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)
         
         existing_one = session.query(OutgoingWMQ.id).\
             filter(ConnDefWMQ.cluster_id==input.cluster_id).\
             filter(OutgoingWMQ.def_id==ConnDefWMQ.id).\
             filter(OutgoingWMQ.name==input.name).\
             first()
         
         if existing_one:
             raise Exception('An outgoing JMS WebSphere MQ connection [{0}] already exists on this cluster'.format(input.name))
         
         try:
             item = OutgoingWMQ()
             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.expiration = input.expiration
             
             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 JMS WebSphere MQ connection, e:[{e}]'.format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise