예제 #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
파일: jms_wmq.py 프로젝트: danlg/zato
    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 IBM MQ connection `{}` 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

                # Commit to DB
                session.add(item)
                session.commit()

                # Notify other servers
                input.id = item.id
                input.action = OUTGOING.WMQ_CREATE.value
                self.broker_client.publish(input)

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

            except Exception:
                self.logger.error(
                    'Could not create an outgoing IBM MQ connection, e:`%s`',
                    format_exc())
                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
예제 #4
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