Exemple #1
0
 def handle(self):
     input = self.request.input
     with closing(self.odb.session()) as session:
         existing_one = session.query(OutgoingZMQ.id).\
             filter(OutgoingZMQ.cluster_id==input.cluster_id).\
             filter(OutgoingZMQ.name==input.name).\
             first()
         
         if existing_one:
             raise Exception('An outgoing ZeroMQ connection [{0}] already exists on this cluster'.format(input.name))
         
         try:
             item = OutgoingZMQ()
             item.name = input.name
             item.is_active = input.is_active
             item.address = input.address
             item.socket_type = input.socket_type
             item.cluster_id = input.cluster_id
             
             session.add(item)
             session.commit()
             
             if item.is_active:
                 start_connector(self.server.repo_location, item.id)
             
             self.response.payload.id = item.id
             self.response.payload.name = item.name
             
         except Exception, e:
             msg = 'Could not create an outgoing ZeroMQ connection, e:[{e}]'.format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise 
Exemple #2
0
    def handle(self):
        input = self.request.input
        with closing(self.odb.session()) as session:
            existing_one = session.query(OutgoingZMQ.id).\
                filter(OutgoingZMQ.cluster_id==input.cluster_id).\
                filter(OutgoingZMQ.name==input.name).\
                first()

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

            try:
                item = OutgoingZMQ()
                item.name = input.name
                item.is_active = input.is_active
                item.address = input.address
                item.socket_type = input.socket_type
                item.socket_method = input.socket_method
                item.cluster_id = input.cluster_id

                session.add(item)
                session.commit()

                input.action = OUTGOING.ZMQ_CREATE.value
                self.broker_client.publish(input)

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

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

                raise
Exemple #3
0
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')
            
            core_params = ['cluster_id', 'name', 'is_active', 'address', 'socket_type']
            core_params = _get_params(payload, core_params, 'data.')
            
            name = core_params['name']
            cluster_id = core_params['cluster_id']
            
            existing_one = session.query(OutgoingZMQ.id).\
                filter(OutgoingZMQ.cluster_id==cluster_id).\
                filter(OutgoingZMQ.name==name).\
                first()
            
            if existing_one:
                raise Exception('An outgoing ZeroMQ connection [{0}] already exists on this cluster'.format(name))
            
            created_elem = Element('out_zmq')
            
            try:

                core_params['is_active'] = is_boolean(core_params['is_active'])
                
                item = OutgoingZMQ()
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.address = core_params['address']
                item.socket_type = core_params['socket_type']
                item.cluster_id = core_params['cluster_id']
                
                session.add(item)
                session.commit()
                
                created_elem.id = item.id
                start_connector(self.server.repo_location, item.id)
                
                return ZATO_OK, etree.tostring(created_elem)
                
            except Exception, e:
                msg = 'Could not create an outgoing ZeroMQ connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise