def handle(self): with closing(self.odb.session()) as session: input = self.request.input # Let's see if we already have a channel of that name before committing # any stuff into the database. existing_one = session.query(ChannelAMQP.id).\ filter(ConnDefAMQP.cluster_id==input.cluster_id).\ filter(ChannelAMQP.def_id==ConnDefAMQP.id).\ filter(ChannelAMQP.name==input.name).\ first() if existing_one: raise Exception( 'An AMQP channel `{}` 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.cluster_id==Cluster.id).\ filter(Service.name==input.service).\ first() if not service: msg = 'Service `{}` does not exist on this cluster'.format( input.service) raise Exception(msg) try: item = ChannelAMQP() item.name = input.name item.is_active = input.is_active item.queue = input.queue item.consumer_tag_prefix = input.consumer_tag_prefix item.def_id = input.def_id item.service = service item.pool_size = input.pool_size item.ack_mode = input.ack_mode item.prefetch_count = input.prefetch_count item.data_format = input.data_format session.add(item) session.commit() input.action = CHANNEL.AMQP_CREATE.value input.def_name = item.def_.name input.id = item.id input.service_name = service.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 AMQP channel, e:`%s`', format_exc(e)) session.rollback() raise
def handle(self): with closing(self.odb.session()) as session: input = self.request.input # Let's see if we already have a channel of that name before committing # any stuff into the database. existing_one = session.query(ChannelAMQP.id).\ filter(ConnDefAMQP.cluster_id==input.cluster_id).\ filter(ChannelAMQP.def_id==ConnDefAMQP.id).\ filter(ChannelAMQP.name==input.name).\ first() if existing_one: raise Exception( 'An AMQP 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.cluster_id==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 = ChannelAMQP() item.name = input.name item.is_active = input.is_active item.queue = input.queue item.consumer_tag_prefix = input.consumer_tag_prefix item.def_id = input.def_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, item.def_id) self.response.payload.id = item.id self.response.payload.name = item.name except Exception, e: msg = 'Could not create an AMQP channel, e:[{e}]'.format( e=format_exc(e)) self.logger.error(msg) session.rollback() raise
def handle(self): with closing(self.odb.session()) as session: input = self.request.input # Let's see if we already have a channel of that name before committing # any stuff into the database. existing_one = session.query(ChannelAMQP.id).\ filter(ConnDefAMQP.cluster_id==input.cluster_id).\ filter(ChannelAMQP.def_id==ConnDefAMQP.id).\ filter(ChannelAMQP.name==input.name).\ first() if existing_one: raise Exception('An AMQP 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 = ChannelAMQP() item.name = input.name item.is_active = input.is_active item.queue = input.queue item.consumer_tag_prefix = input.consumer_tag_prefix item.def_id = input.def_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, item.def_id) self.response.payload.id = item.id self.response.payload.name = item.name except Exception, e: msg = 'Could not create an AMQP channel, e:[{e}]'.format(e=format_exc(e)) self.logger.error(msg) session.rollback() raise
def handle(self, *args, **kwargs): with closing(self.server.odb.session()) as session: payload = kwargs.get('payload') params = ['cluster_id', 'name', 'is_active', 'def_id', 'queue', 'consumer_tag_prefix', 'service'] params = _get_params(payload, params, 'data.') name = params['name'] cluster_id = params['cluster_id'] service_name = params['service'] params['def_id'] = int(params['def_id']) # Let's see if we already have a channel of that name before committing # any stuff into the database. existing_one = session.query(ChannelAMQP.id).\ filter(ConnDefAMQP.cluster_id==cluster_id).\ filter(ChannelAMQP.def_id==ConnDefAMQP.id).\ filter(ChannelAMQP.name==name).\ first() if existing_one: raise Exception('An AMQP 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_amqp') try: params['is_active'] = is_boolean(params['is_active']) item = ChannelAMQP() item.name = params['name'] item.is_active = params['is_active'] item.queue = params['queue'] item.consumer_tag_prefix = params['consumer_tag_prefix'] item.def_id = params['def_id'] item.service = service 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 AMQP channel, e=[{e}]'.format(e=format_exc(e)) self.logger.error(msg) session.rollback() raise