Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Connection Page to include Logging #258

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions project/ui/conn.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "e0bbd6b3-4faf-4419-a70e-2cf270e5f85a",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import logging\n",
"\n",
"log_folder = 'logs'\n",
"if not os.path.exists(log_folder):\n",
" os.makedirs(log_folder)\n",
"logging.basicConfig(filename='logs/jupyter_log.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -9,7 +25,7 @@
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display, HTML\n",
"\n",
"logging.info('[Connection Page] Creating top buttons')\n",
"# Define the URLs for the links\n",
"url1 = \"/lab/\"\n",
"url2 = \"/voila/render/ui/qprof_main.ipynb\"\n",
Expand Down Expand Up @@ -46,13 +62,15 @@
"metadata": {},
"outputs": [],
"source": [
"logging.info('[Connection Page] Importing libraries')\n",
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"import ipywidgets as widgets\n",
"from IPython.display import display,clear_output, HTML\n",
"from ipyfilechooser import FileChooser\n",
"import ssl\n",
"\n",
"import verticapy as vp"
"import verticapy as vp\n",
"logging.info('[Connection Page] Imported all libraries')"
]
},
{
Expand All @@ -63,6 +81,7 @@
"outputs": [],
"source": [
"# style = {'description_width': '150px', 'width' : '400px'}\n",
"logging.info('[Connection Page] Creating the widgets for input')\n",
"host = widgets.Text(description = \"Host\",placeholder = \"Enter Host (default is 'verticadb')\", layout=widgets.Layout(width='350px'))\n",
"port = widgets.Text(description = \"Port\", placeholder = \"Enter Port (default is 5433)\", layout=widgets.Layout(width='350px'))\n",
"user = widgets.Text(description = \"User name\", placeholder = \"Enter User Name (default is 'dbadmin')\", layout=widgets.Layout(width='350px'))\n",
Expand All @@ -86,7 +105,9 @@
"kerberos_service_name = widgets.Text(description = \"Kerberos service name\", placeholder = \"Enter Name\", layout=widgets.Layout(width='500px'))\n",
"kerberos_service_name.style.description_width = '150px'\n",
"\n",
"backup_server_node = [\"localhost\"]"
"backup_server_node = [\"localhost\"]\n",
"\n",
"logging.info('[Connection Page] Created all widgets')"
]
},
{
Expand Down Expand Up @@ -114,7 +135,8 @@
" database,\n",
" name,\n",
" connection_timeout\n",
"]))"
"]))\n",
"logging.info('[Connection Page] Displayed all widgets')"
]
},
{
Expand Down Expand Up @@ -148,7 +170,8 @@
"\n",
"# Call function when radio button value changes\n",
"tls_params.observe(lambda change: display_widget_tls(change['new']), names='value')\n",
"\n"
"\n",
"logging.info('[Connection Page] TLS widegt done')"
]
},
{
Expand Down Expand Up @@ -188,7 +211,8 @@
" ssl_context\n",
"\n",
"# Call function when dropdown value changes\n",
"dropdown.observe(lambda change: display_widget_advanced_connection(change['new']), names='value')"
"dropdown.observe(lambda change: display_widget_advanced_connection(change['new']), names='value')\n",
"logging.info('[Connection Page] Advanced setting connection done')"
]
},
{
Expand All @@ -198,8 +222,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"advanced_options = widgets.VBox([dropdown,output_advanced_connection, autocommit])\n",
"\n",
"accordion = widgets.Accordion(children=[advanced_options], titles=('Advanced Options',))\n",
Expand All @@ -213,13 +235,11 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"button = widgets.Button(description=\"Create a Connection\")\n",
"output = widgets.Output(layout={'border': '1px solid black'})\n",
"display(button, output)\n",
"\n",
"\n",
"\n",
"def on_button_clicked(b):\n",
" output.clear_output(wait=True) # Clear the output\n",
" global ssl_context\n",
Expand All @@ -233,23 +253,22 @@
" 'password': password.value if password.value else \"\",\n",
" 'database': database.value if database.value else \"demo\",\n",
" 'ssl': ssl_context if dropdown.value ==\"TLS\" else False,\n",
" 'connection_timeout': eval(connection_timeout.value) if not connection_timeout.value == \"\" else 5,\n",
" }\n",
" logging.info(f\"\"\"[Connection Page] Trying to connect with the following parameters: {conn_info},\"\"\")\n",
" vp.new_connection(\n",
" conn_info,\n",
" name = name.value if name.value else \"VerticaDSN\",\n",
" auto = True,\n",
" overwrite = True,)\n",
" print(\"Successfully connected to the database:\", vp.current_connection().options['database'])\n",
"button.on_click(on_button_clicked)\n",
"\n"
"button.on_click(on_button_clicked)"
]
},
{
"cell_type": "markdown",
"id": "4caf85a1-a3f9-4dd2-af9f-f2a43d239ed1",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"metadata": {},
"source": [
"## Or Select From List"
]
Expand All @@ -265,7 +284,7 @@
"\n",
"selection = widgets.Dropdown(\n",
" options=vp.available_connections(),\n",
" description='Available Coneections:',\n",
" description='Available Connections:',\n",
" disabled=False, layout=widgets.Layout(width='300px'))\n",
"selection.style.description_width = '150px'\n",
"\n",
Expand All @@ -278,6 +297,7 @@
" with output_2:\n",
" vp.connect(selection.value)\n",
" change_auto_connection(selection.value)\n",
" logging.info(f\"\"\"[Connection Page] Trying to connect to the following connection: {selection.value},\"\"\")\n",
" print(\"Successfully connected to the database:\", vp.current_connection().options['database'])\n",
"button_select.on_click(on_button_clicked_select)"
]
Expand Down Expand Up @@ -335,9 +355,11 @@
"\n",
"def install_verticapy(_):\n",
" with output_install:\n",
" logging.info(f\"\"\"[Connection Page] Trying install verticapy\"\"\")\n",
" subprocess.run([\"pip\", \"install\", \"git+https://github.com/vertica/VerticaPy.git@master\"])\n",
" print(\"Successfully installed latest verticapy from the master branch.\")\n",
" print(\"Note: You must refresh to get the latest version.\")\n",
" logging.info(f\"\"\"Successfully isntalled verticapy\"\"\")\n",
"\n",
"install_button = widgets.Button(description=\"Install latest verticapy\")\n",
"install_button.on_click(install_verticapy)\n",
Expand Down
Loading