Tuesday, October 11, 2016

Extend the Bluemix CLI Through Plugins

Put a smile in your cloud
As much as I like nice graphical user interfaces (UIs) and working with the browser, for most tasks I prefer using the command line. I have done so and still do for working with DB2 and dashDB, I also use the Cloud Foundry (CF) Command Line Interface (CLI) to manage my Bluemix environments. The "cf" tool is quite handy, allows to perform what I need to accomplish. A great feature is its support of plugins that allow to extend its functionality. There are IBM-provided plugins and several coming from the Cloud Foundry ecosystem. Here are some brief instructions on how to get started.

Once you have installed a recent version of the "cf" tool, just invoking it without any parameters should display some help text on available commands and features. In the lower part of that text should be two sections related to plugins:

   add-plugin-repo                        Add a new plugin repository
   remove-plugin-repo                     Remove a plugin repository
   list-plugin-repos                      List all the added plugin repositories
   repo-plugins                           List all available plugins in specified repository or in all added repositories

   plugins                                List all available plugin commands
   install-plugin                         Install CLI plugin
   uninstall-plugin                       Uninstall the plugin defined in command argument

The command "add-plugin-repo" allows to add new repositories from which plugins can be installed, "list-plugin-repos" lists those repositories already available in your environment. Try the following two commands to add the plugin repositories from Bluemix Public and from the Cloud Foundry community collection:

cf add-plugin-repo  BluemixPublic http://plugins.ng.bluemix.net/

cf add-plugin-repo CF-Community http://plugins.cloudfoundry.org/

Once done, try the following command to list the repositories. It should return something like shown:
henrik>> cf list-plugin-repos

Repo Name      Url  
BluemixPublic  http://plugins.ng.bluemix.net  
CF-Community   http://plugins.cloudfoundry.org/ 

With the command "repo-plugins" it is possible to list all the available plugins ready to be installed. You can read more about them at the repository descriptions linked above. For switching quickly between my different Bluemix environments I have installed the "targets" plugin from the Cloud Foundry community repository:

henrik>> cf install-plugin targets -r CF-Community

**Attention: Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.**

Do you want to install the plugin targets? (y or n)> y
Looking up 'targets' from repository 'CF-Community'
8230816 bytes downloaded...
Installing plugin /tmp/cf-targets-plugin...
Plugin cf-targets v1.1.0 successfully installed.

After I am done when calling just "cf" again, there is a new section in the help text available:
   targets                                List available targets
   set-target                             Set current target
   save-target                            Save current target
   delete-target                          Delete a saved target

If you have more plugins installed then there will be more commands displayed. Using the "targets" plugin I can save the current environment, i.e., the Bluemix or Cloud Foundry instance I am logged into, and quickly can switch between the Bluemix Dallas (NG) and Bluemix London (EU-GB) platforms using the "set-target" command. "cf set-target eu" would replace several "cf api" and "cf login" commands and a lot of typing, great for scripting and more efficient work.

Thursday, October 6, 2016

Easy to identify: Does the table have a primary key?

Primary Key
Next week I am going to teach students database basics again. One of the topics will be primary keys and how they help enforcing uniqueness and identify each of the stored objects. Recently I stumbled over the question how it is easily possible to tell whether a DB2 or dashDB table has a primary key. The answer, as often, is in the catalog, the database metadata.

For performance reasons almost all database systems use an unique index to implement a primary key. So the key (pun intended) is to look for such an index. Both DB2 for Linux, UNIX, and Windows (LUW) and DB2 for z/OS store information about indexes in a system table SYSIBM.SYSINDEXES. On DB2 for z/OS that table is exposed to the user and documented here. DB2 LUW has catalog views on top and the view to use is named SYSCAT.INDEXES, however querying the table still works:


The query returns the columns on which the primary key is defined for the table MYTABLE. As can be seen in the documentation, the UNIQUERULE provides information about whether the index is an index with duplicates, an unique index, or it is used to implement a primary key (value P). On DB2 LUW we could write the query utilizing the catalog view SYSCAT.INDEXES. The following query returns the table name and schema as well as the column names for all tables which have a primary key defined:


So the key to quickly working with primary keys are indexes and their metadata...

Monday, August 22, 2016

Notes on Notebooks, Data, DB2, and Bluemix

Weather Graph in Jupyter Notebook
Some time ago I shared with you how I used open data like weather data and CeBIT statistics to have some fun with Jupyter Notebooks. Notebooks are an old, but now - in the age of Cloud Computing - trendy way of collaborative data exploration (see this article for some background reading). Notebooks consist of so-called cells, places to put code, instructions, text and more. Cells can hold Markdown-formatted text, code written in Python, Scala and other languages. It is possible to fetch data from DB2, dashDB and other database systems and process it in the notebook, creating stunning graphics. And with extensions such as RISE (reveal.js IPython Slideshow Extension) those notebooks replace Powerpoint & Co as source for great data-driven presentations. How to use notebooks and DB2 is what I plan to present at the IDUG EMEA 2016 Conference in Brussels later this year.

If you can't wait until then I recommend to take a look at these recent blog posts on how to get started with Notebooks and data on Bluemix:
In case you have trouble programming your notebooks, head over to Stack Overflow and search for "ipython-notebook" or "jupyter-notebook".

That's it for today with my notes on notebooks.


Related Posts with Thumbnails