def handle(self): input = self.request.input input.password = uuid4().hex 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).\ first() if existing_one: raise Exception( 'An outgoing SQL connection [{0}] already exists on this cluster' .format(input.name)) try: cluster = session.query(Cluster).filter_by( id=input.cluster_id).one() item = SQLConnectionPool(cluster=cluster) item.name = input.name item.is_active = input.is_active item.engine = input.engine item.host = input.host item.port = input.port item.db_name = input.db_name item.username = input.username item.password = input.password item.pool_size = input.pool_size item.extra = input.extra session.add(item) session.commit() 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 created, e:`{}`', format_exc()) session.rollback() raise
def index(req): """ Lists all the SQL connections. """ items = [] create_form = CreateForm() edit_form = EditForm(prefix='edit') change_password_form = ChangePasswordForm() if req.zato.cluster_id and req.method == 'GET': zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:outgoing.sql.get-list', {'cluster_id': req.zato.cluster_id}) if zato_path('response.item_list.item').get_from(zato_message) is not None: for msg_item in zato_message.response.item_list.item: id = msg_item.id.text name = msg_item.name.text is_active = is_boolean(msg_item.is_active.text) engine = msg_item.engine.text if msg_item.engine else '' host = msg_item.host.text if msg_item.host else '' port = msg_item.port.text if msg_item.port else '' db_name = msg_item.db_name.text if msg_item.db_name else '' username = msg_item.username.text if msg_item.username else '' pool_size = msg_item.pool_size.text if msg_item.pool_size else '' extra = msg_item.extra.text if msg_item.extra else '' item = SQLConnectionPool() item.id = id item.name = name item.is_active = is_active item.engine = engine item.engine_text = odb_engine_friendly_name[engine] item.host = host item.port = port item.db_name = db_name item.username = username item.pool_size = pool_size item.extra = extra items.append(item) return_data = {'zato_clusters':req.zato.clusters, 'cluster_id':req.zato.cluster_id, 'choose_cluster_form':req.zato.choose_cluster_form, 'items':items, 'create_form':create_form, 'edit_form':edit_form, 'change_password_form': change_password_form } return TemplateResponse(req, 'zato/outgoing/sql.html', return_data)
def handle(self): input = self.request.input input.password = uuid4().hex 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).\ first() if existing_one: raise Exception( 'An outgoing SQL connection [{0}] already exists on this cluster' .format(input.name)) try: item = SQLConnectionPool() 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.password = input.password item.pool_size = input.pool_size item.extra = input.extra session.add(item) session.commit() self.notify_worker_threads(input) self.response.payload.id = item.id self.response.payload.name = item.name except Exception, e: msg = 'Could not create an outgoing SQL connection, e:[{e}]'.format( e=format_exc(e)) self.logger.error(msg) session.rollback() raise
def handle(self): input = self.request.input input.password = uuid4().hex 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).\ first() if existing_one: raise Exception('An outgoing SQL connection [{0}] already exists on this cluster'.format(input.name)) try: item = SQLConnectionPool() 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.password = input.password item.pool_size = input.pool_size item.extra = input.extra session.add(item) session.commit() self.notify_worker_threads(input) self.response.payload.id = item.id self.response.payload.name = item.name except Exception, e: msg = 'Could not create an outgoing SQL connection, e:[{e}]'.format(e=format_exc(e)) self.logger.error(msg) session.rollback() raise