Monday, March 16, 2015

My Path to node.js and Oracle Glory - Volume 3, node.js setup on ubuntu on chromebook

Next step - node.js setup on Ubuntu.  This was remarkably easy!  I went to https://nodejs.org/ and viewed their Downloads section, where I then went to "Installing from package managers".  That link takes you to this URL on GitHub.  If you read the first line of "Debian and Ubuntu based Linux distributions", you'll note you should go to nodesource's blog post for the most up to date instructions.  I did what I was told - read what they have to say on the page - helpful stuff!

The instructions to install are as follows:

Open a new crosh window or use ctrl+alt+t
type shell
type sudo startxfce4 to get into Ubuntu
click on the Terminal Emulator icon

You need curl (a tool for making http calls, etc. - http://en.wikipedia.org/wiki/CURL), so get it - type sudo apt-get install curl

The instructions from nodesource's blog post say to then enter the following:

# Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

# Then install with:
sudo apt-get install -y nodejs

Type node to start node..

That's it!  node.js is installed in Ubuntu inside my chromebook!

There are a TON of node.js intros, etc. that I've been pouring over for a while now - I'm not going to bother to explain the basics of node as it's extremely well documented.  I will now start to write some small pl/sql and js programs using the node-oracledb driver and will continue to blog as things progress in that area...  That's it for today!

Saturday, March 14, 2015

My Path to node.js and Oracle Glory - Volume 2, Linux setup on Chromebook

OK, so now having established my database server in Volume 1 of this series, I now need to move to the next step - setting up my chromebook with Linux in order to facilitate node.js development.  I chose a chromebook as my dev machine of choice as I wanted something that natively runs on Linux, but didn't want to pay as much as a Mac and didn't really like the Linux based machine options out there...  Google is doing a great job with these and after having my chromebook for a little over a week - I have to say I love it...

So, the first step is to put your chromebook into developer mode - this is a fairly frightening experience, but since everything on your chromebook is "in the cloud" and can be restored, fear not and hack on!

I bought a Toshiba Chromebook 2 and found instructions to put the machine into developer mode at this URL and this URL as well...

  • To put it your chromebook into developer mode, you simply hit the esc+refresh+power keys at the same time after you've logged in.  When you do this, your machine will reboot and show an alert screen - at this point, hit Ctrl+D to go into Developer mode.  THIS WILL WIPE YOUR MACHINE!  You'll need to re-login and setup the machine again, but once done you won't need to do this again...  I bought this machine to develop, so this was basically the first thing I did with it - the data wipe didn't concern me...  Since most things you do are auto backed-up to Google drive, this probably won't concern most people.  The process for the laptop to transition to Developer Mode takes 15 minutes or so (one time only) - so go grab a beer...

Next up - Crouton!  ...What the hell does a crouton have to do with this?  Well, crouton stands for ChRomium Os Universal chrooT envirONment - and all the information you really need about it is at the GitHub location here.  This is now the point where I'm over my head, but I believe crouton is a set of scripts written by a prolific Google developer named David Schneider that allows you to create what's known as a chroot, which allows Linux distributions to run under a segregated file system as a guest OS -  more info about chroots here

So, basically in order to run Ubuntu (the Linux distribution I've chosen) alongside my ChromeOS, I need to run it within a chroot.  I need to use the crouton script bundle to generate this chroot.

You should go to https://goo.gl/fd3zc - it will download into your Downloads folder - leave it there.

So, in order to properly generate a chroot - you have to have some opinions.  You need to choose a Linux distribution and a desktop environment... 

I need to choose a Linux distribution -- I have no idea where to start even - there are over 600 distributions of Linux and 300 are actively being developed!!  Where do you even begin in this world?  My understanding of a distribution of Linux is that it is a packaging of software (libraries, desktop environment, utilities, GUI, etc.).  I have a lot to learn on this, but for now I'm going to be lame and choose a commercially backed option - Ubuntu.  I am choosing the most recent "Long Term Support" (LTS) version of this distro, code named Trusty Tahr.

Within Ubuntu, there are different flavors based on the desktop environment you prefer.  After some basic research, I want a basic desktop - I actually installed several different versions and thought the Unity desktop was awful...  So, I'm going with Xfce - a basic, yet comfortable desktop environment!  This flavor of Ubuntu is known as Xubuntu...

So, I have my opinions settled - I know what I want - next is to go to the Chrome web store and install a few items
  1. Secure Shell
  2. Crosh Window - opens a separate window from your browser
  3. crouton extension - Allows for copy/paste to/from guest OS window (in my case Ubuntu)
So, now you have all your dependencies - you can either do Ctrl+alt+t to open a "Chrome Operating Shell" or crosh for short in a full screen window or you can use the Crosh Window app you just installed.  
  • At the command prompt, type shell
  • Next type sudo sh ~/Downloads/crouton -t xiwi,xfce -r trusty
    • This is basically telling crouton that the target (-t) is the xfce desktop environment using the xiwi version (which allows for the copy/paste) and the distribution release (-r) should be Trusty Tahr (trusty)
  • This takes a while to install - go get another beer...  At the very end of the install, you'll be asked "Please specify a username for the primary user:" - plug in your preferred username...  you'll then be asked for a password as well...
Once done, you'll be taken back to the shell prompt where you just type sudo startxfce4 and bam!  Ubuntu should boot!  It will boot in a full screen Chrome OS window - in order to minimize and size the window, just click at the top where it says "crouton integration" triggered full screen Exit full screen and then resize as necessary.

Each time you log out of Ubuntu, you want to ensure you logout properly - for the distro I chose, I just go to the upper right hand corner where my username is, choose it and select Log Out...  

Now that I've done this once, the next time is a breeze - open a new Crosh Window, type sudo startxfce4 and that's it - I'm up and running in seconds.

I learned a lot about this crouton extension jazz by reading this - the dude Francois Beaufort seems to be one of the chromebook leads and has a lot of great posts...  You probably want to follow him on Google + if you have a chromebook and are a developer.

OK - it worked - I have Linux up and running within a Chrome OS Window!  YAY!


... that's it for today - next up Volume 3, Setting up node.js on Ubuntu in my Chromebook!


Monday, March 9, 2015

My Path to node.js and Oracle Glory - Volume 1, Oracle XE Setup on Windows machine

I am starting a new personal project with the following goals in mind:

  1. Learn JavaScript (I'm a beginner, but been reading/implementing for a while)
  2. Learn node.js
  3. Create a RESTful API using node.js calling a remote database server using Oracle's node driver (node-oracledb)
    • API should be simple to understand
    • API in the backend should use the HR sample schema
    • When using node.js, goal is to form a service request object in javascript and pass that object to a stored procedure in Oracle as an IN parameter, the same stored procedure should return a response object that will be parsed in javascript and the results displayed
  4. DISCLAIMER - When I actually have free time to develop - I am primarily a PL/SQL developer -- I love PL/SQL - there I said it!  I work with java and perl, but at the end of the day, I love the insulated, hassle-free world of developing within a database.  I know enough of command line to get by, but my 4th major goal is to become a command line "expert" (or at least know where all the relevant references I need are) for sqlplus and more importantly Linux, so bear with me as I toil through the basics along the way!

So, on to the actual work - I am going to setup two machines on my home network -- one machine (an old Windows 7 laptop) will act as a database server, the other machine (my new Chromebook) will act as the calling application (in this case node.js using Oracle's node-Oracledb driver).

Step 1.  Install Oracle XE on my windows machine using this URL - I won't go into depth on how to install XE as it's well documented.

Step 2. DO NOT DO THIS!  Live and learn - I had no idea that the HR and other sample schemas are already installed with XE and went through all the below steps to clone and install the schema, only to figure out that I had accidentally installed the HR objects in the SYSTEM schema (I've now corrected the steps)....  Anyway, if for some reason, you need to install Oracle's sample schemas in your XE instance using Christopher Jones' db-sample-schemas on Github at this URL, then follow these steps!
  • If you're not familiar with Github, it's definitely worth your while to learn about it, though there is a learning curve (I still suck at it, actually, but getting there...)
  • Install Github for Windows using this URL
  • Once installed, you can just go to https://github.com/oracle/db-sample-schemas.git and choose "Clone in Desktop" and choose the folder location you wish to store the db-sample-schemas repository.  If you're not comfortable with Github yet - you can always get the same files by choosing "Download ZIP"
  • After you've cloned or downloaded the files, navigate to the human_resources directory using the Windows command line interface (cmd.exe).
  • When you're in the directory, type sqlplus - you'll then be asked to login - be sure to login as the HR schema.  I am assuming you've already created the HR schema.  If you have not, you should - you'll need to figure that out on your own though.  You can look at the hr_main.sql in the human_resources directory that you just downloaded for an example of creating HR.
  • After you're logged in as HR in sqlplus, just type @hr_cre.sql - sqlplus will then execute the script and create all the necessary objects.  You can then type @hr_popul.sql to populate the tables you just created with data!
  • Anyway, if you screw things up like I did, Christopher has nicely provided a script hr_drop.sql that you can run whenever necessary.
Step 3.  Open up Windows firewall for Port 1521:  
  • To enable remote calls from my Chromebook, I need to enable Firewall rules on my Windows machine so that data can flow in and out of the machine through port 1521 (the standard port that Oracle is configured for)
  • First, you want to be sure your listener is up and running for the Oracle XE instance you installed (it should be by default), but you can check in the Windows command line interface (cmd.exe) by typing lsnrctl status (you don't have to browse anywhere in particular for this command)
    • You can find out some critical items from this status, ie your HOST and PORT (will be 1521 by default) which you'll need when connecting later
    • Click here for more information on Managing Network Connections - doc shows you how to stop and start your db listener if you need me to...
  • Assuming you are using the default port, next step is to open up connections (inbound and outbound) on it 
    • Goto Start -> Control Panel -> System and Security -> Windows Firewall -> Advanced settings
      • Once in Advanced Settings, you'll see a window titled "Windows Firewall with Advanced Security"
        • click on Inbound Rules and choose the "New Rule..." action
          • Choose "Port" when asked What type of rule would you like to create?
            • Choose TCP when asked Does this apply to TCP or UDP?
            • Add 1521 next to Specified Local Ports
            • Choose Allow the connection
            • Rule applies to whichever domain you choose...
            • Give the rule a name - I chose OracleInboundPort, click Finish
        • Rinse and repeat the above for the Outbound Rules, just name the rule appropriately, i.e. OracleOutboundPort

... that's it for today - next up Volume 2, Configuring Linux on my Chromebook