Beispiel #1
0
 def handle(self):
     with closing(self.odb.session()) as session:
         data = self.get_data(session)
         for item in data:
             item.engine_display_name = get_sql_engine_display_name(
                 item.engine, self.server.fs_sql_config)
         self.response.payload[:] = data
Beispiel #2
0
    def handle(self):
        input = self.request.input
        input.extra = input.extra.encode('utf-8') if input.extra else b''

        self.validate_extra(self.cid, input.extra.decode('utf-8'))

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

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

            try:
                item = session.query(SQLConnectionPool).filter_by(
                    id=input.id).one()
                old_name = item.name
                item.name = input.name
                item.is_active = input.is_active
                item.cluster_id = input.cluster_id
                item.engine = input.engine
                item.host = input.host
                item.port = input.port
                item.db_name = input.db_name
                item.username = input.username
                item.pool_size = input.pool_size
                item.extra = input.extra.encode('utf8') if isinstance(
                    input.extra, unicode) else input.extra

                session.add(item)
                session.commit()

                input.password = item.password
                input.old_name = old_name
                self.notify_worker_threads(input)

                self.response.payload.id = item.id
                self.response.payload.name = item.name
                self.response.payload.display_name = get_sql_engine_display_name(
                    input.engine, self.server.fs_sql_config)

            except Exception:
                self.logger.error(
                    'SQL connection could not be updated, e:`{}`',
                    format_exc())
                session.rollback()

                raise