Basic HBase Java Classes and Methods – Part 5: Getting Data from a Table

Now that we have seen how to Create a table and Put data into a table, we will explore how to read data out of a table. The main skeleton code is the the same as before, but this time we will construct a Get object and pass it in to the get method of the Table object.  The get method is overloaded, so it will accept a single get request or a list of get requests.

First lets look at what the skeleton code looks like, everything except our get requests:

First we will construct a basic Get object, add three columns to it using the addColumn method, pass that to the get method of the Table object and print out the results.  Remember everything in HBase is a byte array.

Now we will create two Get objects, add them to a list and then pass them in the same way.  The result given back to us is a list which we will walk through and print the results.

Complete program is below:

The results of our program are as follows:

Next part we will look at using the Scan command to accomplish similar to what the SELECT command does in SQL.  Next Basic HBase Java Classes and Methods – Part 6: Scan a Table

Posted in Data Analytics | Tagged , | Leave a comment

Summary of Cisco NX-OS security vulnerabilities I uncovered

I reported various vulnerabilities in NX-OS back in 2011, in various posts on my blog:

Hacking NX-OS Part 1

Hacking NX-OS Part 2

Hacking NX-OS Part 3

These were follow on’s to a series of posts I made about getting access to the OS by simply accessing the image:

Deconstructing Cisco NX-OS Part 1: Exploding Kickstart
Deconstructing Cisco NX-OS Part 2: Exploding the System Image

The exploits, which I formally reported to Cisco, were never made public, until over four years later.  These exploits were describe in the above posts years before their acknowledgement by Cisco.  Some of the exploits which I described  and were later made public by Cisco are:

GNU Bash Environment Variable Command Injection Vulnerability

Cisco Nexus Devices NX-OS Software Command-Line Interpreter Local Privilege Escalation Vulnerability

Cisco Nexus Operating System Devices Command Line Interface Local Privilege Escalation Vulnerability

Cisco NX-OS Software Arbitrary Code Execution Vulnerability

Cisco NX-OS Software Input Validation Vulnerability



Posted in Nexus, NX-OS | Tagged , | Leave a comment

Basic HBase Java Classes and Methods – Part 4: Putting Data into a Table

To put data into a table in HBase, we will create a Class very similar in structure to our last Class in Part 3.  Instead of using an Admin object, which is used to create a table or delete it, we will just work with a regular table object.  All data in HBase is stored as byte arrays.  Lets create our imports and basic variables to store our column family names and columns.

Now we create our main method, create a connection to our Table, instantiate a Put object and add columns to it using our addColumn method.   Finally we use the put method on the Table object to put the data into the table.  We have the table defined outside of the try block because we need to check for it in the finally block later on, and we can’t do that if its defined in the try block itself, as then it would be out of scope.

This is a very simple case.  We did not have to insert all of the columns, we could have left many blank just as we did before when using the HBase shell.  The HBase table put method is overloaded and supports either passing in a Put object or a list of Put objects.  We will now put more data in using a list of Put objects.

Last we will use our finally block to close our connection to HBase and check if we have an open table and if so close it.

So the completed program looks like so:

We can see that our data was added properly by checking with scan from the HBase shell.

Next we will explore how we can retrieve column data from the HBase table in Basic HBase Java Classes and Methods – Part 5: Getting Data from a Table.

Posted in Data Analytics | Tagged , | Leave a comment

Basic HBase Java Classes and Methods – Part 3: Table Creation

We will cover these basic steps:

Instantiating a configuration object
Establishing a connection to HBase
Manipulating tables using an administration object
Manipulating data within a table using a table instance

Creating our table

I am using Maven, and below is my pom.xml that I will be using for all of these examples.

You may also want to optionally create a file if using Maven.  Maven uses this file for logging.  We will create a basic properties file and store it in our main/resources folder.  For more information on log4j visit the project site.  Here is the basic properties file we will use.

AdminCreateTable basic libraries and main method.

Instantiating a Configuration object 

We will instantiate a Configuration object using the HBaseConfiguration static method.  The configuration Class is the base class for all config objects in the Hadoop ecosystem.

Establish a connection to the HBase cluster

We use the ConnectionFactory to create a connection object by passing in our Configuration object.

All code which uses our connection should be in try / finally blocks so that you can manage the connection manually and close the connection when you are done using it.

Instantiate an Admin object

Because functions such as Creating or Removing tables are administrative functions, these must be done using the Admin object.  We will create an Admin object from our Connection object.

You can see we put the instantiation of the Admin object inside of our try/finally clause.  The rest of our commands will also be inside this clause.  We added a command to close our connection in the finally clause.

Create the table schema using an HTableDescriptor

We use an HTableDescriptor to define our table, its properties such as column families, performance settings, etc.  We will create a table of name employee and two column families: personal and professional.

Create the table

We check to see if the table exists using our Admin object.  If it does not exist, we create it, and it does exist we print so.  We use the createTable method on our Admin object and pass in the HTableDescriptor we created previously.

Putting it all together we have the following:

Build and Run the code. You can verify the table has been created by going to the HBase Shell and verifying it exists.

See you in the next part Basic HBase Java Classes and Methods – Part 4: Putting Data into a Table

Posted in Data Analytics | Tagged , | Leave a comment

Basic HBase Java Classes and Methods – Part 2: HBase Shell

For the purpose of these exercises we will be working with a basic table which as two column families.  The first column family is “personal” and will contain first_name, last_name, age, gender, martial_status.  The second column family is “professional” and will contain “occupation” and “education”.

We will walk through all of the steps from creating the table, column families, populating data, changing data, deleting data and dropping the table.  We will first show you this in the HBase shell so you can be familiar with the data we are working with.  In Part 3 we will start to do these tasks programmatically using Java.

We are making a very brisk journey through the shell, with little to no explanation of the various parts of HBase, we assume you have learned the basics from reading the documentation.  Our goal is to just so some basic common HBase table operations using the shell, and then replicate it using Java.

Our employee table will look like so:

personal professional
ID first_name last_name age gender martial_status occupation education

First we fire up the HBase shell

We can request the basic status from HBase

We ask it who we are, similar to the whoami UNIX command, and get a list of any tables

We see that there are no tables.  We create the employee table with two column families, personal and professional.

We can use the describe command to give us more copious information about the table.  Many of these parameters have to do with the underlaying Hadoop layer and are not important for our exercises.

We can see we have no actual records in the table

Let’s insert a single record with an ID (row key) of 1.

You can see we inserted a single record with a column first_name inside of the column family personal.  There are no constraints in our table, so we can leave entire columns out or create new ones on the fly.

We will add a bunch more data

Notice I inserted the above record using a row key that was not 2, instead I skipped 2.  HBase doesn’t care what you make the row key, it can be a string, number, even an array.

Now that we have inserted information regarding three employees, lets take a look at our table.

We can easily make changes to any information:

We can delete just a single cell if we wish

We can use the exists command to see if a table exists

We have to disable a table before we can drop it. Disabling a table flushes all the data in memory to disk.

We can see there are no more tables

We will be repeating these commands in the next Part using Java in Basic HBase Java Classes and Methods – Part 3: Table Creation

Posted in Data Analytics | Tagged , | Leave a comment