From f935ec7070bd57f696845143eccd8f33eb9b827a Mon Sep 17 00:00:00 2001 From: Umar Farooq Ghumman Date: Tue, 14 May 2024 11:04:16 -0500 Subject: [PATCH] Updated Connection Page to include Logging --- project/ui/conn.ipynb | 54 ++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/project/ui/conn.ipynb b/project/ui/conn.ipynb index 09c6598e..5ae38d5e 100644 --- a/project/ui/conn.ipynb +++ b/project/ui/conn.ipynb @@ -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, @@ -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", @@ -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')" ] }, { @@ -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", @@ -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')" ] }, { @@ -114,7 +135,8 @@ " database,\n", " name,\n", " connection_timeout\n", - "]))" + "]))\n", + "logging.info('[Connection Page] Displayed all widgets')" ] }, { @@ -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')" ] }, { @@ -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')" ] }, { @@ -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", @@ -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", @@ -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" ] @@ -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", @@ -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)" ] @@ -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",