Esempio n. 1
0
    def handle(self):
        input = self.request.input

        with closing(self.odb.session()) as session:
            existing_one = session.query(ChannelZMQ.id).\
                filter(ChannelZMQ.cluster_id==input.cluster_id).\
                filter(ChannelZMQ.name==input.name).\
                first()

            if existing_one:
                raise Exception(
                    'A ZeroMQ 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 = ChannelZMQ()
                item.name = input.name
                item.is_active = input.is_active
                item.address = input.address
                item.socket_type = input.socket_type
                item.sub_key = input.get('sub_key', b'')
                item.cluster_id = input.cluster_id
                item.service = service
                item.data_format = input.data_format

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

                raise
Esempio n. 2
0
File: zmq.py Progetto: lucval/zato
    def handle(self):
        input = self.request.input

        with closing(self.odb.session()) as session:
            existing_one = (
                session.query(ChannelZMQ.id)
                .filter(ChannelZMQ.cluster_id == input.cluster_id)
                .filter(ChannelZMQ.name == input.name)
                .first()
            )

            if existing_one:
                raise Exception("A ZeroMQ 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 = ChannelZMQ()
                item.name = input.name
                item.is_active = input.is_active
                item.address = input.address
                item.socket_type = input.socket_type
                item.sub_key = input.get("sub_key", b"")
                item.cluster_id = input.cluster_id
                item.service = service
                item.data_format = input.data_format

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

                raise
Esempio n. 3
0
File: zmq.py Progetto: 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', 'address', 'socket_type', 'service']
            core_params = _get_params(payload, core_params, 'data.')
            
            optional_params = ['sub_key']
            optional_params = _get_params(payload, optional_params, 'data.', default_value=None)
            
            name = core_params['name']
            service_name = core_params['service']
            cluster_id = core_params['cluster_id']
            
            existing_one = session.query(ChannelZMQ.id).\
                filter(ChannelZMQ.cluster_id==cluster_id).\
                filter(ChannelZMQ.name==name).\
                first()
            
            if existing_one:
                raise Exception('A ZeroMQ 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_zmq')
            
            try:

                core_params['is_active'] = is_boolean(core_params['is_active'])
                
                item = ChannelZMQ()
                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.sub_key = optional_params.get('sub_key')
                item.cluster_id = core_params['cluster_id']
                item.service = service
                
                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 a ZeroMQ channel, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()
                
                raise 
Esempio n. 4
0
    def handle(self):
        input = self.request.input
        require_tcp_port(input.address)

        with closing(self.odb.session()) as session:
            existing_one = session.query(ChannelZMQ.id).\
                filter(ChannelZMQ.cluster_id==input.cluster_id).\
                filter(ChannelZMQ.name==input.name).\
                first()

            if existing_one:
                raise Exception('A ZeroMQ channel `{}` already exists in this cluster'.format(input.name))

            # Is the service's name correct?
            service = session.query(ServiceModel).\
                filter(Cluster.id==input.cluster_id).\
                filter(ServiceModel.cluster_id==Cluster.id).\
                filter(ServiceModel.name==input.service).first()

            if not service:
                msg = 'Service `{}` does not exist in this cluster'.format(input.service)
                raise Exception(msg)

            try:

                sub_key = input.get('sub_key', b'')

                item = ChannelZMQ()
                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.sub_key = sub_key
                item.cluster_id = input.cluster_id
                item.service = service
                item.pool_strategy = input.pool_strategy
                item.service_source = input.service_source
                item.data_format = input.data_format

                session.add(item)
                session.commit()

                input.action = CHANNEL.ZMQ_CREATE.value
                input.sub_key = sub_key
                input.service_name = service.name
                input.source_server = self.server.get_full_name()
                input.id = item.id
                input.config_cid = 'channel.zmq.create.{}.{}'.format(input.source_server, self.cid)

                self.broker_client.publish(input)

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

            except Exception:
                self.logger.error('ZeroMQ channel could not be created, e:`%s`', format_exc())
                session.rollback()

                raise
Esempio n. 5
0
    def handle(self):
        input = self.request.input

        with closing(self.odb.session()) as session:
            existing_one = session.query(ChannelZMQ.id).\
                filter(ChannelZMQ.cluster_id==input.cluster_id).\
                filter(ChannelZMQ.name==input.name).\
                first()

            if existing_one:
                raise Exception('A ZeroMQ 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:

                sub_key = input.get('sub_key', b'')

                item = ChannelZMQ()
                item.name = input.name
                item.is_active = input.is_active
                item.address = input.address
                item.socket_type = input.socket_type
                item.sub_key = sub_key
                item.socket_method = input.socket_method
                item.cluster_id = input.cluster_id
                item.service = service
                item.pool_strategy = input.pool_strategy
                item.service_source = input.service_source
                item.data_format = input.data_format

                session.add(item)
                session.commit()

                input.action = CHANNEL.ZMQ_CREATE.value
                input.sub_key = sub_key
                input.service = service.impl_name
                self.broker_client.publish(input)

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

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

                raise