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": "http://ocr-eureka.bosh-lite.com/eureka/"}'
 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 api.10.244.0.34.xip.io.  I read up on xip.io 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 api.bosh-lite.com 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.