Prerequisite of running Jupyter Notebook with IBM Db2 Event Store
In IBM® Db2® Event Store, you have to complete the following instructions before you can use Jupyter Notebook with Db2 Event Store.
About this task
IBM Db2 Event Store can run in a Jupyter Notebook that comes with IBM Watson™ Studio or IBM Cloud Pak for Data. You have to properly configure the connection to the target Db2 Event Store instance before running the Jupyter Notebook. The following steps are different based on the platform you are using.
Prerequisite steps for IBM Watson Studio
- You have to run the following code in the first code cell in the Notebook. You have to replace
the
<userid>and<password>with your IBM Watson Studio username and password, respectively.Note: You should only choose one of the following cells to run, based on your Notebook language.- Run the following in the Python
Notebook:
# Only run this in the Python Notebook from eventstore.common import ConfigurationReader ConfigurationReader.setEventUser("<userid>") ConfigurationReader.setEventPassword("<password>") - Run the following in the Scala
Notebook:
// Only run this in the Scala Notebook import com.ibm.event.common.ConfigurationReader ConfigurationReader.setEventUser("<userid>") ConfigurationReader.setEventPassword("<password>")
- Run the following in the Python
Notebook:
Prerequisite steps for IBM Cloud Pak for Data
- Link the Db2 Event Store Python library to the current Notebook kernel.
- Configure the Jupyter Notebook connection.
You have to run the following code in the first code cell in the Notebook to configure the connection to the target Db2 Event Store instance.
Note: You should only choose one of the following cells to run, based on your Notebook language.- Run either Step a OR Step b in the Python Notebook based on which version of
IBM Cloud Pak for Data you have:
-
If you are running IBM Cloud Pak for Data 3.0 or before, run this:
# Only run this in the Python Notebook # This link is created to ensure that the Event Store Python # library is properly exposed to the Spark runtime import os import traceback src = '/home/spark/user_home/eventstore/eventstore' dst = '/home/spark/shared/user-libs/python3.6/eventstore' try: os.remove(dst) print("Creating symlink to include Event Store Python library...") except EnvironmentError as e: print("Symlink doesn't exist, creating symlink to include Event Store library...") os.symlink(src, dst) from eventstore.common import ConfigurationReader ConfigurationReader.setEventUser("<userid>") ConfigurationReader.setEventPassword("<password>") ConfigurationReader.setConnectionEndpoints("<SCALA_CONNECTION_ENDPOINT>") ConfigurationReader.setDeploymentID("<DEPLOYMENT ID>") -
If you are running IBM Cloud Pak for Data higher than 3.0, run this:
from eventstore.common import ConfigurationReader ConfigurationReader.setEventUser("<userid>") ConfigurationReader.setEventPassword("<password>") ConfigurationReader.setConnectionEndpoints("<SCALA_CONNECTION_ENDPOINT>") ConfigurationReader.setDeploymentID("<DEPLOYMENT ID>")
-
- Run the following in the Scala
Notebook:
// Only run this in the Scala Notebook import com.ibm.event.common.ConfigurationReader ConfigurationReader.setEventUser("<userid>") ConfigurationReader.setEventPassword("<password>") ConfigurationReader.setConnectionEndpoints("<SCALA_CONNECTION_ENDPOINT>") ConfigurationReader.setDeploymentID("<DEPLOYMENT ID>")
Replace the information from the code samples where appropriate:<userid>: your IBM Cloud Pak for Data username.<password>: your IBM Cloud Pak for Data password.<DEPLOYMENT ID>: you can get this from the Database details page in the IBM Cloud Pak for Data UI console.<SCALA_CONNECTION_ENDPOINT>: the Scala connection endpoint of the target Db2 Event Store deployment. It can be found in the Scala Connection URL in the Database details page in the IBM Cloud Pak for Data UI console. The Scala Connection URL can be found at Navigate menu -> Collect -> My data -> Databases -> Database details -> Access Information -> Scala Connection URL. An example <SCALA_CONNECTION_ENDPOINT> could be:cpd-001-master-1.fyre.ibm.com:32016,cpd-001-master-2.fyre.ibm.com:32016,cpd-001-master-3.fyre.ibm.com:32016; cpd-001-master-1.fyre.ibm.com:30723,cpd-001-master-2.fyre.ibm.com:30723,cpd-001-master-3.fyre.ibm.com:30723or it could look like:172.16.205.68:32016,172.16.205.67:32016,66:32016;172.16.205.68:30723,172.16.205.67:30723,172.16.205.66:30723
- Run either Step a OR Step b in the Python Notebook based on which version of
IBM Cloud Pak for Data you have: