Wednesday, August 22, 2012

Grails, Scaffolding, GSPs

I've spent the last few evenings reading up on Grails Domain Classes and Controllers, the 'M' and 'C' portions of MVC, respectively.

I have been working through Getting Started with Grails, Second Edition by Scott Davis and Jason Rudolph. 

Throughout the process of working through their Racetrack sample application, I have been switching between MongoDB 2.0.6 and MySQL 5.5.25. 

In the process, I have hit some bumps in the road regarding MongoDB Issues with Grails Scaffolding that do not occur in MySQL. 

I posted these on StackOverflow and mentioned in LinkedIn discussions.  This has led me down the path of going so far as to trying to download a tag from GitHub for newer builds of the MongoDB Plugin for Grails (as of today 2012-08-22, 1.0.0.GA is the latest official release for this plug-in).

I've also learned a lot about MySQL in the process of setting it up, securing it on Fedora 17. 

Neat things I've learned:

Now, I'm starting to learn about the 'V' aspect of MVC in Grails.  I am digging into GSPs. 

Wednesday, August 15, 2012

MySQL on Fedora 17 and Grails

I was running into some strange behavior when writing a test Grails Application that uses MongoDB (MongoDB 2.0.6-2.fc17 installed via YUM) for storage.

Specifically, when I use scaffolding, I am unable to reorder the fields using the static constraints block.

I saw this mentioned on a post in the Nabble forum for Grails, alluding to this possibly being a problem with MongoDB.  However, I was not able to find any more information on scaffold field ordering via static constraints not working for MongoDB.

In order to run this down further, I decided to take my same test application and run it using MySQL for storage.  I haven't used MySQL for years, so it took a little to get re-acclimated.

  1. Quick check for MySQL on the Fedora 17 server:
    # yum list mysql
    Loaded plugins: langpacks, presto, refresh-packagekit
    Installed Packages
    mysql.x86_64                       5.5.25a-1.fc17                       @updates
    Available Packages
    mysql.i686                         5.5.25a-1.fc17                       updates
    

    Yay, it's already installed. Looks like it shipped with 5.5.25a-1, a specific build for FC17.

  2. Enable the Service upon startup:
    # systemctl enable mysqld.service
    

  3. Secure it:
    # mysqladmin -u root password ********
    

  4. Enable remote connections from development machine for administration.
    # mysql -u root -p mysql
    mysql> GRANT ALL PRIVILEGES ON *.* TO root@'DEV_MACHINE_HOSTNAME' IDENTIFIED BY ********;
    
    Also, I opened up port 3306 through the firewall on the FC17 server.

  5. Next, I logged in via MySQL Client and ran Create Database, Create User,  and Grant All to create a new Database for my Grails Application, create a User for this Database, and Grant all privileges to that User for the newly-created database.
  6. Finally, I changed my Grails App Plugins (removed mongodb, installed mysql-connectorj-5.1.12 and hibernate-2.1.0) and updated DataSource.groovy:
    dataSource {
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
        username = "racetrack"
        password = "********"
    }
    hibernate {
        cache.use_second_level_cache = true
        cache.use_query_cache = true
        cache.provider_class = "net.sf.ehcache.hibernate.EhCacheProvider"
    }
    
    // environment specific settings
    environments {
        development {
          dataSource {
             dbCreate = "create-drop" // one of 'create', 'create-drop','update'
             url = "jdbc:mysql://ptenn:3306/racetrack"
          }
       }
       test {
          dataSource {
             dbCreate = "create"
             url = "jdbc:mysql://ptenn:3306/racetrack"
          }
       }
       production {
          dataSource {
             dbCreate = "update"
             url = "jdbc:mysql://ptenn:3306/racetrack"
          }
       }
    }
    

Monday, August 13, 2012

Fedora transition: SysVinit to Systemd

I installed Fedora 17 on a Linux Server (previously had been working with Fedora 14), and ran across a surprise.

Apparently, Fedora is transitioning from SysVinit to Systemd: Fedora features/systemd

I realized something was amiss when attempting to set runlevels for 2 services: sshd and mongod.

I ran the following commands:

# chkconfig sshd on
# chkconfig mongod on

and proceeded to reboot the server.

My understanding is that these commands should turn runlevels 2, 3, 4, 5 on for both sshd and mongod services.

When I restarted, I was able to verify via testing that these 2 services came up as expected.

However, when I went to run:
# chkconfig --list

These services did not appear in the list.

After doing some more research, I found the following guide: Fedora SysVinit to Systemd Cheatsheet.

Ran the new equivalent of chkconfig --list:

# ls /etc/systemd/system/*.wants

...

/etc/systemd/system/multi-user.target.wants:
abrt-ccpp.service     chronyd.service         nfs-lock.service
abrtd.service         crond.service           remote-fs.target
abrt-oops.service     cups.path               rpcbind.service
abrt-vmcore.service   irqbalance.service      rsyslog.service
acpid.service         mcelog.service          sendmail.service
arp-ethers.service    mdmonitor.service       smartd.service
atd.service           mongod.service          sm-client.service
auditd.service        multipathd.service      sshd.service
avahi-daemon.service  NetworkManager.service

...
and saw my sshd.service and mongod.service as expected.
It will take some time to get used to this new syntax for systemd ... so used to chkconfig and service.

Wednesday, August 8, 2012

Grails and MongoDB: Setup

I am attempting to create a sample Grails project that uses MongoDB for persistent store. 

I've learned a lot about Grails Plugins while trying to build a simple Grails App with MongoDB.

First stop was this blog post on MongoDB titled "Grails in the Land of MongoDB".

My blog post is based on this posting from MongoDB, with additional notes and information that I discovered while following these steps. 
The blog post "Grails in the Land of MongoDB" listed steps as follows:

Step 1: Remove the hibernate dependency from the BuildConfig.groovy file.

This wasn't as straightforward as I thought.  I am using Grails 2.1.0.  After I ran the command:

grails create-app doctor

I opened up the BuildConfig.groovy file.  It had the following plugins:

    
plugins {
        runtime ":hibernate:$grailsVersion"
        runtime ":jquery:1.7.2"
        runtime ":resources:1.1.6"

        // Uncomment these (or add new ones) to enable additional resources capabilities
        //runtime ":zipped-resources:1.0"
        //runtime ":cached-resources:1.0"
        //runtime ":yui-minify-resources:0.1.4"

        build ":tomcat:$grailsVersion"

        runtime ":database-migration:1.1"

        compile ':cache:1.0.0'
    }

I removed the entries for Hibernate and Database Migration. 

After making these changes, my plugins section of BuildConfig.groovy appeared as follows:

    
    plugins {
        runtime ":jquery:1.7.2"
        runtime ":resources:1.1.6"

        // Uncomment these (or add new ones) to enable additional resources capabilities
        //runtime ":zipped-resources:1.0"
        //runtime ":cached-resources:1.0"
        //runtime ":yui-minify-resources:0.1.4"

        build ":tomcat:$grailsVersion"

        compile ':cache:1.0.0'
    }

Step 2:Install the MongoDB GORM
I ran the command:

grails install-plugin mongodb

This did the following (as far as I can tell): 



  1. Added an entry to my application.properties: plugins.mongodb=1.0.0.GA
  2. Created the directory projects/doctor/plugins/mongodb-1.0.0.GA in my .grails directory.
Step 3:Edit DataSource.groovy to specify connection settings
There was a slight typo in the MongoDB blog. The port should actually be 27017.

grails { 
  mongo { 
    host = "localhost"
    port = 27017 
    username = "doctorUser"
    password="medicine"
    databaseName = "doctors"
  } 
}

Thursday, July 26, 2012

Cloud Foundry, Micro Cloud Foundry, VMX

As part of my exploration into NoSQL and MongoDB, I have been exploring CloudFoundry. 

I first learned about CloudFoundry during SpringOne 2GX 2011 last October in Chicago. 

We received flash drives with the Micro Cloud Foundry on it, but I was way too busy with work at the time to give it much thought. 

However, as I started looking for Cloud Hosting and PaaS that supports MongoDB, I realized that CloudFoundry supports MongoDB. 

Registered here: http://my.cloudfoundry.com/signup and received an email with my credentials.  One thing that struck me as odd was that when I signed in, I was unable to change my password from the randomly generated one.

Oh, well, I proceeded to download Micro Cloud Foundry. I also set up VMX and am able to remotely connect to CloudFoundry.

ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

C:\>gem install vmc
Fetching: json_pure-1.6.7.gem (100%)
Fetching: rubyzip-0.9.9.gem (100%)
Fetching: mime-types-1.19.gem (100%)
Fetching: rest-client-1.6.7.gem (100%)
Fetching: terminal-table-1.4.5.gem (100%)
Fetching: interact-0.4.5.gem (100%)
Fetching: addressable-2.2.8.gem (100%)
Fetching: uuidtools-2.1.3.gem (100%)
Fetching: rb-readline-0.4.2.gem (100%)
Fetching: vmc-0.3.18.gem (100%)
Successfully installed json_pure-1.6.7
Successfully installed rubyzip-0.9.9
Successfully installed mime-types-1.19
Successfully installed rest-client-1.6.7
Successfully installed terminal-table-1.4.5
Successfully installed interact-0.4.5
Successfully installed addressable-2.2.8
Successfully installed uuidtools-2.1.3
Successfully installed rb-readline-0.4.2
Successfully installed vmc-0.3.18
10 gems installed
Installing ri documentation for json_pure-1.6.7...
Installing ri documentation for rubyzip-0.9.9...
Installing ri documentation for mime-types-1.19...
Installing ri documentation for rest-client-1.6.7...
Installing ri documentation for terminal-table-1.4.5...
Installing ri documentation for interact-0.4.5...
Installing ri documentation for addressable-2.2.8...
Installing ri documentation for uuidtools-2.1.3...
Installing ri documentation for rb-readline-0.4.2...
Installing ri documentation for vmc-0.3.18...
Installing RDoc documentation for json_pure-1.6.7...
Installing RDoc documentation for rubyzip-0.9.9...
Installing RDoc documentation for mime-types-1.19...
Installing RDoc documentation for rest-client-1.6.7...
Installing RDoc documentation for terminal-table-1.4.5...
Installing RDoc documentation for interact-0.4.5...
Installing RDoc documentation for addressable-2.2.8...
Installing RDoc documentation for uuidtools-2.1.3...
Installing RDoc documentation for rb-readline-0.4.2...
Installing RDoc documentation for vmc-0.3.18...

C:\>vmc
Usage: vmc [options] command [<args>] [command_options]
Try 'vmc help [command]' or 'vmc help options' for more information.


C:\>vmc target

[http://api.vcap.me]


C:\>vmc target api.cloudfoundry.com
Successfully targeted to [http://api.cloudfoundry.com]


C:\>vmc login
Attempting login to [http://api.cloudfoundry.com]
Email: ********
Password: ********
Successfully logged into [http://api.cloudfoundry.com]

Friday, July 13, 2012

NoSQL, BigTable, and data stores

I've started reading a lot about NoSQL Databases and it fascinates me, especially as a developer who has grown up in the Relational Database world (Oracle and SQL Server) and spent a lot of time optimizing queries, working on complex SQL statements, normalizing tables, inner joins, left outer joins, inline views, and all that good stuff.

Over time, I've watched the evolution from the Data Tier of the n-tiered model go from DAOs that executed JDBC to ORM (been doing a lot of Hibernate and NHibernate) to Grails/GORM (which provides a ton of create/read/update/delete methods automatically, freeing the developer from having to maintain this code). 

I have read articles about how companies that work with extremely large volumes of data like Google have developed distributed, non-relational data stores such as BigTable.  When I was playing with Google App Engine was my first exposure to BigTable, and it was a bit of culture shock for a developer who is used to the traditional RDBMS model present in most corporate environments (at least every environment I have worked in since I started in industry in 1998). 

BigTable and the problem it was created to address fascinated me.  However, I really couldn't get into Google App Engine.  At the time, it was purely Python/Django, though it has since been expanded out to include Java.  I did write several Python scripts and built a few pages in Django, but found it to be an uncomfortable fit for someone comfortable with writing Java in IntelliJ or C# in Visual Studio .NET. 

Recently I have been reading about the NoSQL movement.  I am going to pull down MongoDB and give it a try.  I was glad to read that Grails has a MondoDB plugin.

Sunday, November 27, 2011

Obtaining Android Source Code on Microsoft Windows Platform

I was able to obtain the Android source code.

Here's a screenshot in Eclipse of what prompted me to go searching for the Android source code.







(really ugly when you try control-clicking on an Android API class only to get this)

Obtaining the source was MUCH more of a challenge than I expected, and took me several hours yesterday evening (plus an overnight download). Somehow I just imagined that the source would be available by Android API version as a ZIP or JAR file. Nope ...

In order to get it installed on Windows (which is officially not supported per the Android Open Source Project documentation), here's what I had to do:




  1. Install Cygwin. I installed Cygwin 1.7.9-1, the latest, obtained from cygwin.com.
  2. The setup.exe is a Web Installer. I specified C:\cygwin as my Root Directory, installed for All Users. When running setup.exe, administrator privileges are required.
  3. In the Cygwin Setup - Select Packages dialog, I found packages for curl, git, and python. These 3 will be necessary for obtaining the Android Source. This installation was a bit tricky, so I want to document this well here:

Cygwin - curl installation


Cygwin - git installation



Cygwin - Python installation


  1. From here, complete installation of Cygwin.
  2. Once Cygwin has been installed, create a local directory to hold the Android Source. In my case, I used C:\android\android-source.
  3. Open a Cygwin terminal session and type:
    cd /cygdrive/c/android/android-source
    (of course, using whatever path for your local directory).
  4. Now, type:
    curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/repo
    This will pull down the repo Python script used by the Android SDK Team and place it in your local directory for Android Source.
  5. Next, type:

    repo init -u https://android.googlesource.com/platform/manifest

    This will create a .repo file and initialize the directory to hold the Android Source.
  6. Finally, type:
    repo sync

    This will do the actual downloading of the Android Source. It takes a long time, and pulled down 8.72 GB into my local working directory.