Thursday, December 31, 2015

Spring Cloud, Cloud Foundry

I returned to part 6 and part 7 of Building Cloud Native Apps with Spring with the idea of deploying the app into my local Cloud Foundry instance instead of IBM Bluemix.

I have to say that once you have got through the ordeal of setting up Cloud Foundry locally, it is a lot less trouble to work with than Bluemix.  I skipped over gobs of instructions about checking things into github, writing little shell scripts and navigating around doing things in the Bluemix web GUI.

All I needed to do to get this working was to register Eureka as a CF service:
cf cups ocr-eureka -p '{"uri": ""}'
 and then make the changes described to the application.yml files.

I had a problem with the Hystrix app.  It was giving me a big stack trace about Tomcat failing to start.  This turned out to be the error that was causing the problem:

    java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet(Ljava/lang/String;Ljavax/servlet/Servlet;)Ljavax/servlet/ServletRegistration$Dynamic;

I found some discussion of this at Getting NoSuchMethodError: javax.servlet.ServletContext.addServlet in Spring Boot while running a Spring MVC application.  Checking the dependencies, I found that Turbine had a dependency on servlet-api 2.5.  I tried excluding that in the Hystrix POM:

and that fixed the problem.

Deploying an app into CF seems really slow.  It's doing some big downloads every time (Open Jdk JRE 1.8.0_65, Open JDK Like Memory Calculator 2.0.1_RELEASE, Spring Auto Reconfiguration 1.10.0_RELEASE).  I feel like it would be hard to work this way.  Wondering if there's a way to speed this up?

Wednesday, December 30, 2015

Setting up a local Cloud Foundry instance

My platform for all of this is Linux Mint 17.2 (rafaela).

It has been 2 or 3 years since I played around with Cloud Foundry.

The first thing I noticed is they have really raised the bar in terms of the effort required to bring up a local instance.  There used to be a thing called Micro Cloud Foundry where you just downloaded a VMware VM and you were good to go.

Today, that is gone... instead there is a whole build process to go through.  On the one hand, it is good that these tools and sources are available, but I can't help feeling like this is a fairly big hurdle for the casual developer who is trying to evaluate CF.

I mostly followed the BOSH-lite README starting here.

When you get to Deploy Cloud Foundry, there are two choices.  The first choice leads to Deploying Cloud Foundry using BOSH which I found to be a trail of tears with lots of manual steps and big, slow downloads.  In the end I was not able to get this to work.

The second choice, checking out cf-release from github and running bin/provision_cf from your checked out bosh-lite directory, did work for me and seemed to go a lot faster (relatively speaking... still have a fast network and hours to spare).  Inside of this shell script you will find some of the same steps the first method does manually, but all neatly packaged and tested.

This got me to the point where I had CF running in my Vagrant VirtualBox and I could run 'bosh vms' and see all the VMs up and running.

My next challenge was to get access to my shiny new CF instance.  Deploying Cloud Foundry using Bosh said to try
curl api.subdomain.domain/info
but of course api.subdomain.domain is not the literal value, just an example.

I found several places indicating that the correct value here should be  I read up on a little, verified that my computer was resolving this name, but still couldn't get this to work.

Googling on, I found a guy who was having this exact problem and the solution that worked for him.  So, using I was able to access my local CF instance:

Having done all of this I was able to complete the remainder of the setup just following the documented steps with cf api, cf login, cf create-org, cf create-space, cf target... See Running Cloud Foundry Locally with BOSH Lite for example.

So, cool, sort of... I spent about a day on this and feel like I have just reached the starting line...

I configured the Eclipse integration and worked through Deploying to Cloud Foundry from STS.  Everything works.  I saw the 'Hello world'.  Ready to try this with a real app.

Here's a nice short presentation I found afterwards that sheds a little more light on Bosh: Why Must I Use Cloud Foundry's Bosh? I just Learned Chef/Puppet!  For when you want to customize your CF instance, and apparently it can do more than just manage CF.

Update 2017: Since I wrote this, Pivotal has released PCF Dev, a downloadable CF VM not unlike the old Micro Cloud Foundry VM for the person just wanting to experiment and get up to speed with a local instance of Cloud Foundry.

Lattice is a tool to bring up a local CF instance.  Here's a pretty good presentation about Lattice and CF.  But note that Lattice is no longer actively maintained and appears to be deprecated now.  I gave this a quick try but didn't get it to work.

Monday, December 28, 2015

Spring Cloud

Last month I watched SpringOne2GX 2015 replay: Getting Started with Spring Cloud.  OK presentation, but they rush through a lot of material quickly and at the end I just had a general impression of coolness but without much in the way of detailed knowledge of how to use it.

Working through Ryan Baxter's Building Cloud Native Apps with Spring (8 part series) has left me with a better understanding of Spring Cloud.  You could divide this roughly into 4 parts: doing the initial setup of the application, the Spring Cloud Netflix components (Eureka, Zuul, Feign, Hystrix, Turbine), deploying to IBM Bluemix, deploying to Docker.  These are mostly nice bite-sized chunks that you can get through in an hour or so, if you are familiar with the other infrastructure (e.g. if you are not learning and installing Docker for the first time).

At first I tried this with the latest Spring Boot version which was 1.3.1.  I had some problems with that but everything worked with 1.2.8.

I elected not to do parts 6 and 7 which involve the use of IBM Bluemix which I gather is based on Cloud Foundry.  This is not a free service although you can get a 30 day free trial.  No thanks.

Part 8 is about deploying into Docker.  I had been playing around with Docker earlier and had it mostly installed, so this proved to be a bit of a refresher and I learned a few new things too, such as Docker Compose.

Links to all of the blog posts: 1 2 3 4 5 6 7 8

Here is one more... this is sort of an introduction... why do things differently when working in the cloud, microservices architecture, 12-factor: Building Cloud Native Applications.

Sunday, November 29, 2015

What's new in Grails 3

SpringOne2GX presentation about what's new in Grails 3

This seems to have been a particularly good SpringOne2GX and a lot of the presentations are becoming available now.

There were several good presentations about Grails and my general impression is the demise of Grails was greatly exaggerated.

Grails has a new corporate sponsor, OCI.

Groovy Grails Tool Suite remains unsupported but Grails 3 Released: Installing Gradle and Groovy 2.4 Support in Eclipse/GGTS offers some tips for continuing to use GGTS with Grails 3.

Another interesting thing about this presentation is Graeme Rocher is using IntelliJ IDEA CE (community edition, i.e. the free version) to demo everything.  I've been using IDEA to debug Groovy scripts because just debugging a script in isolation doesn't seem to be very well supported in the Eclipse-based IDEs like GGTS.  But this is opening my eyes to the CE version having a lot of functionality and being a pretty useful tool.

I like the direction of taking advantage of existing infrastructure like Gradle as the build tool.

One downside of the many changes in 3.X is there is no direct upgrade path.  This seems like it is going to be a big hump to get over, especially for projects using a lot of Grails 2.X plugins (as we do at work).

Learning priorities

What I'm most interested in at the moment
  • Spring Boot/Cloud, generally getting back up to speed in Spring
  • Gradle
  • IntelliJ IDEA
  • TextMate
  • Cloud Foundry (free version running locally)
  • Docker
  • Jenkins, CI

Sunday, October 11, 2015

Java 8

Wow, have I really not posted anything since January?

I'm coming up to speed on Java 8.  I've been working in Groovy for like a year and a half so these concepts are not new, but the syntax is just different enough that I have to think about it.

Here is some code I wrote a while back.  It is a solution to a Cracking the Coding Interview problem to write a boolean method taking two strings as input and returning whether one string is a permutation of the other (same characters in a different order):

This is basically Java 6 the way we've been writing it for the last 10 years or so.

isPermutation stays the same so I'll just be showing changes to signature.

Use a Java 8 lambda and a stream to iterate through the String.  Note the use of String.chars() returning an IntStream which is where the stream comes from.  You'd think there's be a CharStream, but no, so I'm using a rather awkward conversion to get the int back to a char:

Not a big improvement so far... next I use the cool new Map.getOrDefault() to replace 7 lines of code with one:

That is starting to be some more expressive and maintainable code... finally there's nothing sacred about the signature being implemented as a Map<Character,Integer>, so let's change that to Map<Integer,Integer> which will make it possible to remove the awkward int to char conversion and make the lambda body an expression rather than a block:

Friday, January 16, 2015

Mint 17, hibernate, plymouth

According to time-honored tradition I took advantage of time off over the holidays to upgrade my home computer from Mint 13 to Mint 17.

It's been about 2 1/2 years since I first tried Mint and I'm really feeling upbeat about this distro.  When Mark Shuttleworth went out of his mind and started ruining Ubuntu around 2010, it created a real vacuum.  For the first time since the Red Hat years there wasn't a Linux distro choice that was obvious.  I tried some different things, Mandriva, Magiea, Lubuntu and Xubuntu, Fedora... the magic just didn't seem to be there.

I was hearing good things about Mint so I gave it a shot.  Mint started out in a relationship with Ubuntu that you could compare with the old Mandrake - Red Hat relationship.  MATE gave me a way to cling to the familiar Gnome 2-ish desktop framework and continue to use all the same Ubuntu packages as before.

Anyway, things went smoothly.  This was kind of a big project due to the many purposes I use this computer for.  It's where I read my mail.  It's my 'file pig' where I keep movies and music.  It's my games box (dual boot with Windows XP).

You can now install Netflix practically out of the box.

I had a little trouble with Google Earth.  (Cool program).  Don't use the Google PPA.  Instead, install googleearth-package from the default Ubuntu repositories, then google-earth-stable:i386 as described here.

I used to just keep this computer up and running 24X7, but a few years ago I started hibernating it at night or when I was at work to keep the power consumption down.  After the upgrade, I had some trouble with hibernate.  Previously I had been using uswsusp, but now that didn't work at all.  I would get through a successful-looking hibernate and resume, then the computer would just lock up and I'd have to power cycle to bring it back up.

I took a shot at using swsusp instead.  uswsusp has several advantages over swsusp.  With uswsusp you get some output on the console showing the progress of the save or restore.  Swsusp just gives you a flashing cursor.  Uswsusp gives you a config file.  It gives you compression.  So uswsusp is my first choice.  But with a little configuration effort (notably building a swap file bigger than my RAM, since it doesn't use compression), swsusp seemed to be working.  But after a couple of weeks I had to admit it wasn't stable.  The longer my computer was up, the more likely hibernate was to fail.  It failed during the 'suspend', and shortly afterward X would lock up and I would need to reboot.

Around this time I started taking a really close look at a package called plymouth.  The purpose of plymouth is to display some eye candy while your system is booting.  By default, it gives you the Linux Mint logo but there are some other things you can configure.  The trouble with this is, if you're trying to troubleshoot something that happens during the boot process, like resuming from hibernate, all that dmesg output is hidden and you can only guess what's going on.

No problem, just remove plymouth, right?  Uh-uh.  For no reason that makes any sense, hundreds of packages are dependent on plymouth.  Packages like apache2, cron, cups, the kernel itself, mysql-server... This appears to come from Ubuntu since my buddy was able to easily remove plymouth from Mint-Debian.

So, a bit of frustration there, but the solution is easy enough... just remove "splash" from the boot line.

OK, did that.  Now I can see that my resume from uswsusp hibernate is proceeding to 100% completion, but right after that the computer locks up.

I did some more googling and found this.  Oh, that's interesting, plymouth itself is breaking the resume?  Here's another page documenting how to fix this.  I tried it and it worked.

So, plymouth was the real villain of this task, first blinding me to the output I needed to troubleshoot a problem, then it turns out plymouth itself caused the problem!  Plymouth is teh sux.

Update 2/17/2015:

I was continuing to have some instability with this system.  Every week or two I would have a lock-up and be forced to reboot.

I was just poking around in the motherboard manual kind of at random looking for clues when I noticed a feature called AHCI.  AHCI is a protocol for accessing SATA hard drives.  The BIOS menu has an option to either use AHCI or to cause the SATA drives to emulate IDE protocol.

Linux is fine with AHCI so I decided to try this.  I changed the BIOS setting to AHCI and Linux stayed up for 2 weeks.

There was a slight problem in that this computer was dual boot with Windows XP which is my games box for stuff I can't play in Linux.  Windows XP was on a SATA drive, and it does not support AHCI.  There are some hacks to enable this which I tried without success.  Finally I decided to just upgrade the Windows partition to Windows 7.  Windows XP was going on a year past its EOL date so this was probably something I was going to want to do eventually anyway.  This went smoothly and left me with a system I could just leave in AHCI mode all the time.

This issue predates my Mint 17 update as the computer has been having these freezes and lockups since the middle of last year. I actually was hoping Mint 17 would fix this.   My current theory is that I was running in AHCI mode for most of the lifetime of this motherboard (since October, 2009!), but after one of the changes I made last year, the BIOS was reset to its defaults, which includes IDE mode for SATA drives.

I'm not observing any disk I/O performance improvements or any other differences besides this system stability improvement as a result of switching to AHCI.  It is said to improve performance for SSDs.