<jupyter_start><jupyter_text>[![](./media/Db2_header_3.png)](https://www.ibm.com/demos/collection/db2-database/)<jupyter_code>%run refresh.ipynb<jupyter_output><empty_output><jupyter_text>Create Node JS Application on OpenShift Connecting to Db2This lab will take the user through the steps required take an application on GitHub and deploy it on Red Hat OpenShift connecting to Db2.In this hands-on lab you will1. Connect to Red Hat OpenShift2. Install a sample NodeJS application3. Run the application and connect it to Db2, also running on OpenShift4. Explore the impact of the application through the Db2 Console  How to Copy Code and ExamplesThroughout this lab there are code samples that need to be copied and modified in a text editor. Any commands that need to be executed from a command line are found in grey boxes (an example is found below) has been designed to be easily copied.<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black;" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
Sample commands are found in cells like this.
</pre>
</div><jupyter_output><empty_output><jupyter_text>Highlight the text and copy it using **Copy** from the right click menu or type Ctrl-C. Paste the command into the Command terminal using **Paste** from the right click menu or type Ctrl-V.It may be easier to keep a terminal window on top of the Jupyter notebook when running these commands. When you have a terminal window displayed, right click on the title bar and select `Always on Top` to keep the screen visible during the duration of the lab.  About the Node.js Application you will deployThis application is designed to give you a simple introduction to deploying Node applications on OpenShift that wil work with Db2 using the Db2 Opensource Node.js drivers.These drivers are kept at https://github.com/ibmdb. The AppIBM® Db2 NodeJS Mock Webstore simulates dozens or hundreds of users making online orders separately at the same time, and includes supporting quantities of queries through two connection pools connecting with Db2.This demo is a simple implementation of an application based on Node.js runtime environment, demonstrating how Node.js applications connect to Db2. It includes examples of running both regular SQL statements as well as JSON capabilities. This Lab will combine Command Line and Openshift Console Activities to build the Node.js Application.The source for this application is available on GitHub at https://github.com/Db2-DTE-POC/db2-nodejs-web-app.  The Virtual Machine EnvironmentThere are four virtual machines or nodes in this environment. All are running on Centos 7 virtual machines.* host-1 (10.0.0.1) **RedHat OpenShift with Db2 172.16.17.32 Cartridge**    * Main UserID: db2pot    * password: <PASSWORD>* server7 (10.0.0.2) **Db2 11.1 on Premises installation**    * Main UserID: db2inst1    * password: <PASSWORD>* host-2 (10.0.0.3) **Db2 Data Management Console 3.1.3 and Db2 11.5 Repository Database**    * Main UserID: db2inst1    * password: <PASSWORD>* host-3 (10.0.0.4) **Jupyter Notebook Environment**    * Main UserID: ibmuser    * password: <PASSWORD>    Passwords for this LabHere are the key passwords you will need to complete the lab. Each virtual machine environment also include a key icon. Click on the icon to see and copy userids and passwords associated with each virtual machine. Operating system login & Web App Login        UserID: db2pot        password: <PASSWORD>3 Openshift Login         UserID: admin        password: <PASSWORD>hat Db2 Login        UserID: db2inst1        password: <PASSWORD>  Creating the Node.js environment  Log into OpenShift from the Command Line1. You should already be using the **Db2 Source Data Server** Virtual Machine 2. If you have not already done so, log in with the **db2inst1** userid and **db2inst1** password3. Double-Click the **Terminal** icon4. From the db2inst1@server7 prompt enter<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black;" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
ssh db2pot@host-1
</pre>
</div><jupyter_output><empty_output><jupyter_text>2. Enter the db2pot password **<PASSWORD>**3. Enter **yes** to continue connectingYou should now see the **db2pot@host-1** command line prompt4. Log into OpenShift using the OC command  Log into Red Hat OpenShiftNow that you have a terminal logged into your OpenShift machine you can log into OpenShift.<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
oc login -u admin -n db2
</pre>
</div><jupyter_output><empty_output><jupyter_text>Create a new OpenShift ProjectCreate a project for your new application.<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
oc new-project db2node
</pre>
</div><jupyter_output><empty_output><jupyter_text>Pull the container for the Node.js application from Docker.<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
sudo docker pull centos/nodejs-12-centos7
</pre>
</div><jupyter_output><empty_output><jupyter_text>Deploy the application, which is stored in a github repositoryhttps://github.com/Db2-DTE-POC/db2-nodejs-web-app.<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
oc new-app nodejs~https://github.com/Db2-DTE-POC/db2-nodejs-web-app
</pre>
</div><jupyter_output><empty_output><jupyter_text>Monitor the application's deployment progress using the following command.<jupyter_code>%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black;" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
oc get pods
</pre>
</div>
%%html
<div style="margin-left: 35px; border-style: solid; border-width: 1px; padding: 10px;background-Color:black;" >
<p style=" color:white ;font-family:courier;background-Color:black"
<pre>
sudo restorecon -Rv /home/db2pot/db2vol1
</pre>
</div><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09758308157099697, 'fraction_numerical': 0.022205438066465258, 'mean_word_length': 5.341954022988506, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 73, 'https://': 5, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '129777', 'license': 'Apache-2.0', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1941, 'n_words': 757, 'path': 'media/Create_Db2_Node_JS_Application.ipynb', 'repo_name': 'Db2-DTE-POC/Db2-Click-To-Containerize-Lab', 'size': '6598'}